forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#10571 Move migration into v3.6 folder
- Loading branch information
1 parent
f05ff90
commit 01000e1
Showing
3 changed files
with
64 additions
and
16 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
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
62 changes: 62 additions & 0 deletions
62
classes/migration/upgrade/V3_6_0/PreflightCheckMigration.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,62 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/upgrade/v3_5_0/PreflightCheckMigration.php | ||
* | ||
* Copyright (c) 2014-2021 Simon Fraser University | ||
* Copyright (c) 2000-2021 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class PreflightCheckMigration | ||
* | ||
* @brief Check for common problems early in the upgrade process. | ||
*/ | ||
|
||
namespace PKP\migration\upgrade\V3_6_0; | ||
|
||
use PKP\db\DAORegistry; | ||
use Throwable; | ||
|
||
class PreflightCheckMigration extends \PKP\migration\Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
try { | ||
} catch (Throwable $e) { | ||
if ($fallbackVersion = $this->setFallbackVersion()) { | ||
$this->_installer->log("A pre-flight check failed. The software was successfully upgraded to {$fallbackVersion} but could not be upgraded further (to " . $this->_installer->newVersion->getVersionString() . '). Check and correct the error, then try again.'); | ||
} | ||
throw $e; | ||
} | ||
} | ||
|
||
/** | ||
* Rollback the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
if ($fallbackVersion = $this->setFallbackVersion()) { | ||
$this->_installer->log("An upgrade step failed! Fallback set to {$fallbackVersion}. Check and correct the error and try the upgrade again. We recommend restoring from backup, though you may be able to continue without doing so."); | ||
// Prevent further downgrade migrations from executing. | ||
$this->_installer->migrations = []; | ||
} | ||
} | ||
|
||
/** | ||
* Store the fallback version in the database, permitting resumption of partial upgrades. | ||
* | ||
* @return ?string Fallback version, if one was identified | ||
*/ | ||
protected function setFallbackVersion(): ?string | ||
{ | ||
if ($fallbackVersion = $this->_attributes['fallback'] ?? null) { | ||
$versionDao = DAORegistry::getDAO('VersionDAO'); /** @var \PKP\site\VersionDAO $versionDao */ | ||
$versionDao->insertVersion(\PKP\site\Version::fromString($fallbackVersion)); | ||
return $fallbackVersion; | ||
} | ||
return null; | ||
} | ||
} |