Skip to content

Commit

Permalink
Create backup command
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Pichat committed Oct 4, 2024
1 parent b7c9c71 commit 55616aa
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 28 deletions.
20 changes: 10 additions & 10 deletions .github/action_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ if [[ $CHANNEL == "local" ]]; then
fi
fi

SKIP_BACKUP=$(docker exec -u www-data prestashop_autoupgrade ls admin-dev/autoupgrade/backup/ | wc -l)
if [[ "$SKIP_BACKUP" > 1 ]]; then
SKIP_BACKUP=1
else
SKIP_BACKUP=0
fi

docker exec -u www-data prestashop_autoupgrade mkdir admin-dev/autoupgrade/download
docker exec -u www-data prestashop_autoupgrade curl -L $ARCHIVE_URL -o admin-dev/autoupgrade/download/prestashop.zip
docker exec -u www-data prestashop_autoupgrade curl -L $XML_URL -o modules/autoupgrade/download/prestashop.xml
echo "{\"channel\":\"local\",\"archive_prestashop\":\"prestashop.zip\",\"archive_num\":\"${VERSION}\", \"archive_xml\":\"prestashop.xml\", \"PS_AUTOUP_CHANGE_DEFAULT_THEME\":${UPDATE_THEME}, \"skip_backup\": ${SKIP_BACKUP}}" > modules/autoupgrade/config.json
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console update:start --action="compareReleases" --config-file-path="modules/autoupgrade/config.json" admin-dev

FILE_COUNT=$(docker exec -u www-data prestashop_autoupgrade ls admin-dev/autoupgrade/backup/ | wc -l)
if [[ "$FILE_COUNT" == 0 ]]; then
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console backup:create admin-dev
fi

echo "{\"channel\":\"local\",\"archive_prestashop\":\"prestashop.zip\",\"archive_num\":\"${VERSION}\", \"archive_xml\":\"prestashop.xml\", \"PS_AUTOUP_CHANGE_DEFAULT_THEME\":${UPDATE_THEME}" > modules/autoupgrade/config.json
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console update:start --action="CompareReleases" --config-file-path="modules/autoupgrade/config.json" admin-dev
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console update:start --config-file-path="modules/autoupgrade/config.json" admin-dev
fi

docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console update:start --action="compareReleases" admin-dev
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console backup:create admin-dev
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console update:start --action="CompareReleases" admin-dev
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/bin/console update:start admin-dev
1 change: 1 addition & 0 deletions .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
- name: Upgrade
run: |
docker exec -t prestashop php modules/autoupgrade/bin/console backup:create admin-dev
docker exec -t prestashop php modules/autoupgrade/bin/console update:start --channel=${{ matrix.UPGRADE_CHANNEL }} admin-dev
docker exec -t prestashop chmod 777 -R /var/www/html/var/cache/dev
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ jobs:
matrix:
from: ['1.7.0.6', '1.7.6.9', '1.7.6.1', '1.7.7.0', '8.0.0', '8.1.0']
ps-versions:
- channel: minor
- channel: major
- channel: online
runs-on: ubuntu-latest
name: Upgrade
steps:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ The requirements can be reviewed to confirm the shop is safe to update:
$ php bin/console update:check <your-admin-dir>
```

You can create backup with the following command:

```
$ php bin/console backup:create --config-file-path=[/path/to/config.json] <your-admin-dir>
```

The update process can be launched with:

```
Expand Down
2 changes: 2 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

use PrestaShop\Module\AutoUpgrade\Commands\CheckRequirementsCommand;
use PrestaShop\Module\AutoUpgrade\Commands\CreateBackupCommand;
use PrestaShop\Module\AutoUpgrade\Commands\RestoreCommand;
use PrestaShop\Module\AutoUpgrade\Commands\UpdateCommand;
use Symfony\Component\Console\Application;
Expand All @@ -46,6 +47,7 @@ $application = new Application();
$application->add(new UpdateCommand());
$application->add(new RestoreCommand());
$application->add(new CheckRequirementsCommand());
$application->add(new CreateBackupCommand());

