From 7eab3f881186f510e8fe4a24f4cefe7ece9e9047 Mon Sep 17 00:00:00 2001 From: matks Date: Wed, 2 Dec 2020 17:21:37 +0100 Subject: [PATCH 01/16] Add some badges in README --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index 5d560f7da..4cbbc0144 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,10 @@ # 1-Click Upgrade [![Build Status](https://travis-ci.com/PrestaShop/autoupgrade.svg?branch=dev)](https://travis-ci.com/PrestaShop/autoupgrade) +![PHP tests](https://github.com/PrestaShop/autoupgrade/workflows/PHP%20tests/badge.svg) +[![Latest Stable Version](https://poser.pugx.org/PrestaShop/autoupgrade/v)](//packagist.org/packages/PrestaShop/autoupgrade) +[![Total Downloads](https://poser.pugx.org/PrestaShop/autoupgrade/downloads)](//packagist.org/packages/PrestaShop/autoupgrade) +[![GitHub license](https://img.shields.io/github/license/PrestaShop/autoupgrade)](https://github.com/PrestaShop/autoupgrade/LICENSE.md) ## About From d00f76f5c2d31150f87b18a25a065f0d65604853 Mon Sep 17 00:00:00 2001 From: matks Date: Wed, 2 Dec 2020 17:23:56 +0100 Subject: [PATCH 02/16] Add LICENSE file --- LICENSE.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..5e4bd602c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,47 @@ +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + +1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + a) to reproduce the Original Work in copies, either alone or as part of a collective work; + + b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + c) to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + d) to perform the Original Work publicly; and + + e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + +5) External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + +6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + +9) Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + +10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + +12) Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + +13) Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + +16) Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. From 0c4a6e21e782d552875e7337c4b574c0c0db32f2 Mon Sep 17 00:00:00 2001 From: matks Date: Thu, 3 Dec 2020 14:43:56 +0100 Subject: [PATCH 03/16] Improve README --- Readme.md | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/Readme.md b/Readme.md index 4cbbc0144..a04daafb3 100644 --- a/Readme.md +++ b/Readme.md @@ -66,43 +66,26 @@ The following parameters are mandatory: $ php cli-rollback.php --dir=admin-dev --backup=V1.7.5.1_20190502-191341-22e883bd ``` -## Contributing +# Documentation -PrestaShop modules are open-source extensions to the PrestaShop e-commerce solution. Everyone is welcome and even encouraged to contribute with their own improvements. +Documentation is hosted on [devdocs.prestashop.com][doc]. -To contribute on this project, start by cloning the repository. -You must have [composer][4] installed on your computer. Run the following command: +# Contributing -``` -$ composer install -``` - -Your module will be available with development libraries. - -### GitHub Requirements - -Contributors **must** follow the following rules: +PrestaShop modules are open source extensions to the [PrestaShop e-commerce platform][prestashop]. Everyone is welcome and even encouraged to contribute with their own improvements! -* **Make your Pull Request on the "dev" branch**, NOT the "master" branch. -* Do not update the module's version number. -* Follow [the coding standards][1]. +Just make sure to follow our [contribution guidelines][contribution-guidelines]. -### Process in details +## Reporting issues -Contributors wishing to edit a module's files should follow the following process: +You can report issues with this module in the main PrestaShop repository. [Click here to report an issue][report-issue]. -1. Create your GitHub account, if you do not have one already. -2. Fork the autoupgrade project to your GitHub account. -3. Clone your fork to your local machine in the ```/modules``` directory of your PrestaShop installation. -4. Create a branch in your local clone of the module for your changes. -5. Change the files in your branch. Be sure to follow [the coding standards][1]! -6. Push your changed branch to your fork in your GitHub account. -7. Create a pull request for your changes **on the _'dev'_ branch** of the module's project. Be sure to follow [the commit message norm][2] in your pull request. If you need help to make a pull request, read the [Github help page about creating pull requests][3]. -8. Wait for one of the core developers either to include your change in the codebase, or to comment on possible improvements you should make to your code. +# License -That's it: you have contributed to this open-source project! Congratulations! +This module is released under the [Academic Free License 3.0][AFL-3.0] -[1]: http://doc.prestashop.com/display/PS16/Coding+Standards -[2]: http://doc.prestashop.com/display/PS16/How+to+write+a+commit+message -[3]: https://help.github.com/articles/using-pull-requests -[4]: https://getcomposer.org/download/ +[report-issue]: https://github.com/PrestaShop/PrestaShop/issues/new/choose +[prestashop]: https://www.prestashop.com/ +[contribution-guidelines]: https://devdocs.prestashop.com/1.7/contribute/contribution-guidelines/project-modules/ +[AFL-3.0]: https://opensource.org/licenses/AFL-3.0 +[doc]: https://devdocs.prestashop.com/1.7/development/upgrade-module/ From f2095f0bd0531e30d2a6de10ab13d304eb604cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20H?= Date: Sun, 13 Dec 2020 21:40:43 +0100 Subject: [PATCH 04/16] Fix error with private method and upgrade --- autoupgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoupgrade.php b/autoupgrade.php index f876022b5..bc16cace9 100644 --- a/autoupgrade.php +++ b/autoupgrade.php @@ -162,7 +162,7 @@ public function uninstall() * * @return bool */ - private function registerHookAndSetToTop($hookName) + public function registerHookAndSetToTop($hookName) { return $this->registerHook($hookName) && $this->updatePosition((int) Hook::getIdByName($hookName), 0); } From db74f0035c877883e89649d55a2ec655abf09b55 Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Fri, 8 Jan 2021 17:31:29 +0100 Subject: [PATCH 05/16] Migrate upgrade test to Github Actions --- .github/Dockerfile | 14 ++++ .github/action.yml | 37 ++++++++++ .github/action_upgrade.sh | 10 +++ .github/get_matrix.php | 31 ++++++++ .github/workflows/nigthly_upgrade.yml | 30 ++++++++ .github/workflows/php.yml | 2 +- .github/workflows/upgrade.yml | 26 +++++++ .../TaskRunner/Miscellaneous/UpdateConfig.php | 72 ++++++++++++++----- cli-updateconfig.php | 47 ++++++++++++ docker-compose.yml | 6 +- 10 files changed, 255 insertions(+), 20 deletions(-) create mode 100644 .github/Dockerfile create mode 100644 .github/action.yml create mode 100755 .github/action_upgrade.sh create mode 100644 .github/get_matrix.php create mode 100644 .github/workflows/nigthly_upgrade.yml create mode 100644 .github/workflows/upgrade.yml create mode 100644 cli-updateconfig.php diff --git a/.github/Dockerfile b/.github/Dockerfile new file mode 100644 index 000000000..181b97346 --- /dev/null +++ b/.github/Dockerfile @@ -0,0 +1,14 @@ +FROM prestashop/base:7.1-apache +LABEL maintainer="PrestaShop Core Team " + +ARG VERSION +ENV PS_VERSION $VERSION + +# Get PrestaShop +ADD https://www.prestashop.com/download/old/prestashop_${PS_VERSION}.zip /tmp/prestashop.zip + +# Extract +RUN mkdir -p /tmp/data-ps \ + && unzip -q /tmp/prestashop.zip -d /tmp/data-ps/ \ + && bash /tmp/ps-extractor.sh /tmp/data-ps \ + && rm /tmp/prestashop.zip diff --git a/.github/action.yml b/.github/action.yml new file mode 100644 index 000000000..bcf224874 --- /dev/null +++ b/.github/action.yml @@ -0,0 +1,37 @@ +name: Upgrade +description: Test PrestaShop upgrade process +runs: + using: composite + steps: + - name: Build docker compose stack + env: + VERSION: ${{ matrix.ps-versions.from }} + shell: bash + run: | + docker-compose -f docker-compose.yml up -d + bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" != "200" ]]; do sleep 5; done' + - name: Copy autoupgrade module + shell: bash + run: docker exec -u www-data prestashop_autoupgrade cp modules/autoupgrade/ -R admin-dev + - name: Upgrade (major) + env: + CHANNEL: ${{ matrix.ps-versions.channel }} + ARCHIVE_URL: ${{ matrix.ps-versions.file }} + VERSION: ${{ matrix.ps-versions.version }} + shell: bash + run: ${{ github.action_path }}/action_upgrade.sh + - name: Check endpoints response + shell: bash + run: | + bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]' + bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' + - name: Rollback + shell: bash + run: docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php \ + admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" \ + --backup=`docker exec prestashop_autoupgrade bash -c "ls -td -- /var/www/html/admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f8 | tr -d '\n'"`; + - name: Check endpoints response + shell: bash + run: | + bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]' + bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' diff --git a/.github/action_upgrade.sh b/.github/action_upgrade.sh new file mode 100755 index 000000000..399c0a6e0 --- /dev/null +++ b/.github/action_upgrade.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [[ $CHANNEL == "archive" ]]; then + docker exec -u www-data prestashop_autoupgrade mkdir admin-dev/autoupgrade/download + docker exec -u www-data prestashop_autoupgrade curl $ARCHIVE_URL -o admin-dev/autoupgrade/download/prestashop.zip + echo "{\"channel\":\"archive\",\"archive_prestashop\":\"prestashop.zip\",\"archive_num\":\"${VERSION}\"}" > config.json + docker exec -u www-data prestashop_autoupgrade php admin-dev/autoupgrade/cli-updateconfig.php --from=modules/autoupgrade/config.json --dir=admin-dev +fi + +docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL" diff --git a/.github/get_matrix.php b/.github/get_matrix.php new file mode 100644 index 000000000..9a642f7e7 --- /dev/null +++ b/.github/get_matrix.php @@ -0,0 +1,31 @@ + "1.7.6.9", + "channel" => "archive", + "version" => getVersionFromFilename($report['download']), + "file" => $report['download'] + ]; + } +} + +function getVersionFromFilename($filename) { + $matches = []; + preg_match('/^.*prestashop_(.*)\.zip$/', $filename, $matches); + + return $matches[1]; +} + +echo json_encode($matrix); diff --git a/.github/workflows/nigthly_upgrade.yml b/.github/workflows/nigthly_upgrade.yml new file mode 100644 index 000000000..576d12cfb --- /dev/null +++ b/.github/workflows/nigthly_upgrade.yml @@ -0,0 +1,30 @@ +name: Nightly Upgrades +on: + schedule: + - cron: '0 0 * * *' +jobs: + get_matrix: + name: Set up matrix + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + - id: set-matrix + run: echo "::set-output name=matrix::$(php ./.github/get_matrix.php)" + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + upgrade: + needs: get_matrix + strategy: + matrix: + ps-versions: ${{ fromJson(needs.get_matrix.outputs.matrix) }} + runs-on: ubuntu-latest + name: Upgrade + steps: + - uses: actions/checkout@v2 + - name: Composer Install + run: composer install + - name: Upgrade & Rollback + uses: ./.github/ diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5a3524adb..6e7d11385 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -18,4 +18,4 @@ jobs: fetch-depth: 0 - run: composer install --prefer-dist - - run: ./vendor/phpunit/phpunit/phpunit tests \ No newline at end of file + - run: ./vendor/phpunit/phpunit/phpunit tests diff --git a/.github/workflows/upgrade.yml b/.github/workflows/upgrade.yml new file mode 100644 index 000000000..fe3b876a1 --- /dev/null +++ b/.github/workflows/upgrade.yml @@ -0,0 +1,26 @@ +name: Upgrades +on: [push, pull_request] +jobs: + upgrade: + strategy: + matrix: + ps-versions: + - from: 1.6.1.11 + channel: minor + # Failing for now + #- from: 1.6.1.24 + # channel: major + - from: 1.7.6.9 + channel: major + - from: 1.7.6.1 + channel: minor + - from: 1.7.7.0 + channel: minor + runs-on: ubuntu-latest + name: Upgrade + steps: + - uses: actions/checkout@v2 + - name: Composer Install + run: composer install + - name: Upgrade & Rollback + uses: ./.github/ diff --git a/classes/TaskRunner/Miscellaneous/UpdateConfig.php b/classes/TaskRunner/Miscellaneous/UpdateConfig.php index 48d60bebc..67cd35c04 100644 --- a/classes/TaskRunner/Miscellaneous/UpdateConfig.php +++ b/classes/TaskRunner/Miscellaneous/UpdateConfig.php @@ -38,61 +38,73 @@ */ class UpdateConfig extends AbstractTask { + /** + * @var bool + */ + protected $isRunInCLI = false; + + /** + * Data being passed by CLI entry point + * + * @var array + */ + protected $cliParameters; + public function run() { // nothing next $this->next = ''; // Was coming from AdminSelfUpgrade::currentParams before - $request = $this->getRequestParams(); + $configurationData = $this->getConfigurationData(); $config = array(); // update channel - if (isset($request['channel'])) { - $config['channel'] = $request['channel']; + if (isset($configurationData['channel'])) { + $config['channel'] = $configurationData['channel']; $config['archive.filename'] = Upgrader::DEFAULT_FILENAME; // Switch on default theme if major upgrade (i.e: 1.6 -> 1.7) - $config['PS_AUTOUP_CHANGE_DEFAULT_THEME'] = ($request['channel'] === 'major'); + $config['PS_AUTOUP_CHANGE_DEFAULT_THEME'] = ($configurationData['channel'] === 'major'); } - if (isset($request['private_release_link'], $request['private_release_md5'])) { + if (isset($configurationData['private_release_link'], $configurationData['private_release_md5'])) { $config['channel'] = 'private'; - $config['private_release_link'] = $request['private_release_link']; - $config['private_release_md5'] = $request['private_release_md5']; - $config['private_allow_major'] = $request['private_allow_major']; + $config['private_release_link'] = $configurationData['private_release_link']; + $config['private_release_md5'] = $configurationData['private_release_md5']; + $config['private_allow_major'] = $configurationData['private_allow_major']; } // if (!empty($request['archive_name']) && !empty($request['archive_num'])) - if (!empty($request['archive_prestashop'])) { - $file = $request['archive_prestashop']; + if (!empty($configurationData['archive_prestashop'])) { + $file = $configurationData['archive_prestashop']; if (!file_exists($this->container->getProperty(UpgradeContainer::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $file)) { $this->error = true; $this->logger->info($this->translator->trans('File %s does not exist. Unable to select that channel.', array($file), 'Modules.Autoupgrade.Admin')); return false; } - if (empty($request['archive_num'])) { + if (empty($configurationData['archive_num'])) { $this->error = true; $this->logger->info($this->translator->trans('Version number is missing. Unable to select that channel.', array(), 'Modules.Autoupgrade.Admin')); return false; } $config['channel'] = 'archive'; - $config['archive.filename'] = $request['archive_prestashop']; - $config['archive.version_num'] = $request['archive_num']; + $config['archive.filename'] = $configurationData['archive_prestashop']; + $config['archive.version_num'] = $configurationData['archive_num']; // $config['archive_name'] = $request['archive_name']; $this->logger->info($this->translator->trans('Upgrade process will use archive.', array(), 'Modules.Autoupgrade.Admin')); } - if (isset($request['directory_num'])) { + if (isset($configurationData['directory_num'])) { $config['channel'] = 'directory'; - if (empty($request['directory_num']) || strpos($request['directory_num'], '.') === false) { + if (empty($configurationData['directory_num']) || strpos($configurationData['directory_num'], '.') === false) { $this->error = true; $this->logger->info($this->translator->trans('Version number is missing. Unable to select that channel.', array(), 'Modules.Autoupgrade.Admin')); return false; } - $config['directory.version_num'] = $request['directory_num']; + $config['directory.version_num'] = $configurationData['directory_num']; } - if (isset($request['skip_backup'])) { - $config['skip_backup'] = $request['skip_backup']; + if (isset($configurationData['skip_backup'])) { + $config['skip_backup'] = $configurationData['skip_backup']; } if (!$this->writeConfig($config)) { @@ -101,6 +113,30 @@ public function run() } } + public function inputCliParameters($parameters) + { + $this->isRunInCLI = true; + $this->cliParameters = $parameters; + } + + protected function getConfigurationData() + { + if ($this->isRunInCLI) { + return $this->getCLIParams(); + } + + return $this->getRequestParams(); + } + + protected function getCLIParams() + { + if (empty($this->cliParameters)) { + throw new \RuntimeException('Empty CLI parameters - did CLI entry point failed to provide data?'); + } + + return $this->cliParameters; + } + protected function getRequestParams() { return empty($_REQUEST['params']) ? array() : $_REQUEST['params']; diff --git a/cli-updateconfig.php b/cli-updateconfig.php new file mode 100644 index 000000000..ab31693c9 --- /dev/null +++ b/cli-updateconfig.php @@ -0,0 +1,47 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ + +if (PHP_SAPI !== 'cli') { + echo 'This script must be called from CLI'; + exit(1); +} + +$inputConfigurationFile = getopt('', array('from::'))['from']; +if (!file_exists($inputConfigurationFile)) { + echo sprintf('Invalid input configuation file %s', $inputConfigurationFile).PHP_EOL; + exit(1); +} + +$inputData = json_decode(file_get_contents($inputConfigurationFile), true); + +require_once realpath(dirname(__FILE__).'/../../modules/autoupgrade') . '/ajax-upgradetabconfig.php'; +$container = autoupgrade_init_container(dirname(__FILE__)); + +$container->setLogger(new \PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); +$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Miscellaneous\UpdateConfig($container); +$controller->inputCliParameters($inputData); +$controller->init(); +exit($controller->run()); diff --git a/docker-compose.yml b/docker-compose.yml index bdbbbb43b..84a60facf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,11 @@ services: reference-release: container_name: prestashop_autoupgrade - image: prestashop/prestashop:${VERSION} + build: + context: . + dockerfile: ./.github/Dockerfile + args: + VERSION: $VERSION volumes: - ./:/var/www/html/modules/autoupgrade - temp-ps:/var/www/html # Used for another container which needs PrestaShop content From d40089bb284fcb695d98750319ea7421654f26fa Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Wed, 13 Jan 2021 11:40:42 +0100 Subject: [PATCH 06/16] Migrate phpstan to Github Actions --- .github/get_matrix.php | 4 +-- .github/workflows/php.yml | 43 ++++++++++++++++++++++++++++++-- tests/phpstan/phpstan-PS-16.neon | 14 +++++------ tests/phpstan/phpstan.neon | 10 ++++---- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/.github/get_matrix.php b/.github/get_matrix.php index 9a642f7e7..e89ca34b9 100644 --- a/.github/get_matrix.php +++ b/.github/get_matrix.php @@ -2,9 +2,9 @@ $matrix = []; -$nightlyEnpoint = "https://api-nightly.prestashop.com/reports"; +$nightlyEndpoint = "https://api-nightly.prestashop.com/reports"; -$reports = json_decode(file_get_contents($nightlyEnpoint), true); +$reports = json_decode(file_get_contents($nightlyEndpoint), true); $currentDate = ""; foreach ($reports as $report) { $date = strtotime($report['date']); diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6e7d11385..a579ac1c1 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,7 +1,7 @@ name: PHP tests on: [push, pull_request] jobs: - build: + php-unit: strategy: matrix: php-versions: ['5.6', '7.1', '7.2','7.4'] @@ -13,9 +13,48 @@ jobs: with: php-version: ${{ matrix.php-versions }} extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv, ext-zip - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 with: fetch-depth: 0 - run: composer install --prefer-dist - run: ./vendor/phpunit/phpunit/phpunit tests + + phpstan: + name: PHPStan + runs-on: ubuntu-latest + strategy: + matrix: + presta-versions: [ '1.6.1.11', '1.7.6.9', 'latest' ] + steps: + - name: Checkout + uses: actions/checkout@v2.0.0 + + - name: Cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: php-${{ hashFiles('composer.lock') }} + + - name: Cache composer folder + uses: actions/cache@v1 + with: + path: ~/.composer/cache + key: php-composer-cache + + - run: composer install + + - name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }}) + env: + PS_VERSION: ${{ matrix.presta-versions }} + IS_16: ${{ startsWith(matrix.presta-versions, '1.6') }} + run: | + PHPSTAN_FILE="phpstan.neon" && [[ $IS_16 == true ]] && PHPSTAN_FILE="phpstan-PS-16.neon" + echo $PHPSTAN_FILE + docker rm -f temp-ps || true + docker volume rm -f ps-volume || true + docker run -d --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION + docker exec -t temp-ps rm -rf /var/www/html/modules/autoupgrade + docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/autoupgrade \ + -e _PS_ROOT_DIR_=/var/www/html --workdir=/var/www/html/modules/autoupgrade \quetzacoalt/phpstan \ + analyse --configuration=/var/www/html/modules/autoupgrade/tests/phpstan/$PHPSTAN_FILE diff --git a/tests/phpstan/phpstan-PS-16.neon b/tests/phpstan/phpstan-PS-16.neon index ac7837203..4b809ffcb 100644 --- a/tests/phpstan/phpstan-PS-16.neon +++ b/tests/phpstan/phpstan-PS-16.neon @@ -3,16 +3,16 @@ # Its objective is to avoid false-positive results regarding non-existing classes ################################################################################# parameters: - bootstrap: /web/module/tests/phpstan/bootstrap.php + bootstrap: ./tests/phpstan/bootstrap.php reportUnmatchedIgnoredErrors: false paths: - - /web/module/classes + - ./classes excludes_analyse: - - /web/module/classes/Tools14.php - - /web/module/classes/pclzip.lib.php - - /web/module/functions.php - - /web/module/classes/UpgradeTools/CoreUpgrader/CoreUpgrader17.php - - /web/module/classes/UpgradeTools/SymfonyAdapter.php + - ./classes/Tools14.php + - ./classes/pclzip.lib.php + - ./functions.php + - ./classes/UpgradeTools/CoreUpgrader/CoreUpgrader17.php + - ./classes/UpgradeTools/SymfonyAdapter.php ignoreErrors: # module specific - '#Function deactivate_custom_modules not found.#' diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index d1ba98844..731f2a4c6 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -1,12 +1,12 @@ parameters: - bootstrap: /web/module/tests/phpstan/bootstrap.php + bootstrap: ./tests/phpstan/bootstrap.php reportUnmatchedIgnoredErrors: false paths: - - /web/module/classes + - ./classes excludes_analyse: - - /web/module/classes/Tools14.php - - /web/module/classes/pclzip.lib.php - - /web/module/functions.php + - ./classes/Tools14.php + - ./classes/pclzip.lib.php + - ./functions.php ignoreErrors: # module specific - '#Function deactivate_custom_modules not found.#' From 2f45e42504047531a78df9a5413e9a25ee1014b8 Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Mon, 18 Jan 2021 11:42:27 +0100 Subject: [PATCH 07/16] Add nightly upgrade results to the nightly-board --- .github/get_matrix.php | 1 + .github/get_results.php | 96 +++++++++++++++++++++++++++ .github/workflows/nigthly_upgrade.yml | 29 +++++++- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .github/get_results.php diff --git a/.github/get_matrix.php b/.github/get_matrix.php index e89ca34b9..82c51ab85 100644 --- a/.github/get_matrix.php +++ b/.github/get_matrix.php @@ -15,6 +15,7 @@ $matrix[] = [ "from" => "1.7.6.9", "channel" => "archive", + "branch" => $report['version'], "version" => getVersionFromFilename($report['download']), "file" => $report['download'] ]; diff --git a/.github/get_results.php b/.github/get_results.php new file mode 100644 index 000000000..ff2219390 --- /dev/null +++ b/.github/get_results.php @@ -0,0 +1,96 @@ + [ + 'start' => $result['date_start']->format('Y-m-d H:i:s'), + 'end' => $result['date_end']->format('Y-m-d H:i:s'), + 'duration' => $result['duration'], + 'skipped' => 0, + 'pending' => 0, + 'passes' => $testPassed ? 1 : 0, + 'failures' => $testPassed ? 0 : 1, + 'suites' => 1, + 'tests' => 1, + ], + 'suites' => [ + 'uuid' => uniqid(), + 'title' => $result['title'], + 'file' => '', + 'duration' => $result['duration'], + 'hasSkipped' => false, + 'hasPending' => false, + 'hasPasses' => $testPassed > 0, + 'hasFailures' => $testPassed === 0, + 'totalSkipped' => 0, + 'totalPending' => 0, + 'totalPasses' => $testPassed ? 1 : 0, + 'totalFailures' => $testPassed ? 0 : 1, + 'hasSuites' => true, + 'hasTests' => false, + 'tests' => [], + 'suites' => [[ + 'uuid' => uniqid(), + 'title' => $result['title'], + 'file' => '', + 'duration' => $result['duration'], + 'hasSkipped' => false, + 'hasPending' => false, + 'hasPasses' => $testPassed > 0, + 'hasFailures' => $testPassed === 0, + 'totalSkipped' => 0, + 'totalPending' => 0, + 'totalPasses' => $testPassed ? 1 : 0, + 'totalFailures' => $testPassed ? 0 : 1, + 'hasSuites' => false, + 'hasTests' => true, + 'suites' => [], + 'tests' => [$result], + ]], + ], +]; + +$filename = 'autoupgrade_' . date('Y-m-d') . '-' . $branch . '.json'; +file_put_contents($filename, json_encode($data)); + +function getTestResultFromFile($file) +{ + $data = explode('|', trim(file_get_contents($file))); + $dateStart = getDateTimeFromString($data[2]); + $dateEnd = getDateTimeFromString($data[3]); + $duration = ($dateEnd->getTimestamp() - $dateStart->getTimestamp()) * 1000; + $state = $data[4] === 'success' ? 'passed' : 'failed'; + $error = null; + if ($state !== 'passed') { + $error = [ + 'message' => sprintf( + '%s/%s/actions/runs/%s', + getenv('GITHUB_SERVER_URL'), + getenv('GITHUB_REPOSITORY'), + getenv('GITHUB_RUN_ID') + ) + ]; + } + + return [ + 'uuid' => uniqid(), + 'title' => 'Upgrade to ' . $data[1], + 'context' => '{"value": "Upgrade to ' . $data[1] . '"}', + 'skipped' => [], + 'pending' => [], + 'duration' => $duration, + 'state' => $state, + 'err' => $error, + 'date_start' => $dateStart, + 'date_end' => $dateEnd, + 'branch' => $data[0] + ]; +} + +function getDateTimeFromString($datetime) +{ + return DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $datetime, new DateTimeZone('UTC')); +} diff --git a/.github/workflows/nigthly_upgrade.yml b/.github/workflows/nigthly_upgrade.yml index 576d12cfb..6a277daa8 100644 --- a/.github/workflows/nigthly_upgrade.yml +++ b/.github/workflows/nigthly_upgrade.yml @@ -16,15 +16,42 @@ jobs: outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} upgrade: + continue-on-error: true needs: get_matrix strategy: + fail-fast: false matrix: ps-versions: ${{ fromJson(needs.get_matrix.outputs.matrix) }} runs-on: ubuntu-latest name: Upgrade + outputs: + result: ${{ steps.export-result.outputs.result }} steps: - uses: actions/checkout@v2 - name: Composer Install - run: composer install + run: | + composer install + echo "START_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`" >> $GITHUB_ENV - name: Upgrade & Rollback + id: upgrade-rollback uses: ./.github/ + - name: Format result + if: ${{ always() }} + run: | + export END_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` + echo "${{matrix.ps-versions.branch}}|${{matrix.ps-versions.version}}|$START_DATE|$END_DATE|${{steps.upgrade-rollback.outcome}}" > result.txt + php ./.github/get_results.php + - name: Set up Cloud SDK + if: ${{ always() }} + uses: google-github-actions/setup-gcloud@master + with: + project_id: ${{ secrets.GCP_PROJECT_ID }} + service_account_key: ${{ secrets.GCP_SA_KEY }} + export_default_credentials: true + - name: Push results to the nightly board + if: ${{ always() }} + run: | + export TODAY=`date -u +"%Y-%m-%d"` + export FILENAME=autoupgrade_$TODAY-${{matrix.ps-versions.branch}}.json + gsutil cp $FILENAME gs://prestashop-core-nightly/reports + curl -X GET "https://api-nightly.prestashop.com/hook/add?filename=$FILENAME&platform=cli&campaign=autoupgrade&token=${{ secrets.QANB_TOKEN }}" From 8c19e50af2c0e02a330626ee6da1b07fe389766f Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Tue, 19 Jan 2021 17:24:42 +0100 Subject: [PATCH 08/16] Delete travis --- .travis.yml | 57 ----------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2a05e5fb2..000000000 --- a/.travis.yml +++ /dev/null @@ -1,57 +0,0 @@ -language: php -services: docker - -php: - - '5.6' - -env: - - VERSION=1.7.2.2 - CHANNEL=major - - VERSION=1.6 - CHANNEL=major - - VERSION=1.6.1.10 - CHANNEL=minor - # Check how the upgrade behaves with the latest PrestaShop - - VERSION=latest - CHANNEL=minor - -cache: - directories: - - $HOME/.composer/cache - -install: - - composer install - - docker-compose up -d - -before_script: - - bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" != "200" ]]; do sleep 5; done' - - docker exec -u www-data -ti prestashop_autoupgrade cp modules/autoupgrade/ -R admin-dev - -script: - # PHP Stan - - if [[ $VERSION == "1.6" ]] || [[ $VERSION == 1\.6* ]]; then - export PHPSTAN_FILE=phpstan-PS-16.neon; - else - export PHPSTAN_FILE=phpstan.neon; - fi - - docker run --rm --volumes-from prestashop_autoupgrade -v $PWD:/web/module -e _PS_ROOT_DIR_=/var/www/html quetzacoalt/phpstan analyse --configuration=/web/module/tests/phpstan/$PHPSTAN_FILE; - - # Upgrade - - docker exec -u www-data -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL" - # Front office -> HTTP code 200 expected (no maintenance) - - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]' - # Back office -> HTTP code 200 expected - - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' - - # Rollback (only when expect a completed upgrade) - - if [ $VERSION != "latest" ]; then - docker exec -u www-data -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" --backup=`docker exec -ti prestashop_autoupgrade bash -c "ls -td -- /var/www/html/admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f8 | tr -d '\n'"`; - fi - # Front office -> HTTP code 200 expected (no maintenance) - - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]' - # Back office -> HTTP code 200 expected - - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' - -after_script: - - docker ps - - docker logs prestashop_autoupgrade From 33c257da2416f578b6fca5d6e810f592917dc22a Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Fri, 22 Jan 2021 11:56:42 +0100 Subject: [PATCH 09/16] Simplify CLI parameters handling --- classes/TaskRunner/Miscellaneous/UpdateConfig.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/classes/TaskRunner/Miscellaneous/UpdateConfig.php b/classes/TaskRunner/Miscellaneous/UpdateConfig.php index 67cd35c04..13b9aaca4 100644 --- a/classes/TaskRunner/Miscellaneous/UpdateConfig.php +++ b/classes/TaskRunner/Miscellaneous/UpdateConfig.php @@ -38,11 +38,6 @@ */ class UpdateConfig extends AbstractTask { - /** - * @var bool - */ - protected $isRunInCLI = false; - /** * Data being passed by CLI entry point * @@ -115,13 +110,12 @@ public function run() public function inputCliParameters($parameters) { - $this->isRunInCLI = true; $this->cliParameters = $parameters; } protected function getConfigurationData() { - if ($this->isRunInCLI) { + if (null !== $this->cliParameters) { return $this->getCLIParams(); } From 0e17be6c7ea7919782401d01f3ca08e97afa77c7 Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Fri, 8 Jan 2021 16:18:20 +0100 Subject: [PATCH 10/16] Clear cache before enabling theme --- classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php index 2d1fc6a6e..6fc88f3ea 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php @@ -27,6 +27,7 @@ namespace PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader; +use Cache; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; use PrestaShop\Module\AutoUpgrade\UpgradeException; use PrestaShop\Module\AutoUpgrade\UpgradeTools\ThemeAdapter; @@ -680,6 +681,8 @@ protected function updateTheme() $this->logger->info($this->container->getTranslator()->trans('Switching to default theme.', array(), 'Modules.Autoupgrade.Admin')); $themeAdapter = new ThemeAdapter($this->db, $this->destinationUpgradeVersion); + Cache::clean('*'); + $themeErrors = $themeAdapter->enableTheme( $themeAdapter->getDefaultTheme() ); From 0bbc6f4e380ccba0fbf9edc8cb3d3d4c3dda1259 Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Fri, 29 Jan 2021 15:55:03 +0100 Subject: [PATCH 11/16] Use official phpstan with php 7.4 --- .github/workflows/php.yml | 5 +++-- composer.json | 5 ++--- composer.lock | 3 ++- tests/phpstan/Dockerfile | 29 ++++++++++++++++++++++++++--- tests/phpstan/phpstan-PS-16.neon | 17 +++++++++-------- tests/phpstan/phpstan.neon | 11 ++++++----- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a579ac1c1..bcb55edbe 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - presta-versions: [ '1.6.1.11', '1.7.6.9', 'latest' ] + presta-versions: [ '1.6.1.18', '1.7.6.9', 'latest' ] steps: - name: Checkout uses: actions/checkout@v2.0.0 @@ -55,6 +55,7 @@ jobs: docker volume rm -f ps-volume || true docker run -d --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION docker exec -t temp-ps rm -rf /var/www/html/modules/autoupgrade + docker build -t phpstan:php-7.4 ./tests/phpstan/ docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/autoupgrade \ - -e _PS_ROOT_DIR_=/var/www/html --workdir=/var/www/html/modules/autoupgrade \quetzacoalt/phpstan \ + -e _PS_ROOT_DIR_=/var/www/html --workdir=/var/www/html/modules/autoupgrade phpstan:php-7.4 \ analyse --configuration=/var/www/html/modules/autoupgrade/tests/phpstan/$PHPSTAN_FILE diff --git a/composer.json b/composer.json index e25b06417..dba824339 100644 --- a/composer.json +++ b/composer.json @@ -32,8 +32,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^5", - "prestashop/php-dev-tools": "^2" + "phpunit/phpunit": "^5" }, "author": "PrestaShop" -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 0756f08fc..456ad3865 100644 --- a/composer.lock +++ b/composer.lock @@ -1521,5 +1521,6 @@ "platform-dev": [], "platform-overrides": { "php": "5.6" - } + }, + "plugin-api-version": "2.0.0" } diff --git a/tests/phpstan/Dockerfile b/tests/phpstan/Dockerfile index 7e1083a78..b974d9552 100644 --- a/tests/phpstan/Dockerfile +++ b/tests/phpstan/Dockerfile @@ -1,3 +1,26 @@ -FROM phpstan/phpstan:latest -RUN apk --update --progress --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.7/community add \ - php7-zip +FROM php:7.4-cli-alpine + +RUN php --version + +ENV COMPOSER_HOME /composer +ENV COMPOSER_ALLOW_SUPERUSER 1 +ENV PATH /composer/vendor/bin:$PATH +ENV PHP_CONF_DIR=/usr/local/etc/php/conf.d + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +RUN echo "memory_limit=-1" > $PHP_CONF_DIR/99_memory-limit.ini \ + && apk add git \ + && rm -rf /var/cache/apk/* /var/tmp/* /tmp/* + +RUN composer global require phpstan/phpstan \ + && rm -rf /composer/vendor/phpstan/phpstan/.git \ + && composer clear-cache + +VOLUME ["/app"] +WORKDIR /app + +ENV PHPSTAN_PRO_WEB_PORT=11111 +EXPOSE 11111 + +ENTRYPOINT ["phpstan"] \ No newline at end of file diff --git a/tests/phpstan/phpstan-PS-16.neon b/tests/phpstan/phpstan-PS-16.neon index 4b809ffcb..390113d09 100644 --- a/tests/phpstan/phpstan-PS-16.neon +++ b/tests/phpstan/phpstan-PS-16.neon @@ -3,16 +3,17 @@ # Its objective is to avoid false-positive results regarding non-existing classes ################################################################################# parameters: - bootstrap: ./tests/phpstan/bootstrap.php + bootstrapFiles: + - ./../../tests/phpstan/bootstrap.php reportUnmatchedIgnoredErrors: false paths: - - ./classes + - ./../../classes excludes_analyse: - - ./classes/Tools14.php - - ./classes/pclzip.lib.php - - ./functions.php - - ./classes/UpgradeTools/CoreUpgrader/CoreUpgrader17.php - - ./classes/UpgradeTools/SymfonyAdapter.php + - ./../../classes/Tools14.php + - ./../../classes/pclzip.lib.php + - ./../../functions.php + - ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader17.php + - ./../../classes/UpgradeTools/SymfonyAdapter.php ignoreErrors: # module specific - '#Function deactivate_custom_modules not found.#' @@ -30,6 +31,6 @@ parameters: - '#PrestaShop\\Module\\AutoUpgrade\\UpgradeTools\\ModuleAdapter#' - '#PrestaShop\\PrestaShop\\Adapter\\Module\\ModuleDataUpdater#' - '#PrestaShopBundle\\Install\\Upgrade#' - - '#Call to an undefined static method ConfigurationTest::test_curl().#' + - '#Call to an undefined static method ConfigurationTest::test_curl\(\).#' level: 5 \ No newline at end of file diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index 731f2a4c6..2f11860eb 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -1,12 +1,13 @@ parameters: - bootstrap: ./tests/phpstan/bootstrap.php + bootstrapFiles: + - ./../../tests/phpstan/bootstrap.php reportUnmatchedIgnoredErrors: false paths: - - ./classes + - ./../../classes excludes_analyse: - - ./classes/Tools14.php - - ./classes/pclzip.lib.php - - ./functions.php + - ./../../classes/Tools14.php + - ./../../classes/pclzip.lib.php + - ./../../functions.php ignoreErrors: # module specific - '#Function deactivate_custom_modules not found.#' From d3a9d54327dd6e98f3d16ab84277ca4f684c7180 Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Fri, 29 Jan 2021 15:55:24 +0100 Subject: [PATCH 12/16] Fix phpstan --- classes/TaskRunner/Upgrade/BackupDb.php | 4 +--- classes/Tools14.php | 4 ++-- classes/UpgradeContainer.php | 2 ++ classes/UpgradePage.php | 2 +- classes/UpgradeTools/ModuleAdapter.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/classes/TaskRunner/Upgrade/BackupDb.php b/classes/TaskRunner/Upgrade/BackupDb.php index ef26d2102..b06f86833 100644 --- a/classes/TaskRunner/Upgrade/BackupDb.php +++ b/classes/TaskRunner/Upgrade/BackupDb.php @@ -262,9 +262,7 @@ public function run() $this->logger->debug($this->translator->trans('%s tables have been saved.', array($found), 'Modules.Autoupgrade.Admin')); $this->next = 'backupDb'; $this->stepDone = false; - if (count($tablesToBackup)) { - $this->logger->info($this->translator->trans('Database backup: %s table(s) left...', array(count($tablesToBackup)), 'Modules.Autoupgrade.Admin')); - } + $this->logger->info($this->translator->trans('Database backup: %s table(s) left...', array(count($tablesToBackup)), 'Modules.Autoupgrade.Admin')); return true; } diff --git a/classes/Tools14.php b/classes/Tools14.php index eda0fa06e..40929c38f 100755 --- a/classes/Tools14.php +++ b/classes/Tools14.php @@ -1434,9 +1434,9 @@ public static function file_get_contents($url, $use_include_path = false, $strea curl_close($curl); return $content; - } else { - return false; } + + return false; } public static function simplexml_load_file($url, $class_name = null) diff --git a/classes/UpgradeContainer.php b/classes/UpgradeContainer.php index 06947a488..f482dbd43 100644 --- a/classes/UpgradeContainer.php +++ b/classes/UpgradeContainer.php @@ -198,6 +198,8 @@ public function getProperty($property) return $this->getProperty(self::DOWNLOAD_PATH) . DIRECTORY_SEPARATOR . $this->getProperty(self::ARCHIVE_FILENAME); case self::PS_VERSION: return $this->getPrestaShopConfiguration()->getPrestaShopVersion(); + default: + return ''; } } diff --git a/classes/UpgradePage.php b/classes/UpgradePage.php index 498c886c1..7dfa2d98f 100644 --- a/classes/UpgradePage.php +++ b/classes/UpgradePage.php @@ -261,7 +261,7 @@ private function getUpgradeOptionsForm() } /** - * @return array|null + * @return array */ private function getErrorMessage() { diff --git a/classes/UpgradeTools/ModuleAdapter.php b/classes/UpgradeTools/ModuleAdapter.php index 3c6f7c753..2456d95fb 100644 --- a/classes/UpgradeTools/ModuleAdapter.php +++ b/classes/UpgradeTools/ModuleAdapter.php @@ -166,7 +166,7 @@ public function upgradeModule($id, $name) continue; } - if ($content === null) { + if (empty($content)) { $msg = '' . $this->translator->trans('[ERROR] No response from Addons server.', array(), 'Modules.Autoupgrade.Admin') . ''; throw new UpgradeException($msg); } From e3e686dfc6da07956d0067a01150ff974ebe746c Mon Sep 17 00:00:00 2001 From: matks Date: Tue, 9 Feb 2021 10:01:07 +0100 Subject: [PATCH 13/16] Bump v4.12.0 --- autoupgrade.php | 2 +- config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoupgrade.php b/autoupgrade.php index bc16cace9..5f0b22542 100644 --- a/autoupgrade.php +++ b/autoupgrade.php @@ -31,7 +31,7 @@ public function __construct() $this->name = 'autoupgrade'; $this->tab = 'administration'; $this->author = 'PrestaShop'; - $this->version = '4.11.0'; + $this->version = '4.12.0'; $this->need_instance = 1; $this->bootstrap = true; diff --git a/config.xml b/config.xml index 066c27a25..20815f462 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ autoupgrade - + From bf396cfb41313d16000a6067e0d726a654cbb1fe Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Tue, 9 Feb 2021 10:19:38 +0100 Subject: [PATCH 14/16] Fix phpstan --- classes/Log/Logger.php | 6 +++--- classes/ZipAction.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/classes/Log/Logger.php b/classes/Log/Logger.php index 9919f7693..df24b581f 100644 --- a/classes/Log/Logger.php +++ b/classes/Log/Logger.php @@ -96,7 +96,7 @@ public function warning($message, array $context = array()) * Equivalent of the old $nextErrors * Used during upgrade. Will be displayed in the top right panel (not visible at the beginning). * - * @var array Details of error which occured during the request. Verbose levels: ERROR + * @return array Details of error which occured during the request. Verbose levels: ERROR */ public function getErrors() { @@ -107,7 +107,7 @@ public function getErrors() * Equivalent of the old $nextQuickInfo * Used during upgrade. Will be displayed in the lower panel. * - * @var array Details on what happened during the execution. Verbose levels: DEBUG / INFO / WARNING + * @return array Details on what happened during the execution. Verbose levels: DEBUG / INFO / WARNING */ public function getInfos() { @@ -119,7 +119,7 @@ public function getInfos() * Equivalent of the old $next_desc * Used during upgrade. Will be displayed on the top left panel. * - * @var string Stores the main information about the current step + * @return string Stores the main information about the current step */ public function getLastInfo() { diff --git a/classes/ZipAction.php b/classes/ZipAction.php index 520989c5c..8d019bd6b 100644 --- a/classes/ZipAction.php +++ b/classes/ZipAction.php @@ -64,7 +64,7 @@ public function __construct($translator, LoggerInterface $logger, UpgradeConfigu * Add files to an archive. * Note the number of files added can be limited. * - * @var array List of files to add + * @var array $filesList List of files to add * @var string $toFile */ public function compress(&$filesList, $toFile) @@ -174,7 +174,7 @@ public function extract($from_file, $to_dir) /** * Lists the files present in the given archive * - * @var string Path to the file + * @var string $zipfile Path to the file * * @return array */ @@ -202,7 +202,7 @@ public function listContent($zipfile) /** * Get the path of a file from the archive root * - * @var string Path of the file on the filesystem + * @var string $filepath Path of the file on the filesystem * * @return string Path of the file in the backup archive */ @@ -214,7 +214,7 @@ private function getFilepathInArchive($filepath) /** * Checks a file size matches the given limits * - * @var string Path to a file + * @var string $filepath Path to a file * * @return bool Size is inside the maximum limit */ @@ -239,8 +239,8 @@ private function isFileWithinFileSizeLimit($filepath) /** * Open an archive * - * @var string Path to the archive - * @var int ZipArchive flags + * @var string $zipFile Path to the archive + * @var int $flags ZipArchive flags * * @return false|\ZipArchive */ From 4816de14d32a3e1cae4da3ff28157e76dd525d01 Mon Sep 17 00:00:00 2001 From: matks Date: Tue, 9 Feb 2021 10:21:09 +0100 Subject: [PATCH 15/16] Replace Travis (deprecated) badge by GitHub Action Upgrade badge --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index a04daafb3..b081f058c 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,7 @@ # 1-Click Upgrade -[![Build Status](https://travis-ci.com/PrestaShop/autoupgrade.svg?branch=dev)](https://travis-ci.com/PrestaShop/autoupgrade) ![PHP tests](https://github.com/PrestaShop/autoupgrade/workflows/PHP%20tests/badge.svg) +![Upgrades](https://github.com/PrestaShop/autoupgrade/workflows/Upgrades/badge.svg) [![Latest Stable Version](https://poser.pugx.org/PrestaShop/autoupgrade/v)](//packagist.org/packages/PrestaShop/autoupgrade) [![Total Downloads](https://poser.pugx.org/PrestaShop/autoupgrade/downloads)](//packagist.org/packages/PrestaShop/autoupgrade) [![GitHub license](https://img.shields.io/github/license/PrestaShop/autoupgrade)](https://github.com/PrestaShop/autoupgrade/LICENSE.md) From 9d403e211769fa8ea9f847931d61c56b22623694 Mon Sep 17 00:00:00 2001 From: Thomas BACCELLI Date: Wed, 10 Feb 2021 15:07:25 +0100 Subject: [PATCH 16/16] Update GCP secret keys --- .github/workflows/nigthly_upgrade.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nigthly_upgrade.yml b/.github/workflows/nigthly_upgrade.yml index 6a277daa8..4d6c0d9be 100644 --- a/.github/workflows/nigthly_upgrade.yml +++ b/.github/workflows/nigthly_upgrade.yml @@ -45,8 +45,8 @@ jobs: if: ${{ always() }} uses: google-github-actions/setup-gcloud@master with: - project_id: ${{ secrets.GCP_PROJECT_ID }} - service_account_key: ${{ secrets.GCP_SA_KEY }} + project_id: ${{ secrets.GC_PROJECT_ID }} + service_account_key: ${{ secrets.GC_SERVICE_KEY }} export_default_credentials: true - name: Push results to the nightly board if: ${{ always() }}