-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9895 moved app key setup on upgrade as part of migration
- Loading branch information
1 parent
514ad58
commit 646455a
Showing
2 changed files
with
57 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
classes/migration/upgrade/v3_5_0/I9895_AddAppKeyToConfigFile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |