Initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use RuntimeException;
|
||||
|
||||
class AfterUpgradeRunner
|
||||
{
|
||||
public function __construct(
|
||||
private InjectableFactory $injectableFactory,
|
||||
private DataManager $dataManager
|
||||
) {}
|
||||
|
||||
public function run(string $step): void
|
||||
{
|
||||
$dir = 'V' . str_replace('.', '_', $step);
|
||||
|
||||
$className = "Espo\\Core\\Upgrades\\Migrations\\$dir\\AfterUpgrade";
|
||||
|
||||
if (!class_exists($className)) {
|
||||
throw new RuntimeException("No after-upgrade script $step.");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dataManager->rebuild();
|
||||
} catch (Error $e) {
|
||||
throw new RuntimeException("Error while rebuild: " . $e->getMessage());
|
||||
}
|
||||
|
||||
/** @var Script $script */
|
||||
$script = $this->injectableFactory->createWith($className, ['isUpgrade' => false]);
|
||||
$script->run();
|
||||
|
||||
try {
|
||||
$this->dataManager->rebuild();
|
||||
} catch (Error $e) {
|
||||
throw new RuntimeException("Error while rebuild: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
class ExtractedStepsProvider
|
||||
{
|
||||
public function __construct(
|
||||
private StepsProvider $stepsProvider
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAfterUpgrade(string $version, string $targetVersion): array
|
||||
{
|
||||
return VersionUtil::extractSteps($version, $targetVersion, $this->stepsProvider->getAfterUpgrade());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPrepare(string $version, string $targetVersion): array
|
||||
{
|
||||
return VersionUtil::extractSteps($version, $targetVersion, $this->stepsProvider->getPrepare());
|
||||
}
|
||||
}
|
||||
127
application/Espo/Core/Upgrades/Migration/Runner.php
Normal file
127
application/Espo/Core/Upgrades/Migration/Runner.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
use Espo\Core\Console\IO;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
class Runner
|
||||
{
|
||||
public function __construct(
|
||||
private ExtractedStepsProvider $stepsProvider,
|
||||
private VersionDataProvider $versionDataProvider,
|
||||
private StepRunner $stepRunner,
|
||||
private DataManager $dataManager,
|
||||
private ConfigWriter $configWriter
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function run(IO $io): void
|
||||
{
|
||||
$this->dataManager->clearCache();
|
||||
|
||||
$version = $this->versionDataProvider->getPreviousVersion();
|
||||
$targetVersion = $this->versionDataProvider->getTargetVersion();
|
||||
|
||||
$prepareSteps = $this->stepsProvider->getPrepare($version, $targetVersion);
|
||||
|
||||
if ($prepareSteps !== []) {
|
||||
$io->writeLine("Running prepare migrations...");
|
||||
|
||||
foreach ($prepareSteps as $step) {
|
||||
$this->runPrepareStep($io, $step);
|
||||
}
|
||||
}
|
||||
|
||||
$afterSteps = $this->stepsProvider->getAfterUpgrade($version, $targetVersion);
|
||||
|
||||
if ($afterSteps === []) {
|
||||
$io->writeLine("No migrations to run.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine("Running after-upgrade migrations...");
|
||||
|
||||
foreach ($afterSteps as $step) {
|
||||
$this->runAfterUpgradeStep($io, $step);
|
||||
$this->updateVersion(VersionUtil::stepToVersion($step));
|
||||
}
|
||||
|
||||
$this->updateVersion($targetVersion);
|
||||
$this->dataManager->updateAppTimestamp();
|
||||
|
||||
$io->writeLine("Completed.");
|
||||
}
|
||||
|
||||
private function runAfterUpgradeStep(IO $io, string $step): void
|
||||
{
|
||||
$io->write(" $step...");
|
||||
|
||||
$isSuccessful = $this->stepRunner->runAfterUpgrade($step);
|
||||
|
||||
if ($isSuccessful) {
|
||||
$io->writeLine(" DONE");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->writeLine(" FAIL");
|
||||
|
||||
throw new RuntimeException("Step process failed.");
|
||||
}
|
||||
|
||||
private function runPrepareStep(IO $io, string $step): void
|
||||
{
|
||||
$io->write(" $step...");
|
||||
|
||||
try {
|
||||
$this->stepRunner->runPrepare($step);
|
||||
} catch (Exception $e) {
|
||||
$io->writeLine(" FAIL");
|
||||
|
||||
throw new RuntimeException($e->getMessage());
|
||||
}
|
||||
|
||||
$io->writeLine(" DONE");
|
||||
}
|
||||
|
||||
private function updateVersion(string $targetVersion): void
|
||||
{
|
||||
$this->configWriter->set('version', $targetVersion);
|
||||
$this->configWriter->save();
|
||||
}
|
||||
}
|
||||
35
application/Espo/Core/Upgrades/Migration/Script.php
Normal file
35
application/Espo/Core/Upgrades/Migration/Script.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
interface Script
|
||||
{
|
||||
public function run(): void;
|
||||
}
|
||||
100
application/Espo/Core/Upgrades/Migration/StepRunner.php
Normal file
100
application/Espo/Core/Upgrades/Migration/StepRunner.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Log;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class StepRunner
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private InjectableFactory $injectableFactory,
|
||||
private Log $log
|
||||
) {}
|
||||
|
||||
public function runAfterUpgrade(string $step): bool
|
||||
{
|
||||
$phpExecutablePath = $this->getPhpExecutablePath();
|
||||
|
||||
$command = "command.php";
|
||||
|
||||
$process = new Process([$phpExecutablePath, $command, 'migration-version-step', "--step=$step"]);
|
||||
$process->setTimeout(null);
|
||||
$process->run();
|
||||
|
||||
$this->processLogging($process);
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
public function runPrepare(string $step): void
|
||||
{
|
||||
$dir = 'V' . str_replace('.', '_', $step);
|
||||
|
||||
$className = "Espo\\Core\\Upgrades\\Migrations\\$dir\\Prepare";
|
||||
|
||||
if (!class_exists($className)) {
|
||||
throw new RuntimeException("No prepare script $step.");
|
||||
}
|
||||
|
||||
/** @var Script $script */
|
||||
$script = $this->injectableFactory->create($className);
|
||||
$script->run();
|
||||
}
|
||||
|
||||
private function getPhpExecutablePath(): string
|
||||
{
|
||||
$phpExecutablePath = $this->config->get('phpExecutablePath');
|
||||
|
||||
if (!$phpExecutablePath) {
|
||||
$phpExecutablePath = (new PhpExecutableFinder)->find();
|
||||
}
|
||||
|
||||
return $phpExecutablePath;
|
||||
}
|
||||
|
||||
private function processLogging(Process $process): void
|
||||
{
|
||||
if ($process->isSuccessful()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = $process->getOutput();
|
||||
|
||||
if ($output) {
|
||||
$this->log->error("Migration step command: " . $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
79
application/Espo/Core/Upgrades/Migration/StepsProvider.php
Normal file
79
application/Espo/Core/Upgrades/Migration/StepsProvider.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
use Espo\Core\Utils\File\Manager;
|
||||
use const SORT_STRING;
|
||||
|
||||
class StepsProvider
|
||||
{
|
||||
private string $dir = 'application/Espo/Core/Upgrades/Migrations';
|
||||
|
||||
public function __construct(
|
||||
private Manager $fileManager
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPrepare(): array
|
||||
{
|
||||
return $this->get('Prepare');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAfterUpgrade(): array
|
||||
{
|
||||
return $this->get('AfterUpgrade');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function get(string $name): array
|
||||
{
|
||||
$list = $this->fileManager->getDirList($this->dir);
|
||||
|
||||
$list = array_filter($list, function ($item) use ($name) {
|
||||
$dir = $this->dir . '/' . $item;
|
||||
|
||||
return $this->fileManager->isFile("$dir/$name.php");
|
||||
});
|
||||
|
||||
$list = array_values($list);
|
||||
$list = array_map(fn ($item) => substr(str_replace('_', '.', $item), 1), $list);
|
||||
|
||||
sort($list, SORT_STRING);
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\File\Manager;
|
||||
use RuntimeException;
|
||||
|
||||
class VersionDataProvider
|
||||
{
|
||||
private string $defaultConfigPath = 'application/Espo/Resources/defaults/config.php';
|
||||
|
||||
public function __construct(
|
||||
private Manager $fileManager,
|
||||
private Config\SystemConfig $systemConfig,
|
||||
) {}
|
||||
|
||||
public function getPreviousVersion(): string
|
||||
{
|
||||
$version = $this->systemConfig->getVersion();
|
||||
|
||||
if (!$version) {
|
||||
throw new RuntimeException("No or bad 'version' in config.");
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
public function getTargetVersion(): string
|
||||
{
|
||||
$data = $this->fileManager->getPhpContents($this->defaultConfigPath);
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new RuntimeException("No default config.");
|
||||
}
|
||||
|
||||
$version = $data['version'] ?? null;
|
||||
|
||||
if (!$version || !is_string($version)) {
|
||||
throw new RuntimeException("No or bad 'version' parameter in default config.");
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
119
application/Espo/Core/Upgrades/Migration/VersionUtil.php
Normal file
119
application/Espo/Core/Upgrades/Migration/VersionUtil.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2025 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Upgrades\Migration;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class VersionUtil
|
||||
{
|
||||
/**
|
||||
* @param string[] $fullList
|
||||
* @return string[]
|
||||
*/
|
||||
public static function extractSteps(string $from, string $to, array $fullList): array
|
||||
{
|
||||
usort($fullList, fn ($v1, $v2) => version_compare($v1, $v2));
|
||||
|
||||
$isPatch = self::isPatch($from, $to);
|
||||
|
||||
$list = [];
|
||||
$nextMinorIsPassed = false;
|
||||
|
||||
foreach ($fullList as $item) {
|
||||
$a = self::split($item);
|
||||
|
||||
if ($isPatch && $a[2] === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$v1 = $a[0] . '.' . $a[1] . '.' . ($a[2] ?? '0');
|
||||
|
||||
if (version_compare($v1, $from) <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (version_compare($v1, $to) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$isItemPatch = $a[2] !== null;
|
||||
|
||||
if (!$isPatch && $isItemPatch && $nextMinorIsPassed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$nextMinorIsPassed && !self::isPatch($from, $v1)) {
|
||||
$nextMinorIsPassed = true;
|
||||
}
|
||||
|
||||
$list[] = $item;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{string, string, ?string}
|
||||
*/
|
||||
public static function split(string $version): array
|
||||
{
|
||||
$array = explode('.', $version, 3);
|
||||
|
||||
if (count($array) === 2) {
|
||||
return [$array[0], $array[1], null];
|
||||
}
|
||||
|
||||
if (count($array) !== 3) {
|
||||
throw new RuntimeException("Bad version number $version.");
|
||||
}
|
||||
|
||||
/** @var array{string, string, string} */
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function isPatch(string $from, string $to): bool
|
||||
{
|
||||
$aFrom = self::split($from);
|
||||
$aTo = self::split($to);
|
||||
|
||||
return $aFrom[0] === $aTo[0] && $aFrom[1] === $aTo[1];
|
||||
}
|
||||
|
||||
public static function stepToVersion(string $step): string
|
||||
{
|
||||
$a = self::split($step);
|
||||
|
||||
if ($a[2] === null) {
|
||||
$a[2] = '0';
|
||||
}
|
||||
|
||||
return implode('.', $a);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user