try {
$application->run();
Expand Down
72 changes: 72 additions & 0 deletions classes/Commands/CreateBackupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\Commands;

use Exception;
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
use PrestaShop\Module\AutoUpgrade\Task\Runner\AllBackupTasks;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CreateBackupCommand extends AbstractCommand
{
/** @var string */
protected static $defaultName = 'backup:create';

protected function configure(): void
{
$this
->setDescription('Create backup.')
->setHelp('This command allows you to create backup.')
->addOption('config-file-path', null, InputOption::VALUE_REQUIRED, 'Configuration file location.')
->addArgument('admin-dir', InputArgument::REQUIRED, 'The admin directory name.');
}

/**
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): ?int
{
try {
$this->setupContainer($input, $output);

$controller = new AllBackupTasks($this->upgradeContainer);
$controller->init();
$exitCode = $controller->run();
$this->logger->debug('Process completed with exit code: ' . $exitCode);

return $exitCode;
} catch (Exception $e) {
$this->logger->error('An error occurred during the backup process: ' . $e->getMessage());

return ExitCode::FAIL;
}
}
}
8 changes: 4 additions & 4 deletions classes/Progress/CompletionCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
use PrestaShop\Module\AutoUpgrade\Task\Backup\BackupDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Backup\BackupFiles;
use PrestaShop\Module\AutoUpgrade\Task\Backup\BackupInitialization;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\Restore;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreComplete;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreFiles;
use PrestaShop\Module\AutoUpgrade\Task\Restore\Restore;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreComplete;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreFiles;
use PrestaShop\Module\AutoUpgrade\Task\Update\CleanDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Update\Download;
use PrestaShop\Module\AutoUpgrade\Task\Update\Unzip;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Restore/NoRestoreFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

namespace PrestaShop\Module\AutoUpgrade\Task\Rollback;
namespace PrestaShop\Module\AutoUpgrade\Task\Restore;

use PrestaShop\Module\AutoUpgrade\Task\AbstractTask;
use PrestaShop\Module\AutoUpgrade\Task\ExitCode;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Restore/Restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

namespace PrestaShop\Module\AutoUpgrade\Task\Rollback;
namespace PrestaShop\Module\AutoUpgrade\Task\Restore;

use Exception;
use PrestaShop\Module\AutoUpgrade\Analytics;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Restore/RestoreComplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

namespace PrestaShop\Module\AutoUpgrade\Task\Rollback;
namespace PrestaShop\Module\AutoUpgrade\Task\Restore;

use PrestaShop\Module\AutoUpgrade\Analytics;
use PrestaShop\Module\AutoUpgrade\Task\AbstractTask;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Restore/RestoreDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

namespace PrestaShop\Module\AutoUpgrade\Task\Rollback;
namespace PrestaShop\Module\AutoUpgrade\Task\Restore;

use Exception;
use PrestaShop\Module\AutoUpgrade\Backup\BackupFinder;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Restore/RestoreFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/

namespace PrestaShop\Module\AutoUpgrade\Task\Rollback;
namespace PrestaShop\Module\AutoUpgrade\Task\Restore;

use Exception;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Runner/AllBackupTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
class AllBackupTasks extends ChainedTasks
{
const initialTask = TaskName::TASK_BACKUP_FILES;
const initialTask = TaskName::TASK_BACKUP_INITIALIZATION;

/**
* @var string
Expand Down
10 changes: 5 additions & 5 deletions classes/UpgradeTools/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\CompareReleases;
use PrestaShop\Module\AutoUpgrade\Task\Miscellaneous\UpdateConfig;
use PrestaShop\Module\AutoUpgrade\Task\NullTask;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\NoRestoreFound;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\Restore;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreComplete;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreFiles;
use PrestaShop\Module\AutoUpgrade\Task\Restore\NoRestoreFound;
use PrestaShop\Module\AutoUpgrade\Task\Restore\Restore;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreComplete;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreFiles;
use PrestaShop\Module\AutoUpgrade\Task\TaskName;
use PrestaShop\Module\AutoUpgrade\Task\Update\CleanDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Update\Download;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Progress/CompletionCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use PHPUnit\Framework\TestCase;
use PrestaShop\Module\AutoUpgrade\Progress\Backlog;
use PrestaShop\Module\AutoUpgrade\Progress\CompletionCalculator;
use PrestaShop\Module\AutoUpgrade\Task\Rollback\RestoreFiles;
use PrestaShop\Module\AutoUpgrade\Task\Restore\RestoreFiles;
use PrestaShop\Module\AutoUpgrade\Task\Runner\SingleTask;
use PrestaShop\Module\AutoUpgrade\Task\Update\UpdateDatabase;
use PrestaShop\Module\AutoUpgrade\Task\Update\UpdateFiles;
Expand Down

0 comments on commit 55616aa

Please sign in to comment.