Skip to content

Commit

Permalink
#9895 moved app key setup on upgrade as part of migration
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed May 28, 2024
1 parent 514ad58 commit 646455a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 30 deletions.
30 changes: 0 additions & 30 deletions classes/install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use PKP\cache\CacheManager;
use PKP\config\Config;
use PKP\core\Core;
use PKP\core\PKPAppKey;
use PKP\core\PKPApplication;
use PKP\core\PKPContainer;
use PKP\db\DAORegistry;
Expand All @@ -42,7 +41,6 @@
use PKP\site\VersionDAO;
use PKP\xml\PKPXMLParser;
use PKP\xml\XMLNode;
use Throwable;

class Installer
{
Expand Down Expand Up @@ -1010,34 +1008,6 @@ public function checkPhpVersion()
$this->setError(self::INSTALLER_ERROR_GENERAL, 'installer.unsupportedPhpError');
return false;
}

/**
* Add the app key if not already set
*
* @return bool Success/failure
*/
public function addAppKey()
{
// if APP KEY already exists, nothing to do
if (PKPAppKey::hasKey()) {
return true;
}

// will set an error if app key variable not set
// but will not halt the process
if (!PKPAppKey::hasKeyVariable()) {
error_log("No key variable named `app_key` defined in the `general` section of config file. Please update the config file's general section and add line `app_key = `");
return true;
}

try {
PKPAppKey::writeToConfig(PKPAppKey::generate());
} catch (Throwable $exception) {
error_log($exception->getMessage());
} finally {
return true;
}
}
}

if (!PKP_STRICT_MODE) {
Expand Down
57 changes: 57 additions & 0 deletions classes/migration/upgrade/v3_5_0/I9895_AddAppKeyToConfigFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I9895_AddAppKeyToConfigFile.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I9895_AddAppKeyToConfigFile
*
* @brief Generate and write the app key in the config file
*/

namespace PKP\migration\upgrade\v3_5_0;

use Throwable;
use PKP\core\PKPAppKey;
use PKP\install\DowngradeNotSupportedException;
use PKP\migration\Migration;

class I9895_AddAppKeyToConfigFile extends Migration
{
/**
* Run the migration.
*/
public function up(): void
{
// if APP KEY already exists, nothing to do
if (PKPAppKey::hasKey()) {
return;
}

// will set an error if app key variable not set
// but will not halt the process
if (!PKPAppKey::hasKeyVariable()) {
error_log("No key variable named `app_key` defined in the `general` section of config file. Please update the config file's general section and add line `app_key = `");
return;
}

try {
PKPAppKey::writeToConfig(PKPAppKey::generate());
} catch (Throwable $exception) {
error_log($exception->getMessage());
}
}

/**
* Reverse the downgrades
*
* @throws DowngradeNotSupportedException
*/
public function down(): void
{
throw new DowngradeNotSupportedException();
}
}

0 comments on commit 646455a

Please sign in to comment.