migrations dev

This commit is contained in:
Yuri Kuznetsov
2024-04-03 15:31:23 +03:00
parent b741898ce9
commit d8dd048a89
12 changed files with 1059 additions and 0 deletions
@@ -0,0 +1,50 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Console\Commands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Core\Upgrades\Migration\Runner;
/**
* @noinspection PhpUnused
*/
class Migrate implements Command
{
public function __construct(
private Runner $runner
) {}
public function run(Params $params, IO $io): void
{
$this->runner->run($io);
}
}
@@ -0,0 +1,81 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Console\Commands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Core\DataManager;
use Espo\Core\Exceptions\Error;
use Espo\Core\InjectableFactory;
use Espo\Core\Upgrades\Migration;
use RuntimeException;
/**
* @noinspection PhpUnused
*/
class MigrationVersionStep implements Command
{
public function __construct(
private InjectableFactory $injectableFactory,
private DataManager $dataManager
) {}
public function run(Params $params, IO $io): void
{
$step = $params->getOption('step');
if (!$step) {
throw new RuntimeException("No step parameter.");
}
$dir = 'V' . str_replace('.', '_', $step);
/** @var class-string<Migration\Script> $className */
$className = "Espo\\Core\\Upgrades\\Migrations\\$dir\\AfterUpgrade";
if (!class_exists($className)) {
$io->writeLine("No after-upgrade script.");
}
/** @var Migration\Script $script */
$script = $this->injectableFactory->create($className);
$script->run();
try {
$this->dataManager->rebuild();
}
catch (Error $e) {
throw new RuntimeException("Error while rebuild: " . $e->getMessage());
}
$io->writeLine("Done.");
}
}
@@ -0,0 +1,121 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Utils\Config;
use Espo\Core\Utils\File\Manager;
use RuntimeException;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
class Runner
{
private string $defaultConfigPath = 'application/Espo/Resources/defaults/config.php';
public function __construct(
private Config $config,
private Manager $fileManager,
private StepsExtractor $stepsExtractor,
private StepsProvider $stepsProvider
) {}
public function run(IO $io): void
{
$version = $this->config->get('version');
$targetVersion = $this->getTargetVersion();
$fullList = $this->stepsProvider->get();
$steps = $this->stepsExtractor->extract($version, $targetVersion, $fullList);
if ($steps === []) {
$io->writeLine(" No migrations to run.");
return;
}
$io->write(" Running migrations...");
foreach ($steps as $step) {
$this->runVersionStep($io, $step);
}
}
private function runVersionStep(IO $io, string $step): void
{
$phpExecutablePath = $this->getPhpExecutablePath();
$command = "command.php migration-version-step --step=$step";
$io->write(" $step...");
$process = new Process([$phpExecutablePath, $command]);
$process->setTimeout(null);
$process->run();
if ($process->isSuccessful()) {
$io->writeLine(" DONE");
return;
}
$io->writeLine(" FAIL");
throw new RuntimeException();
}
private function getPhpExecutablePath(): string
{
$phpExecutablePath = $this->config->get('phpExecutablePath');
if (!$phpExecutablePath) {
$phpExecutablePath = (new PhpExecutableFinder)->find();
}
return $phpExecutablePath;
}
private 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;
}
}
@@ -0,0 +1,35 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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;
}
@@ -0,0 +1,93 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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;
use const SORT_STRING;
class StepsExtractor
{
/**
* @param string[] $fullList
* @return string[]
*/
public function extract(string $from, string $to, array $fullList): array
{
sort($fullList, SORT_STRING);
$aFrom = self::split($from);
$aTo = self::split($to);
$isHotfix = $aFrom[0] === $aTo[0] && $aFrom[1] === $aTo[1];
$list = [];
foreach ($fullList as $item) {
$a = self::split($item);
$v1 = $a[0] . '.' . $a[1] . '.' . ($a[2] ?? '0');
if (version_compare($v1, $from) <= 0) {
continue;
}
if (version_compare($v1, $to) > 0) {
continue;
}
if (!$isHotfix && $a[2] !== null) {
continue;
}
$list[] = $item;
}
return $list;
}
/**
* @return array{string, string, ?string}
*/
private 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;
}
}
@@ -0,0 +1,63 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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 get(): array
{
$list = $this->fileManager->getDirList($this->dir);
$list = array_filter($list, function ($item) {
$dir = $this->dir . '/' . $item;
return $this->fileManager->isFile($dir . '/AfterUpgrade.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,119 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Migrations\V8_0;
use Espo\Core\Container;
use Espo\Core\Upgrades\Migration\Script;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Role;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\Part\Expression;
use Espo\ORM\Query\UpdateBuilder;
class AfterUpgrade implements Script
{
public function __construct(
private Container $container
) {}
public function run(): void
{
$this->updateRoles(
$this->container->getByClass(EntityManager::class)
);
$this->updateMetadata(
$this->container->getByClass(Metadata::class)
);
}
private function updateRoles(EntityManager $entityManager): void
{
$query = UpdateBuilder::create()
->in(Role::ENTITY_TYPE)
->set(['messagePermission' => Expression::column('assignmentPermission')])
->build();
$entityManager->getQueryExecutor()->execute($query);
}
private function updateMetadata(Metadata $metadata): void
{
$defs = $metadata->get(['scopes']);
foreach ($defs as $entityType => $item) {
$isCustom = $item['isCustom'] ?? false;
$type = $item['type'] ?? false;
if (!$isCustom) {
continue;
}
if ($type === 'Event') {
$metadata->set('entityDefs', $entityType, [
'fields' => [
'dateEnd' => [
'suppressValidationList' => ['required'],
],
]
]);
$metadata->save();
continue;
}
if (
!in_array($type, [
'BasePlus',
'Base',
'Company',
'Person',
])
) {
continue;
}
$recordDefs = $metadata->getCustom('recordDefs', $entityType) ?? (object) [];
$scopes = $metadata->getCustom('scopes', $entityType) ?? (object) [];
$recordDefs->duplicateWhereBuilderClassName = "Espo\\Classes\\DuplicateWhereBuilders\\General";
$scopes->duplicateCheckFieldList = [];
if ($type === 'Company' || $type === 'Person') {
$scopes->duplicateCheckFieldList = ['name', 'emailAddress'];
}
$metadata->saveCustom('recordDefs', $entityType, $recordDefs);
$metadata->saveCustom('scopes', $entityType, $scopes);
}
}
}
@@ -0,0 +1,61 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Migrations\V8_1;
use Espo\Core\Container;
use Espo\Core\Upgrades\Migration\Script;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config;
class AfterUpgrade implements Script
{
public function __construct(
private Container $container
) {}
public function run(): void
{
$config = $this->container->getByClass(Config::class);
$configWriter = $this->container->getByClass(InjectableFactory::class)
->create(Config\ConfigWriter::class);
$configWriter->setMultiple([
'phoneNumberNumericSearch' => false,
'phoneNumberInternational' => false,
]);
if ($config->get('pdfEngine') === 'Tcpdf') {
$configWriter->set('pdfEngine', 'Dompdf');
}
$configWriter->save();
}
}
@@ -0,0 +1,125 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Migrations\V8_2;
use Espo\Core\Upgrades\Migration\Script;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Template;
use Espo\ORM\EntityManager;
use Espo\Tools\Pdf\Template as PdfTemplate;
class AfterUpgrade implements Script
{
public function __construct(
private InjectableFactory $injectableFactory,
private Config $config,
private EntityManager $entityManager,
private Metadata $metadata
) {}
public function run(): void
{
$configWriter = $this->injectableFactory->create(Config\ConfigWriter::class);
$configWriter->setMultiple([
'jobForceUtc' => true,
]);
$configWriter->save();
$em = $this->entityManager;
$config = $this->config;
$this->updateTemplates($em, $config);
$this->updateTargetList($this->metadata);
}
private function updateTemplates(EntityManager $entityManager, Config $config): void
{
if ($config->get('pdfEngine') !== 'Dompdf') {
return;
}
/** @var iterable<Template> $templates */
$templates = $entityManager->getRDBRepositoryByClass(Template::class)
->sth()
->where(['pageFormat' => PdfTemplate::PAGE_FORMAT_CUSTOM])
->find();
foreach ($templates as $template) {
$width = $template->get('pageWidth') ?? 0.0;
$height = $template->get('pageHeight') ?? 0.0;
$template->setMultiple([
'pageWidth' => $width / 2.83465,
'pageHeight' => $height / 2.83465,
]);
$entityManager->saveEntity($template);
}
}
private function updateTargetList(Metadata $metadata): void
{
$links = $metadata->get('entityDefs.TargetList.links') ?? [];
$toSave = false;
foreach ($links as $link => $defs) {
if (empty($defs['isCustom'])) {
continue;
}
if (!$metadata->get("clientDefs.TargetList.relationshipPanels.$link.massSelect")) {
continue;
}
$metadata->set('recordDefs', 'TargetList', [
'relationships' => [
$link => [
'massLink' => true,
'linkRequiredForeignAccess' => 'read',
'mandatoryAttributeList' => ['targetListIsOptedOut'],
]
]
]);
$toSave = true;
}
if (!$toSave) {
return;
}
$metadata->save();
}
}
@@ -0,0 +1,45 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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\Migrations\V8_2_2;
use Espo\Core\Upgrades\Migration\Script;
use Espo\Core\Utils\Log;
class AfterUpgrade implements Script
{
public function __construct(
private Log $log
) {}
public function run(): void
{
$this->log->warning('Upgrade script test...');
}
}
@@ -0,0 +1,205 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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 tests\unit\Espo\Core\Upgrades\Migration;
use Espo\Core\Upgrades\Migration\StepsExtractor;
use PHPUnit\Framework\TestCase;
class StepsExtractorTest extends TestCase
{
public function testGet1(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.0.0', '8.3.0', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.1',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGet2(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.0.0', '8.3.1', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.1',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGet3(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.0.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGet4(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.2.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]);
$this->assertEquals([
'8.3',
], $list);
}
public function testGet5(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.0.4', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]);
$this->assertEquals([
'8.1',
'8.3',
], $list);
}
public function testGetMajor1(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('7.5.4', '8.3.5', array_reverse([
'7.0',
'7.5',
'7.5.1',
'7.6',
'7.6.1',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
]));
$this->assertEquals([
'7.6',
'8.0',
'8.1',
'8.3',
], $list);
}
public function testGetPatch1(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.3.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
'8.3.4',
]);
$this->assertEquals([
'8.3.2',
'8.3.4',
], $list);
}
public function testGetPatch2(): void
{
$extractor = new StepsExtractor();
$list = $extractor->extract('8.3.0', '8.3.5', [
'7.0',
'7.5',
'8.0',
'8.1',
'8.1.4',
'8.3',
'8.3.2',
'8.3.4',
'8.3.5',
'8.6.1',
]);
$this->assertEquals([
'8.3.2',
'8.3.4',
'8.3.5',
], $list);
}
}
@@ -0,0 +1,61 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* 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 PHPUnit\Framework\TestCase;
class StepsProviderTest extends TestCase
{
public function testGet1(): void
{
$fileManager = $this->createMock(Manager::class);
$fileManager
->expects($this->once())
->method('getDirList')
->willReturn(['V7_5_1', 'V8_0', 'V8_1', 'V8_2', 'V8_2_2']);
$fileManager
->expects($this->any())
->method('isFile')
->willReturn(true);
$provider = new StepsProvider($fileManager);
$this->assertEquals([
'7.5.1',
'8.0',
'8.1',
'8.2',
'8.2.2',
], $provider->get());
}
}