Skip to content

Commit

Permalink
fix(Migration): correct loading logic for third party plugin migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldogedev committed Oct 17, 2023
1 parent 7c9da6a commit 02ed7b3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* MIT License
*
* Copyright (c) 2021-2023 cooldogedev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @auto-license
*/

declare(strict_types=1);

namespace cooldogedev\BedrockEconomy\database\constant;

interface MigrationVersion
{
public const VERSION_ANY = "any";
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

namespace cooldogedev\BedrockEconomy\database\migration;

use cooldogedev\BedrockEconomy\database\constant\MigrationVersion;
use cooldogedev\BedrockEconomy\database\migration\v2_1_2\Migration as v2_1_2;

final class MigrationRegistry
Expand All @@ -47,11 +48,14 @@ public static function init(): void
public static function get(string $version): ?IMigration
{
foreach (MigrationRegistry::$migrations as $migration) {
if (!version_compare($version, $migration->getMin(), ">=")) {
$min = $migration->getMin();
$max = $migration->getMax();

if ($min !== MigrationVersion::VERSION_ANY && !version_compare($version, $min, ">=")) {
continue;
}

if (!version_compare($version, $migration->getMax(), "<=")) {
if ($max !== MigrationVersion::VERSION_ANY && !version_compare($version, $max, "<=")) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use cooldogedev\BedrockEconomy\api\BedrockEconomyAPI;
use cooldogedev\BedrockEconomy\BedrockEconomy;
use cooldogedev\BedrockEconomy\database\constant\MigrationVersion;
use cooldogedev\BedrockEconomy\database\migration\IMigration;
use Generator;
use SOFe\AwaitGenerator\Await;
Expand All @@ -45,12 +46,12 @@ public function getName(): string

public function getMin(): string
{
return "0.0.1";
return MigrationVersion::VERSION_ANY;
}

public function getMax(): string
{
return "0.0.1";
return MigrationVersion::VERSION_ANY;
}

public function run(string $mode): bool
Expand Down

0 comments on commit 02ed7b3

Please sign in to comment.