-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added backwards compatibility with old log formatting
- Loading branch information
Showing
8 changed files
with
123 additions
and
70 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
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,43 @@ | ||
<?php | ||
|
||
namespace WpMailCatcher; | ||
|
||
use WpMailCatcher\Models\Settings; | ||
|
||
class DatabaseUpgradeService | ||
{ | ||
private $dbVersion; | ||
private $upgradePaths = []; | ||
|
||
public function __construct($upgradePaths, $currentDbVersion) | ||
{ | ||
$this->upgradePaths = $upgradePaths; | ||
$this->dbVersion = $currentDbVersion; | ||
} | ||
|
||
public function isUpgradeRequired() | ||
{ | ||
foreach ($this->upgradePaths as $version => $function) { | ||
if ($this->dbVersion < $version) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function doUpgrade() | ||
{ | ||
if (!$this->isUpgradeRequired()) { | ||
return; | ||
} | ||
|
||
foreach ($this->upgradePaths as $version => $function) { | ||
if ($this->dbVersion < $version) { | ||
$function(); | ||
} | ||
} | ||
|
||
Settings::update(['db_version' => GeneralHelper::$pluginVersion]); | ||
} | ||
} |
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
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
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,31 @@ | ||
<?php | ||
|
||
use WpMailCatcher\DatabaseUpgradeService; | ||
|
||
class TestDbUpgrade extends WP_UnitTestCase | ||
{ | ||
public function testMultipleUpgradesAreHandledCorrectly() | ||
{ | ||
$wasV05UpgradeCalled = false; | ||
$wasV2UpgradeCalled = false; | ||
$wasV25UpgradeCalled = false; | ||
|
||
$dbUpgradeManager = new DatabaseUpgradeService([ | ||
'0.5.0' => function () use (&$wasV05UpgradeCalled) { | ||
$wasV05UpgradeCalled = true; | ||
}, | ||
'2.0.0' => function () use (&$wasV2UpgradeCalled) { | ||
$wasV2UpgradeCalled = true; | ||
}, | ||
'2.5.0' => function () use (&$wasV25UpgradeCalled) { | ||
$wasV25UpgradeCalled = true; | ||
}, | ||
], '1.0.0'); | ||
|
||
$dbUpgradeManager->doUpgrade(); | ||
|
||
$this->assertFalse($wasV05UpgradeCalled); | ||
$this->assertTrue($wasV2UpgradeCalled); | ||
$this->assertTrue($wasV25UpgradeCalled); | ||
} | ||
} |