diff --git a/README.md b/README.md index 8e986bef5..cb11bd4bf 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The following parameters are mandatory: * **--dir**: Tells where the admin directory is. * **--channel**: Selects what upgrade to run (minor, major etc.) -* **--action**: Advanced users only. Sets the step you want to start from (Default: `UpgradeNow`, [other values available](classes/TaskRunner/Upgrade/)). +* **--action**: Advanced users only. Sets the step you want to start from (Default: `UpgradeNow`, [other values available](classes/Task/Upgrade/)). ``` $ php cli-upgrade.php --dir=admin-dev --channel=major @@ -82,7 +82,8 @@ $ php cli-rollback.php --dir=admin-dev --backup=V1.7.5.1_20190502-191341-22e883 ## Documentation -Documentation is hosted on [the Developer documentation][doc]. +* Documentation is hosted on [the Developer documentation][doc]. +* Privacy documentation is hosted [on the PrestaShop Project website][prestashop-privacy]. ## Contributing @@ -104,6 +105,7 @@ This module is released under the [Academic Free License 3.0][AFL-3.0] [report-issue]: https://github.com/PrestaShop/PrestaShop/issues/new/choose [prestashop]: https://www.prestashop-project.org/ +[prestashop-privacy]: https://www.prestashop-project.org/data-transparency/ [contribution-guidelines]: https://devdocs.prestashop-project.org/8/contribute/contribution-guidelines/project-modules/ [AFL-3.0]: https://opensource.org/licenses/AFL-3.0 [doc]: https://devdocs.prestashop-project.org/8/basics/keeping-up-to-date/upgrade-module/ diff --git a/ajax-upgradetab.php b/ajax-upgradetab.php index 3eb3ea8b1..75d263052 100755 --- a/ajax-upgradetab.php +++ b/ajax-upgradetab.php @@ -24,8 +24,9 @@ * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ + +use PrestaShop\Module\AutoUpgrade\Task\Runner\SingleTask; use PrestaShop\Module\AutoUpgrade\Tools14; -use PrestaShop\Module\AutoUpgrade\UpgradeTools\TaskRepository; /** * This file is the entrypoint for all ajax requests during a upgrade, rollback or configuration. @@ -48,7 +49,7 @@ exit(1); } -$controller = TaskRepository::get(Tools14::getValue('action'), $container); -$controller->init(); +$controller = new SingleTask($container); +$controller->setOptions(['action' => Tools14::getValue('action')]); $controller->run(); echo $controller->getJsonResponse(); diff --git a/classes/Analytics.php b/classes/Analytics.php new file mode 100644 index 000000000..87b80d067 --- /dev/null +++ b/classes/Analytics.php @@ -0,0 +1,158 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ + +namespace PrestaShop\Module\AutoUpgrade; + +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; + +class Analytics +{ + const SEGMENT_CLIENT_KEY_PHP = 'NrWZk42rDrA56DkEt9Tj18DBirLoRLhj'; + const SEGMENT_CLIENT_KEY_JS = 'RM87m03McDSL4Fvm3GJ3piBPbAL3Fa2i'; + + const WITH_COMMON_PROPERTIES = 0; + const WITH_UPGRADE_PROPERTIES = 1; + const WITH_ROLLBACK_PROPERTIES = 2; + + // Reusing environment variable from Distribution API + public const URL_TRACKING_ENV_NAME = 'PS_URL_TRACKING'; + + /** + * @var string + */ + private $anonymousId; + + /** + * @var array + */ + private $properties; + + /** + * @var UpgradeConfiguration + */ + private $upgradeConfiguration; + + /** + * @var State + */ + private $state; + + /** + * @param string $anonymousUserId + * @param array{'properties'?: array} $options + */ + public function __construct( + UpgradeConfiguration $upgradeConfiguration, + State $state, + $anonymousUserId, + array $options + ) { + $this->upgradeConfiguration = $upgradeConfiguration; + $this->state = $state; + + $this->anonymousId = hash('sha256', $anonymousUserId, false); + $this->properties = $options['properties'] ?? []; + + if ($this->hasOptedOut()) { + return; + } + + \Segment::init(self::SEGMENT_CLIENT_KEY_PHP); + } + + /** + * @param string $event + * @param self::WITH_*_PROPERTIES $propertiesType + * + * @return void + */ + public function track($event, $propertiesType = self::WITH_COMMON_PROPERTIES) + { + if ($this->hasOptedOut()) { + return; + } + + \Segment::track(array_merge( + ['event' => $event], + $this->getProperties($propertiesType) + )); + \Segment::flush(); + } + + /** + * @param self::WITH_*_PROPERTIES $type + * + * @return array + */ + public function getProperties($type) + { + switch ($type) { + case self::WITH_UPGRADE_PROPERTIES: + $additionalProperties = [ + 'from_ps_version' => $this->state->getOriginVersion(), + 'to_ps_version' => $this->state->getInstallVersion(), + 'upgrade_channel' => $this->upgradeConfiguration->getChannel(), + 'backup_files_and_databases' => $this->upgradeConfiguration->get('PS_AUTOUP_BACKUP') + || !$this->upgradeConfiguration->get('skip_backup'), + 'backup_images' => $this->upgradeConfiguration->shouldBackupImages(), + 'server_performance' => $this->upgradeConfiguration->getPerformanceLevel(), + 'disable_non_native_modules' => $this->upgradeConfiguration->shouldDeactivateCustomModules(), + 'upgrade_default_theme' => $this->upgradeConfiguration->shouldUpdateDefaultTheme(), + 'switch_to_default_theme' => $this->upgradeConfiguration->shouldSwitchToDefaultTheme(), + 'regenerate_rtl_stylesheet' => $this->upgradeConfiguration->shouldUpdateRTLFiles(), + 'keep_customized_email_templates' => $this->upgradeConfiguration->shouldKeepMails(), + ]; + break; + case self::WITH_ROLLBACK_PROPERTIES: + $additionalProperties = [ + 'from_ps_version' => $this->properties['ps_version'] ?? null, + 'to_ps_version' => $this->state->getRestoreVersion(), + ]; + break; + default: + $additionalProperties = []; + } + + return [ + 'anonymousId' => $this->anonymousId, + 'channel' => 'browser', + 'properties' => array_merge( + $this->properties, + $additionalProperties, + [ + 'module' => 'autoupgrade', + ] + ), + ]; + } + + private function hasOptedOut(): bool + { + return isset($_SERVER[self::URL_TRACKING_ENV_NAME]) + && ((bool) $_SERVER[self::URL_TRACKING_ENV_NAME] === false || $_SERVER[self::URL_TRACKING_ENV_NAME] === 'false'); + } +} diff --git a/classes/State.php b/classes/State.php index d5636bba8..8d0c03d2b 100644 --- a/classes/State.php +++ b/classes/State.php @@ -32,6 +32,10 @@ */ class State { + /** + * @var string + */ + private $originVersion; // Origin version of PrestaShop /** * @var string */ @@ -176,6 +180,11 @@ function ($v) { return $v['iso_code']; }, } // GETTERS + public function getOriginVersion(): string + { + return $this->originVersion; + } + public function getInstallVersion(): string { return $this->install_version; @@ -263,6 +272,13 @@ public function getWarningExists(): bool } // SETTERS + public function setOriginVersion(string $originVersion): State + { + $this->originVersion = $originVersion; + + return $this; + } + public function setInstallVersion(string $install_version): State { $this->install_version = $install_version; @@ -348,6 +364,21 @@ public function setRestoreDbFilenames(array $restoreDbFilenames): State return $this; } + /** + * Pick version from restoration file name in the format v[version]_[date]-[time]-[random] + */ + public function getRestoreVersion(): ?string + { + $matches = []; + preg_match( + '/^V(?[1-9\.]+)_/', + $this->getRestoreName(), + $matches + ); + + return $matches[1] ?? null; + } + /** * @param string[] $installedLanguagesIso */ diff --git a/classes/TaskRunner/AbstractTask.php b/classes/Task/AbstractTask.php similarity index 86% rename from classes/TaskRunner/AbstractTask.php rename to classes/Task/AbstractTask.php index 342d7684b..85d0909c0 100644 --- a/classes/TaskRunner/AbstractTask.php +++ b/classes/Task/AbstractTask.php @@ -25,10 +25,11 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner; +namespace PrestaShop\Module\AutoUpgrade\Task; use Exception; use PrestaShop\Module\AutoUpgrade\AjaxResponse; +use PrestaShop\Module\AutoUpgrade\Analytics; use PrestaShop\Module\AutoUpgrade\Log\Logger; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; @@ -59,6 +60,11 @@ abstract class AbstractTask */ protected $container; + /** + * @var 'upgrade'|'rollback'|null + */ + const TASK_TYPE = null; + // Task progress details /** * @var bool @@ -138,6 +144,19 @@ private function checkTaskMayRun(): void } } + public function setErrorFlag(): void + { + $this->error = true; + // TODO: Add this? $this->next = 'error'; + + if (static::TASK_TYPE) { + $this->container->getAnalytics()->track( + ucfirst(static::TASK_TYPE) . ' Failed', + static::TASK_TYPE === 'upgrade' ? Analytics::WITH_UPGRADE_PROPERTIES : Analytics::WITH_ROLLBACK_PROPERTIES + ); + } + } + /** * @throws Exception */ diff --git a/classes/TaskRunner/ExitCode.php b/classes/Task/ExitCode.php similarity index 95% rename from classes/TaskRunner/ExitCode.php rename to classes/Task/ExitCode.php index 4df8a1965..6eb5aa3e5 100644 --- a/classes/TaskRunner/ExitCode.php +++ b/classes/Task/ExitCode.php @@ -25,7 +25,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner; +namespace PrestaShop\Module\AutoUpgrade\Task; class ExitCode { diff --git a/classes/TaskRunner/Miscellaneous/CheckFilesVersion.php b/classes/Task/Miscellaneous/CheckFilesVersion.php similarity index 94% rename from classes/TaskRunner/Miscellaneous/CheckFilesVersion.php rename to classes/Task/Miscellaneous/CheckFilesVersion.php index 916794612..11d743217 100644 --- a/classes/TaskRunner/Miscellaneous/CheckFilesVersion.php +++ b/classes/Task/Miscellaneous/CheckFilesVersion.php @@ -25,12 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous; +namespace PrestaShop\Module\AutoUpgrade\Task\Miscellaneous; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; /** diff --git a/classes/TaskRunner/Miscellaneous/CompareReleases.php b/classes/Task/Miscellaneous/CompareReleases.php similarity index 95% rename from classes/TaskRunner/Miscellaneous/CompareReleases.php rename to classes/Task/Miscellaneous/CompareReleases.php index 6776d2a9b..cbe454590 100644 --- a/classes/TaskRunner/Miscellaneous/CompareReleases.php +++ b/classes/Task/Miscellaneous/CompareReleases.php @@ -25,12 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous; +namespace PrestaShop\Module\AutoUpgrade\Task\Miscellaneous; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\VersionUtils; /** diff --git a/classes/TaskRunner/Miscellaneous/GetChannelInfo.php b/classes/Task/Miscellaneous/GetChannelInfo.php similarity index 92% rename from classes/TaskRunner/Miscellaneous/GetChannelInfo.php rename to classes/Task/Miscellaneous/GetChannelInfo.php index ab2848213..5e7b351ae 100644 --- a/classes/TaskRunner/Miscellaneous/GetChannelInfo.php +++ b/classes/Task/Miscellaneous/GetChannelInfo.php @@ -25,12 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous; +namespace PrestaShop\Module\AutoUpgrade\Task\Miscellaneous; use Exception; use PrestaShop\Module\AutoUpgrade\ChannelInfo; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\Twig\Block\ChannelInfoBlock; use Twig\Error\LoaderError; diff --git a/classes/TaskRunner/Miscellaneous/UpdateConfig.php b/classes/Task/Miscellaneous/UpdateConfig.php similarity index 95% rename from classes/TaskRunner/Miscellaneous/UpdateConfig.php rename to classes/Task/Miscellaneous/UpdateConfig.php index fe74bdde1..f07d73173 100644 --- a/classes/TaskRunner/Miscellaneous/UpdateConfig.php +++ b/classes/Task/Miscellaneous/UpdateConfig.php @@ -25,14 +25,14 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous; +namespace PrestaShop\Module\AutoUpgrade\Task\Miscellaneous; use Exception; use PrestaShop\Module\AutoUpgrade\Exceptions\ZipActionException; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfigurationStorage; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\Upgrader; use RuntimeException; @@ -80,7 +80,7 @@ public function run(): int $file = $configurationData['archive_prestashop']; $fullFilePath = $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file; if (!file_exists($fullFilePath)) { - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('File %s does not exist. Unable to select that channel.', [$file])); return ExitCode::FAIL; @@ -89,7 +89,7 @@ public function run(): int try { $targetVersion = $this->extractPrestashopVersionFromZip($fullFilePath); } catch (Exception $exception) { - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('Unable to retrieve version from zip: %s.', [$exception->getMessage()])); return ExitCode::FAIL; @@ -98,7 +98,7 @@ public function run(): int $xmlFile = $configurationData['archive_xml']; $fullXmlPath = $this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $xmlFile; if (!empty($xmlFile) && !file_exists($fullXmlPath)) { - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('File %s does not exist. Unable to select that channel.', [$xmlFile])); return ExitCode::FAIL; @@ -123,7 +123,7 @@ public function run(): int if (isset($configurationData['directory_num'])) { $config['channel'] = 'directory'; if (empty($configurationData['directory_num']) || strpos($configurationData['directory_num'], '.') === false) { - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('Version number is missing. Unable to select that channel.')); return ExitCode::FAIL; @@ -139,7 +139,7 @@ public function run(): int } if (!$this->writeConfig($config)) { - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('Error on saving configuration')); return ExitCode::FAIL; @@ -204,6 +204,7 @@ private function writeConfig(array $config): bool $this->container->getUpgrader()->checkPSVersion(); $this->container->getState()->setInstallVersion($this->container->getUpgrader()->version_num); + $this->container->getState()->setOriginVersion($this->container->getProperty(UpgradeContainer::PS_VERSION)); } $this->container->getUpgradeConfiguration()->merge($config); diff --git a/classes/TaskRunner/Miscellaneous/index.php b/classes/Task/Miscellaneous/index.php similarity index 100% rename from classes/TaskRunner/Miscellaneous/index.php rename to classes/Task/Miscellaneous/index.php diff --git a/classes/TaskRunner/NullTask.php b/classes/Task/NullTask.php similarity index 95% rename from classes/TaskRunner/NullTask.php rename to classes/Task/NullTask.php index a676611e3..a89c3d5a3 100644 --- a/classes/TaskRunner/NullTask.php +++ b/classes/Task/NullTask.php @@ -25,7 +25,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner; +namespace PrestaShop\Module\AutoUpgrade\Task; class NullTask extends AbstractTask { diff --git a/classes/TaskRunner/Rollback/NoRollbackFound.php b/classes/Task/Rollback/NoRollbackFound.php similarity index 87% rename from classes/TaskRunner/Rollback/NoRollbackFound.php rename to classes/Task/Rollback/NoRollbackFound.php index 342b8dc71..40ea5f0ba 100644 --- a/classes/TaskRunner/Rollback/NoRollbackFound.php +++ b/classes/Task/Rollback/NoRollbackFound.php @@ -25,13 +25,15 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; +namespace PrestaShop\Module\AutoUpgrade\Task\Rollback; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; class NoRollbackFound extends AbstractTask { + const TASK_TYPE = 'rollback'; + public function run(): int { $this->logger->info($this->translator->trans('Nothing to restore')); diff --git a/classes/TaskRunner/Rollback/RestoreDb.php b/classes/Task/Rollback/RestoreDb.php similarity index 97% rename from classes/TaskRunner/Rollback/RestoreDb.php rename to classes/Task/Rollback/RestoreDb.php index df8d8bffa..6a7e76405 100644 --- a/classes/TaskRunner/Rollback/RestoreDb.php +++ b/classes/Task/Rollback/RestoreDb.php @@ -25,12 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; +namespace PrestaShop\Module\AutoUpgrade\Task\Rollback; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Database; @@ -39,6 +39,8 @@ */ class RestoreDb extends AbstractTask { + const TASK_TYPE = 'rollback'; + /** * @throws Exception */ @@ -67,7 +69,7 @@ public function run(): int $this->container->getState()->setRestoreDbFilenames($restoreDbFilenames); if (!preg_match('#auto-backupdb_([0-9]{6})_#', $currentDbFilename, $match)) { $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); $this->logger->error($this->translator->trans('%s: File format does not match.', [$currentDbFilename])); return ExitCode::FAIL; @@ -199,7 +201,7 @@ public function run(): int $this->logger->error($this->translator->trans('[SQL ERROR]') . ' ' . $query . ' - ' . $this->container->getDb()->getMsgError()); $this->logger->info($this->translator->trans('Error during database restoration')); $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); unlink($this->container->getProperty(UpgradeContainer::WORKSPACE_PATH) . DIRECTORY_SEPARATOR . UpgradeFileNames::QUERIES_TO_RESTORE_LIST); return ExitCode::FAIL; diff --git a/classes/TaskRunner/Rollback/RestoreFiles.php b/classes/Task/Rollback/RestoreFiles.php similarity index 95% rename from classes/TaskRunner/Rollback/RestoreFiles.php rename to classes/Task/Rollback/RestoreFiles.php index 8c2980737..0135f6608 100644 --- a/classes/TaskRunner/Rollback/RestoreFiles.php +++ b/classes/Task/Rollback/RestoreFiles.php @@ -25,12 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; +namespace PrestaShop\Module\AutoUpgrade\Task\Rollback; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; /** @@ -39,6 +39,8 @@ */ class RestoreFiles extends AbstractTask { + const TASK_TYPE = 'rollback'; + /** * @throws Exception */ @@ -83,6 +85,7 @@ public function run(): int } $this->logger->info($this->translator->trans('Unable to remove upgraded files.')); $this->next = 'error'; + $this->setErrorFlag(); return ExitCode::FAIL; } @@ -95,6 +98,7 @@ public function run(): int $res = $this->container->getZipAction()->extract($filepath, $destExtract); if (!$res) { $this->next = 'error'; + $this->setErrorFlag(); $this->logger->error($this->translator->trans( 'Unable to extract file %filename% into directory %directoryname%.', [ diff --git a/classes/TaskRunner/Rollback/Rollback.php b/classes/Task/Rollback/Rollback.php similarity index 91% rename from classes/TaskRunner/Rollback/Rollback.php rename to classes/Task/Rollback/Rollback.php index e2d0c4720..56829fde7 100644 --- a/classes/TaskRunner/Rollback/Rollback.php +++ b/classes/Task/Rollback/Rollback.php @@ -25,12 +25,13 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; +namespace PrestaShop\Module\AutoUpgrade\Task\Rollback; use Exception; +use PrestaShop\Module\AutoUpgrade\Analytics; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; /** @@ -38,6 +39,8 @@ */ class Rollback extends AbstractTask { + const TASK_TYPE = 'rollback'; + /** * @throws Exception */ @@ -64,6 +67,7 @@ public function run(): int } if (!is_file($this->container->getProperty(UpgradeContainer::BACKUP_PATH) . DIRECTORY_SEPARATOR . $this->container->getState()->getRestoreFilesFilename())) { $this->next = 'error'; + $this->setErrorFlag(); $this->logger->error($this->translator->trans('[ERROR] File %s is missing: unable to restore files. Operation aborted.', [$this->container->getState()->getRestoreFilesFilename()])); return ExitCode::FAIL; @@ -80,6 +84,7 @@ public function run(): int $this->container->getState()->setRestoreDbFilenames($restoreDbFilenames); if (count($restoreDbFilenames) == 0) { $this->next = 'error'; + $this->setErrorFlag(); $this->logger->error($this->translator->trans('[ERROR] No backup database files found: it would be impossible to restore the database. Operation aborted.')); return ExitCode::FAIL; @@ -95,6 +100,8 @@ public function run(): int unlink($this->container->getProperty(UpgradeContainer::WORKSPACE_PATH) . DIRECTORY_SEPARATOR . UpgradeFileNames::FILES_TO_REMOVE_LIST); } + $this->container->getAnalytics()->track('Rollback Launched', Analytics::WITH_ROLLBACK_PROPERTIES); + return ExitCode::SUCCESS; } diff --git a/classes/TaskRunner/Rollback/RollbackComplete.php b/classes/Task/Rollback/RollbackComplete.php similarity index 80% rename from classes/TaskRunner/Rollback/RollbackComplete.php rename to classes/Task/Rollback/RollbackComplete.php index 411cb4f19..0c87f331a 100644 --- a/classes/TaskRunner/Rollback/RollbackComplete.php +++ b/classes/Task/Rollback/RollbackComplete.php @@ -25,20 +25,24 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; +namespace PrestaShop\Module\AutoUpgrade\Task\Rollback; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Analytics; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; /** * Only displays the success message. */ class RollbackComplete extends AbstractTask { + const TASK_TYPE = 'rollback'; + public function run(): int { $this->logger->info($this->translator->trans('Restoration process done. Congratulations! You can now reactivate your shop.')); $this->next = ''; + $this->container->getAnalytics()->track('Rollback Succeeded', Analytics::WITH_ROLLBACK_PROPERTIES); return ExitCode::SUCCESS; } diff --git a/classes/TaskRunner/Rollback/index.php b/classes/Task/Rollback/index.php similarity index 100% rename from classes/TaskRunner/Rollback/index.php rename to classes/Task/Rollback/index.php diff --git a/classes/TaskRunner/Rollback/AllRollbackTasks.php b/classes/Task/Runner/AllRollbackTasks.php similarity index 94% rename from classes/TaskRunner/Rollback/AllRollbackTasks.php rename to classes/Task/Runner/AllRollbackTasks.php index 207392901..8ef9b319d 100644 --- a/classes/TaskRunner/Rollback/AllRollbackTasks.php +++ b/classes/Task/Runner/AllRollbackTasks.php @@ -25,9 +25,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; - -use PrestaShop\Module\AutoUpgrade\TaskRunner\ChainedTasks; +namespace PrestaShop\Module\AutoUpgrade\Task\Runner; /** * Execute the whole upgrade process in a single request. diff --git a/classes/TaskRunner/Upgrade/AllUpgradeTasks.php b/classes/Task/Runner/AllUpgradeTasks.php similarity index 97% rename from classes/TaskRunner/Upgrade/AllUpgradeTasks.php rename to classes/Task/Runner/AllUpgradeTasks.php index 43a0fa474..ad5c40a7e 100644 --- a/classes/TaskRunner/Upgrade/AllUpgradeTasks.php +++ b/classes/Task/Runner/AllUpgradeTasks.php @@ -25,11 +25,10 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Runner; use Exception; use PrestaShop\Module\AutoUpgrade\AjaxResponse; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ChainedTasks; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; /** diff --git a/classes/TaskRunner/ChainedTasks.php b/classes/Task/Runner/ChainedTasks.php similarity index 87% rename from classes/TaskRunner/ChainedTasks.php rename to classes/Task/Runner/ChainedTasks.php index 1e24a616f..47cc23825 100644 --- a/classes/TaskRunner/ChainedTasks.php +++ b/classes/Task/Runner/ChainedTasks.php @@ -25,11 +25,13 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner; +namespace PrestaShop\Module\AutoUpgrade\Task\Runner; use Exception; use PrestaShop\Module\AutoUpgrade\AjaxResponse; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; use PrestaShop\Module\AutoUpgrade\UpgradeTools\TaskRepository; +use Throwable; /** * Execute the whole process in a single request, useful in CLI. @@ -55,13 +57,19 @@ public function run(): int $this->logger->info('=== Step ' . $this->step); $controller = TaskRepository::get($this->step, $this->container); $controller->init(); - $controller->run(); + try { + $controller->run(); + } catch (Throwable $t) { + $controller->setErrorFlag(); + throw $t; + } $result = $controller->getResponse(); $requireRestart = $this->checkIfRestartRequested($result); $this->error = $result->getError(); $this->stepDone = $result->getStepDone(); - $this->step = $result->getNext(); + $this->step = $this->next = $result->getNext(); + $this->nextParams = $result->getNextParams(); } return (int) ($this->error || $this->step === 'error'); diff --git a/classes/Task/Runner/SingleTask.php b/classes/Task/Runner/SingleTask.php new file mode 100644 index 000000000..1197ff33b --- /dev/null +++ b/classes/Task/Runner/SingleTask.php @@ -0,0 +1,54 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ + +namespace PrestaShop\Module\AutoUpgrade\Task\Runner; + +class SingleTask extends ChainedTasks +{ + protected $step; + + /** @var bool */ + private $stepHasRun = false; + + public function setOptions(array $options): void + { + if (!empty($options['action'])) { + $this->step = $options['action']; + } + } + + protected function canContinue(): bool + { + if (!$this->stepHasRun) { + $this->stepHasRun = true; + + return true; + } + + return false; + } +} diff --git a/classes/TaskRunner/Upgrade/BackupDb.php b/classes/Task/Upgrade/BackupDb.php similarity index 97% rename from classes/TaskRunner/Upgrade/BackupDb.php rename to classes/Task/Upgrade/BackupDb.php index 56d4901f9..609142a92 100644 --- a/classes/TaskRunner/Upgrade/BackupDb.php +++ b/classes/Task/Upgrade/BackupDb.php @@ -25,17 +25,19 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\Tools14; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; class BackupDb extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ @@ -58,7 +60,7 @@ public function run(): int if (!\ConfigurationTest::test_dir($relative_backup_path, false, $report)) { $this->logger->error($this->translator->trans('Backup directory is not writable (%path%).', ['%path%' => $this->container->getProperty(UpgradeContainer::BACKUP_PATH)])); $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); return ExitCode::FAIL; } @@ -132,7 +134,7 @@ public function run(): int // Figure out what compression is available and open the file if (file_exists($backupfile)) { $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); $this->logger->error($this->translator->trans('Backup file %s already exists. Operation aborted.', [$backupfile])); } @@ -149,7 +151,7 @@ public function run(): int if ($fp === false) { $this->logger->error($this->translator->trans('Unable to create backup database file %s.', [addslashes($backupfile)])); $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('Error during database backup.')); return ExitCode::FAIL; @@ -177,7 +179,7 @@ public function run(): int $this->logger->error($this->translator->trans('An error occurred while backing up. Unable to obtain the schema of %s', [$table])); $this->logger->info($this->translator->trans('Error during database backup.')); $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); return ExitCode::FAIL; } @@ -278,7 +280,7 @@ public function run(): int } $this->logger->error($this->translator->trans('No valid tables were found to back up. Backup of file %s canceled.', [$backupfile])); $this->logger->info($this->translator->trans('Error during database backup for file %s.', [$backupfile])); - $this->error = true; + $this->setErrorFlag(); return ExitCode::FAIL; } else { diff --git a/classes/TaskRunner/Upgrade/BackupFiles.php b/classes/Task/Upgrade/BackupFiles.php similarity index 95% rename from classes/TaskRunner/Upgrade/BackupFiles.php rename to classes/Task/Upgrade/BackupFiles.php index 01c18c4f3..f713b5046 100644 --- a/classes/TaskRunner/Upgrade/BackupFiles.php +++ b/classes/Task/Upgrade/BackupFiles.php @@ -25,16 +25,18 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; class BackupFiles extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ @@ -54,7 +56,7 @@ public function run(): int $backupFilesFilename = $this->container->getState()->getBackupFilesFilename(); if (empty($backupFilesFilename)) { $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans('Error during backupFiles')); $this->logger->error($this->translator->trans('[ERROR] backupFiles filename has not been set')); diff --git a/classes/TaskRunner/Upgrade/CleanDatabase.php b/classes/Task/Upgrade/CleanDatabase.php similarity index 91% rename from classes/TaskRunner/Upgrade/CleanDatabase.php rename to classes/Task/Upgrade/CleanDatabase.php index bb9b87656..25c7d8f08 100644 --- a/classes/TaskRunner/Upgrade/CleanDatabase.php +++ b/classes/Task/Upgrade/CleanDatabase.php @@ -25,16 +25,18 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; /** * Clean the database from unwanted entries. */ class CleanDatabase extends AbstractTask { + const TASK_TYPE = 'upgrade'; + public function run(): int { // Clean tabs order diff --git a/classes/TaskRunner/Upgrade/Download.php b/classes/Task/Upgrade/Download.php similarity index 96% rename from classes/TaskRunner/Upgrade/Download.php rename to classes/Task/Upgrade/Download.php index 08581ac2d..9eb82d214 100644 --- a/classes/TaskRunner/Upgrade/Download.php +++ b/classes/Task/Upgrade/Download.php @@ -25,11 +25,11 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter; use PrestaShop\Module\AutoUpgrade\VersionUtils; @@ -39,6 +39,8 @@ */ class Download extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ diff --git a/classes/TaskRunner/Upgrade/Unzip.php b/classes/Task/Upgrade/Unzip.php similarity index 94% rename from classes/TaskRunner/Upgrade/Unzip.php rename to classes/Task/Upgrade/Unzip.php index b936a0f4b..36477986b 100644 --- a/classes/TaskRunner/Upgrade/Unzip.php +++ b/classes/Task/Upgrade/Unzip.php @@ -25,11 +25,11 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter; use Symfony\Component\Filesystem\Filesystem; @@ -39,6 +39,8 @@ */ class Unzip extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ @@ -56,7 +58,7 @@ public function run(): int if (!\ConfigurationTest::test_dir($relative_extract_path, false, $report)) { $this->logger->error($this->translator->trans('Extraction directory %s is not writable.', [$destExtract])); $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); return ExitCode::FAIL; } @@ -65,7 +67,7 @@ public function run(): int if (!$res) { $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); $this->logger->info($this->translator->trans( 'Unable to extract %filepath% file into %destination% folder...', [ diff --git a/classes/TaskRunner/Upgrade/UpgradeComplete.php b/classes/Task/Upgrade/UpgradeComplete.php similarity index 90% rename from classes/TaskRunner/Upgrade/UpgradeComplete.php rename to classes/Task/Upgrade/UpgradeComplete.php index 2ba3105cf..277cd0e2a 100644 --- a/classes/TaskRunner/Upgrade/UpgradeComplete.php +++ b/classes/Task/Upgrade/UpgradeComplete.php @@ -25,11 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Analytics; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter; @@ -38,6 +39,8 @@ */ class UpgradeComplete extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ @@ -64,6 +67,7 @@ public function run(): int // removing temporary files $this->container->getFileConfigurationStorage()->cleanAll(); + $this->container->getAnalytics()->track('Upgrade Succeeded', Analytics::WITH_UPGRADE_PROPERTIES); return ExitCode::SUCCESS; } diff --git a/classes/TaskRunner/Upgrade/UpgradeDb.php b/classes/Task/Upgrade/UpgradeDb.php similarity index 93% rename from classes/TaskRunner/Upgrade/UpgradeDb.php rename to classes/Task/Upgrade/UpgradeDb.php index 27251c49f..6e6cfb9dc 100644 --- a/classes/TaskRunner/Upgrade/UpgradeDb.php +++ b/classes/Task/Upgrade/UpgradeDb.php @@ -25,11 +25,11 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader\CoreUpgrader; use PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader\CoreUpgrader17; use PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader\CoreUpgrader80; @@ -37,13 +37,15 @@ class UpgradeDb extends AbstractTask { + const TASK_TYPE = 'upgrade'; + public function run(): int { try { $this->getCoreUpgrader()->doUpgrade(); } catch (UpgradeException $e) { $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); foreach ($e->getQuickInfos() as $log) { $this->logger->debug($log); } diff --git a/classes/TaskRunner/Upgrade/UpgradeFiles.php b/classes/Task/Upgrade/UpgradeFiles.php similarity index 98% rename from classes/TaskRunner/Upgrade/UpgradeFiles.php rename to classes/Task/Upgrade/UpgradeFiles.php index 2f1dfee40..0e4e3dbfc 100644 --- a/classes/TaskRunner/Upgrade/UpgradeFiles.php +++ b/classes/Task/Upgrade/UpgradeFiles.php @@ -25,17 +25,19 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter; class UpgradeFiles extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @var string */ diff --git a/classes/TaskRunner/Upgrade/UpgradeModules.php b/classes/Task/Upgrade/UpgradeModules.php similarity index 96% rename from classes/TaskRunner/Upgrade/UpgradeModules.php rename to classes/Task/Upgrade/UpgradeModules.php index fb90907b6..885fe3a86 100644 --- a/classes/TaskRunner/Upgrade/UpgradeModules.php +++ b/classes/Task/Upgrade/UpgradeModules.php @@ -25,19 +25,21 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; /** * Upgrade all partners modules according to the installed prestashop version. */ class UpgradeModules extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ @@ -176,7 +178,7 @@ private function handleException(UpgradeException $e): void } if ($e->getSeverity() === UpgradeException::SEVERITY_ERROR) { $this->next = 'error'; - $this->error = true; + $this->setErrorFlag(); $this->logger->error($e->getMessage()); } if ($e->getSeverity() === UpgradeException::SEVERITY_WARNING) { diff --git a/classes/TaskRunner/Upgrade/UpgradeNow.php b/classes/Task/Upgrade/UpgradeNow.php similarity index 92% rename from classes/TaskRunner/Upgrade/UpgradeNow.php rename to classes/Task/Upgrade/UpgradeNow.php index 9cd50a57f..75ccd8bb8 100644 --- a/classes/TaskRunner/Upgrade/UpgradeNow.php +++ b/classes/Task/Upgrade/UpgradeNow.php @@ -25,11 +25,12 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\Task\Upgrade; use Exception; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\ExitCode; +use PrestaShop\Module\AutoUpgrade\Analytics; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\ExitCode; use PrestaShop\Module\AutoUpgrade\VersionUtils; /** @@ -38,6 +39,8 @@ */ class UpgradeNow extends AbstractTask { + const TASK_TYPE = 'upgrade'; + /** * @throws Exception */ @@ -88,6 +91,7 @@ public function run(): int $this->logger->debug($this->translator->trans('Downloaded archive will come from %s', [$upgrader->link])); $this->logger->debug($this->translator->trans('MD5 hash will be checked against %s', [$upgrader->md5])); } + $this->container->getAnalytics()->track('Upgrade Launched', Analytics::WITH_UPGRADE_PROPERTIES); return ExitCode::SUCCESS; } diff --git a/classes/TaskRunner/Upgrade/index.php b/classes/Task/Upgrade/index.php similarity index 100% rename from classes/TaskRunner/Upgrade/index.php rename to classes/Task/Upgrade/index.php diff --git a/classes/TaskRunner/index.php b/classes/Task/index.php similarity index 100% rename from classes/TaskRunner/index.php rename to classes/Task/index.php diff --git a/classes/Twig/Block/UpgradeButtonBlock.php b/classes/Twig/Block/UpgradeButtonBlock.php index 6bb80137f..7ef094822 100644 --- a/classes/Twig/Block/UpgradeButtonBlock.php +++ b/classes/Twig/Block/UpgradeButtonBlock.php @@ -30,7 +30,7 @@ use Configuration; use PrestaShop\Module\AutoUpgrade\ChannelInfo; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; use PrestaShop\Module\AutoUpgrade\Upgrader; use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; diff --git a/classes/UpgradeContainer.php b/classes/UpgradeContainer.php index b01f5d4a2..ef9211ac2 100644 --- a/classes/UpgradeContainer.php +++ b/classes/UpgradeContainer.php @@ -71,6 +71,11 @@ class UpgradeContainer const PS_VERSION = 'version'; const DB_CONFIG_KEYS = ['PS_DISABLE_OVERRIDES']; + /** + * @var Analytics + */ + private $analytics; + /** * @var CacheCleaner */ @@ -221,6 +226,28 @@ public function getProperty(string $property): string } } + public function getAnalytics(): Analytics + { + if (null !== $this->analytics) { + return $this->analytics; + } + + // The identifier shoudl be a value a value always different between two shops + // But equal between two upgrade processes + return $this->analytics = new Analytics( + $this->getUpgradeConfiguration(), + $this->getState(), + $this->getProperty(self::WORKSPACE_PATH), [ + 'properties' => [ + 'ps_version' => $this->getProperty(self::PS_VERSION), + 'php_version' => PHP_VERSION_ID, + 'autoupgrade_version' => $this->getPrestaShopConfiguration()->getModuleVersion(), + // TODO: Improve this part by having a safe getter + 'disable_all_overrides' => class_exists('\Configuration', false) ? \Configuration::get('PS_DISABLE_OVERRIDES') : null, + ], + ]); + } + /** * Init and return CacheCleaner */ @@ -352,6 +379,7 @@ public function getUpgrader(): Upgrader } } $this->getState()->setInstallVersion($upgrader->version_num); + $this->getState()->setOriginVersion($this->getProperty(self::PS_VERSION)); $this->upgrader = $upgrader; return $this->upgrader; diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php index 2c6cde23e..d8c7d5546 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php @@ -246,7 +246,7 @@ protected function initConstants(): void protected function getPreUpgradeVersion(): string { - return $this->normalizeVersion(\Configuration::get('PS_VERSION_DB')); + return $this->normalizeVersion($this->container->getState()->getOriginVersion()); } /** diff --git a/classes/UpgradeTools/TaskRepository.php b/classes/UpgradeTools/TaskRepository.php index 230ab46fe..2c7e15dd3 100644 --- a/classes/UpgradeTools/TaskRepository.php +++ b/classes/UpgradeTools/TaskRepository.php @@ -27,27 +27,27 @@ namespace PrestaShop\Module\AutoUpgrade\UpgradeTools; -use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous\CheckFilesVersion; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous\CompareReleases; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous\GetChannelInfo; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous\UpdateConfig; -use PrestaShop\Module\AutoUpgrade\TaskRunner\NullTask; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\NoRollbackFound; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\RestoreDb; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\RestoreFiles; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\Rollback; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\RollbackComplete; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\BackupDb; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\BackupFiles; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\CleanDatabase; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\Download; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\Unzip; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\UpgradeComplete; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\UpgradeDb; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\UpgradeFiles; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\UpgradeModules; -use PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\UpgradeNow; +use PrestaShop\Module\AutoUpgrade\Task\AbstractTask; +use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\CheckFilesVersion; +use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\CompareReleases; +use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\GetChannelInfo; +use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\UpdateConfig; +use PrestaShop\Module\AutoUpgrade\Task\NullTask; +use PrestaShop\Module\AutoUpgrade\Task\Rollback\NoRollbackFound; +use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreDb; +use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreFiles; +use PrestaShop\Module\AutoUpgrade\Task\Rollback\Rollback; +use PrestaShop\Module\AutoUpgrade\Task\Rollback\RollbackComplete; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\BackupDb; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\BackupFiles; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\CleanDatabase; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\Download; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\Unzip; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeComplete; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeDb; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeFiles; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeModules; +use PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeNow; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; class TaskRepository diff --git a/cli-rollback.php b/cli-rollback.php index 5cc0c65f3..90943d039 100644 --- a/cli-rollback.php +++ b/cli-rollback.php @@ -33,7 +33,7 @@ $container = autoupgrade_init_container(dirname(__FILE__)); $container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); -$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\AllRollbackTasks($container); +$controller = new \PrestaShop\Module\AutoUpgrade\Task\Runner\AllRollbackTasks($container); $controller->setOptions(getopt('', ['backup::'])); $controller->init(); exit($controller->run()); diff --git a/cli-updateconfig.php b/cli-updateconfig.php index c1657fe43..460934d10 100644 --- a/cli-updateconfig.php +++ b/cli-updateconfig.php @@ -40,7 +40,7 @@ $container = autoupgrade_init_container(dirname(__FILE__)); $container->setLogger(new \PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); -$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous\UpdateConfig($container); +$controller = new \PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\UpdateConfig($container); $controller->inputCliParameters($inputData); $controller->init(); exit($controller->run()); diff --git a/cli-upgrade.php b/cli-upgrade.php index 745c715ea..02753aeef 100644 --- a/cli-upgrade.php +++ b/cli-upgrade.php @@ -40,7 +40,7 @@ $logger = new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger(); $container->setLogger($logger); -$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\AllUpgradeTasks($container); +$controller = new \PrestaShop\Module\AutoUpgrade\Task\Runner\AllUpgradeTasks($container); $controller->setOptions(getopt('', ['action::', 'channel::', 'data::'])); $controller->init(); $exitCode = $controller->run(); diff --git a/composer.json b/composer.json index c9c8a2ce6..8514d703c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "php": ">=7.1", "ext-zip": "*", "symfony/filesystem": "^3.0", - "doctrine/collections": "~1.3.0" + "doctrine/collections": "~1.3.0", + "segmentio/analytics-php": "^1.8" }, "require-dev": { "phpunit/phpunit": "^5", diff --git a/composer.lock b/composer.lock index c8b49b8cb..47a6f063b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "31c3746f204358648b7ebcf4c3a16e9e", + "content-hash": "f5fa53f72144ec38a19d2640d53ba2ba", "packages": [ { "name": "doctrine/collections", @@ -75,6 +75,61 @@ }, "time": "2015-04-14T22:21:58+00:00" }, + { + "name": "segmentio/analytics-php", + "version": "1.8.0", + "source": { + "type": "git", + "url": "https://github.com/segmentio/analytics-php.git", + "reference": "7e25b2f6094632bbfb79e33ca024d533899a2ffe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/segmentio/analytics-php/zipball/7e25b2f6094632bbfb79e33ca024d533899a2ffe", + "reference": "7e25b2f6094632bbfb79e33ca024d533899a2ffe", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "overtrue/phplint": "^1.1", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "^3.3" + }, + "bin": [ + "bin/analytics" + ], + "type": "library", + "autoload": { + "files": [ + "lib/Segment.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Segment.io ", + "homepage": "https://segment.com/" + } + ], + "description": "Segment Analytics PHP Library", + "homepage": "https://segment.com/libraries/php", + "keywords": [ + "analytics", + "analytics.js", + "segment", + "segmentio" + ], + "support": { + "issues": "https://github.com/segmentio/analytics-php/issues", + "source": "https://github.com/segmentio/analytics-php/tree/1.8.0" + }, + "time": "2021-05-31T22:44:22+00:00" + }, { "name": "symfony/filesystem", "version": "v3.4.47", @@ -139,16 +194,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4" + "reference": "0424dff1c58f028c451efff2045f5d92410bd540" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4", - "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", + "reference": "0424dff1c58f028c451efff2045f5d92410bd540", "shasum": "" }, "require": { @@ -198,7 +253,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" }, "funding": [ { @@ -214,7 +269,7 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" } ], "packages-dev": [ @@ -3011,16 +3066,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", - "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", "shasum": "" }, "require": { @@ -3071,7 +3126,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" }, "funding": [ { @@ -3087,7 +3142,7 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-06-19T12:30:46+00:00" }, { "name": "symfony/polyfill-php70", @@ -3159,16 +3214,16 @@ }, { "name": "symfony/polyfill-php72", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25" + "reference": "10112722600777e02d2745716b70c5db4ca70442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/861391a8da9a04cbad2d232ddd9e4893220d6e25", - "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/10112722600777e02d2745716b70c5db4ca70442", + "reference": "10112722600777e02d2745716b70c5db4ca70442", "shasum": "" }, "require": { @@ -3212,7 +3267,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php72/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-php72/tree/v1.30.0" }, "funding": [ { @@ -3228,20 +3283,20 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-06-19T12:30:46+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.29.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" + "reference": "77fa7995ac1b21ab60769b7323d600a991a90433" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", - "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433", + "reference": "77fa7995ac1b21ab60769b7323d600a991a90433", "shasum": "" }, "require": { @@ -3292,7 +3347,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0" }, "funding": [ { @@ -3308,7 +3363,7 @@ "type": "tidelift" } ], - "time": "2024-01-29T20:11:03+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/process", diff --git a/tests/fixtures/listOfFiles-ShopExample.json b/tests/fixtures/listOfFiles-ShopExample.json index 1ef7a0b78..3e897a29c 100644 --- a/tests/fixtures/listOfFiles-ShopExample.json +++ b/tests/fixtures/listOfFiles-ShopExample.json @@ -6195,35 +6195,35 @@ "\/modules\/autoupgrade\/classes\/Parameters\/index.php", "\/modules\/autoupgrade\/classes\/PrestashopConfiguration.php", "\/modules\/autoupgrade\/classes\/State.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/AbstractTask.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/ChainedTasks.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Miscellaneous\/CheckFilesVersion.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Miscellaneous\/CompareReleases.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Miscellaneous\/GetChannelInfo.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Miscellaneous\/UpdateConfig.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Miscellaneous\/index.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/NullTask.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/AllRollbackTasks.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/NoRollbackFound.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/RestoreDb.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/RestoreFiles.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/Rollback.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/RollbackComplete.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Rollback\/index.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/AllUpgradeTasks.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/BackupDb.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/BackupFiles.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/CleanDatabase.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/Download.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/RemoveSamples.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/Unzip.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/UpgradeComplete.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/UpgradeDb.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/UpgradeFiles.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/UpgradeModules.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/UpgradeNow.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/Upgrade\/index.php", - "\/modules\/autoupgrade\/classes\/TaskRunner\/index.php", + "\/modules\/autoupgrade\/classes\/Task\/AbstractTask.php", + "\/modules\/autoupgrade\/classes\/Task\/ChainedTasks.php", + "\/modules\/autoupgrade\/classes\/Task\/Miscellaneous\/CheckFilesVersion.php", + "\/modules\/autoupgrade\/classes\/Task\/Miscellaneous\/CompareReleases.php", + "\/modules\/autoupgrade\/classes\/Task\/Miscellaneous\/GetChannelInfo.php", + "\/modules\/autoupgrade\/classes\/Task\/Miscellaneous\/UpdateConfig.php", + "\/modules\/autoupgrade\/classes\/Task\/Miscellaneous\/index.php", + "\/modules\/autoupgrade\/classes\/Task\/NullTask.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/AllRollbackTasks.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/NoRollbackFound.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/RestoreDb.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/RestoreFiles.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/Rollback.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/RollbackComplete.php", + "\/modules\/autoupgrade\/classes\/Task\/Rollback\/index.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/AllUpgradeTasks.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/BackupDb.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/BackupFiles.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/CleanDatabase.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/Download.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/RemoveSamples.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/Unzip.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/UpgradeComplete.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/UpgradeDb.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/UpgradeFiles.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/UpgradeModules.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/UpgradeNow.php", + "\/modules\/autoupgrade\/classes\/Task\/Upgrade\/index.php", + "\/modules\/autoupgrade\/classes\/Task\/index.php", "\/modules\/autoupgrade\/classes\/Tools14.php", "\/modules\/autoupgrade\/classes\/Twig\/Block\/ChannelInfoBlock.php", "\/modules\/autoupgrade\/classes\/Twig\/Block\/RollbackForm.php", diff --git a/tests/unit/AnalyticsTest.php b/tests/unit/AnalyticsTest.php new file mode 100644 index 000000000..1fde16925 --- /dev/null +++ b/tests/unit/AnalyticsTest.php @@ -0,0 +1,125 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +use PHPUnit\Framework\TestCase; +use PrestaShop\Module\AutoUpgrade\Analytics; +use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; +use PrestaShop\Module\AutoUpgrade\State; + +class AnalyticsTest extends TestCase +{ + public function testProperties() + { + $state = (new State()) + ->setOriginVersion('8.8.8') + ->setInstallVersion('8.8.808') + ->setRestoreName('V1.2.3_blablabla-🐶'); + $upgradeConfiguration = (new UpgradeConfiguration([ + 'PS_AUTOUP_PERFORMANCE' => 5, + 'PS_AUTOUP_CUSTOM_MOD_DESACT' => 0, + 'PS_AUTOUP_UPDATE_DEFAULT_THEME' => 1, + 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 1, + 'PS_AUTOUP_KEEP_MAILS' => 0, + 'PS_AUTOUP_BACKUP' => 1, + 'PS_AUTOUP_KEEP_IMAGES' => 0, + 'channel' => 'major', + 'archive.filename' => 'zip.zip', + ])); + + $analytics = new Analytics( + $upgradeConfiguration, + $state, + 'somePathToAutoupgradeModule', + [ + 'properties' => [ + 'ps_version' => '8.8.8', + 'php_version' => '6.0.8', + 'autoupgrade_version' => '9.8.7', + 'disable_all_overrides' => true, + ], + ] + ); + + $this->assertEquals([ + 'anonymousId' => '3cbc0821f904fd952a8526f17b9b92a8abde4b394a66c9171cf35c9beb2b4784', + 'channel' => 'browser', + 'properties' => array_merge( + [ + 'ps_version' => '8.8.8', + 'php_version' => '6.0.8', + 'autoupgrade_version' => '9.8.7', + 'disable_all_overrides' => true, + 'module' => 'autoupgrade', + ]), + ], + $analytics->getProperties(Analytics::WITH_COMMON_PROPERTIES) + ); + + $this->assertEquals([ + 'anonymousId' => '3cbc0821f904fd952a8526f17b9b92a8abde4b394a66c9171cf35c9beb2b4784', + 'channel' => 'browser', + 'properties' => array_merge( + [ + 'ps_version' => '8.8.8', + 'php_version' => '6.0.8', + 'autoupgrade_version' => '9.8.7', + 'disable_all_overrides' => true, + 'module' => 'autoupgrade', + + 'from_ps_version' => '8.8.8', + 'to_ps_version' => '8.8.808', + 'upgrade_channel' => 'major', + 'backup_files_and_databases' => true, + 'backup_images' => false, + 'server_performance' => 4, + 'disable_non_native_modules' => false, + 'upgrade_default_theme' => true, + 'switch_to_default_theme' => true, + 'regenerate_rtl_stylesheet' => false, + 'keep_customized_email_templates' => false, + ]), + ], + $analytics->getProperties(Analytics::WITH_UPGRADE_PROPERTIES) + ); + + $this->assertEquals([ + 'anonymousId' => '3cbc0821f904fd952a8526f17b9b92a8abde4b394a66c9171cf35c9beb2b4784', + 'channel' => 'browser', + 'properties' => array_merge( + [ + 'ps_version' => '8.8.8', + 'php_version' => '6.0.8', + 'autoupgrade_version' => '9.8.7', + 'disable_all_overrides' => true, + 'module' => 'autoupgrade', + + 'from_ps_version' => '8.8.8', + 'to_ps_version' => '1.2.3', + ]), + ], + $analytics->getProperties(Analytics::WITH_ROLLBACK_PROPERTIES) + ); + } +} diff --git a/tests/unit/ErrorHandlerTest.php b/tests/unit/ErrorHandlerTest.php index 14111a770..f8c140abf 100644 --- a/tests/unit/ErrorHandlerTest.php +++ b/tests/unit/ErrorHandlerTest.php @@ -81,8 +81,8 @@ public function testGeneratedJsonLog($log) public function logProvider() { return [ - ["[INTERNAL] /var/www/html/modules/autoupgrade/classes/TaskRunner/Upgrade/BackupFiles.php line 55 - Class 'PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\UpgradeContainer' not found"], - ["[INTERNAL] /var/www/html/modules/autoupgrade/classes/TaskRunner/Upgrade/BackupDb.php line 105 - Can't use method return value in write context"], + ["[INTERNAL] /var/www/html/modules/autoupgrade/classes/Task/Upgrade/BackupFiles.php line 55 - Class 'PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeContainer' not found"], + ["[INTERNAL] /var/www/html/modules/autoupgrade/classes/Task/Upgrade/BackupDb.php line 105 - Can't use method return value in write context"], ]; } } diff --git a/tests/unit/StateTest.php b/tests/unit/StateTest.php index 0529c0427..c5ddcb851 100644 --- a/tests/unit/StateTest.php +++ b/tests/unit/StateTest.php @@ -89,4 +89,21 @@ public function testClassReceivesPropertyFromEncodedData() $this->assertSame($modules, $state->getModules_addons()); $this->assertSame($modules, $exported['modules_addons']); } + + public function testGetRestoreVersion() + { + $state = new State(); + + $this->assertSame( + '1.7.8.11', + $state->setRestoreName('V1.7.8.11_20240604-170048-3ceb32b2') + ->getRestoreVersion() + ); + + $this->assertSame( + '8.1.6', + $state->setRestoreName('V8.1.6_20240604-170048-3ceb32b2') + ->getRestoreVersion() + ); + } }