Skip to content

Commit

Permalink
Display the success message after a complete backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Dec 10, 2024
1 parent dfcfcf9 commit 2b2d342
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 18 deletions.
1 change: 0 additions & 1 deletion _dev/tests/utils/Stepper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,4 @@ describe('Stepper', () => {
stepper.setCurrentStep('🐕');
checkStepsStatus();
});

});
3 changes: 2 additions & 1 deletion classes/Parameters/UpgradeFileNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ class UpgradeFileNames
* @var array<string, string>
*/
public static $backup_tmp_files = [
'STATE_FILENAME' => self::STATE_FILENAME,
// TODO: Needs the split of state files to avoid dropping data useful for the update on the web UI
// 'STATE_FILENAME' => self::STATE_FILENAME,
'FILES_TO_BACKUP_LIST' => self::FILES_TO_BACKUP_LIST,
'DB_TABLES_TO_BACKUP_LIST' => self::DB_TABLES_TO_BACKUP_LIST,
];
Expand Down
4 changes: 4 additions & 0 deletions classes/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public function __construct(UpgradeContainer $upgradeContainer)
'controller' => UpdatePageBackupController::class,
'method' => 'step',
],
Routes::UPDATE_PAGE_POST_BACKUP => [
'controller' => UpdatePageBackupController::class,
'method' => 'saveBackupIsCompleted',
],
Routes::UPDATE_PAGE_UPDATE => [
'controller' => UpdatePageUpdateController::class,
'method' => 'index',
Expand Down
17 changes: 17 additions & 0 deletions classes/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class State
* @var string
*/
private $backupDbFilename;
/**
* @var bool Marks the backup done during the update configuration
*/
private $backupCompleted = false;
/**
* @var string
*/
Expand Down Expand Up @@ -222,6 +226,11 @@ public function getBackupDbFilename(): string
return $this->backupDbFilename;
}

public function isBackupCompleted(): bool
{
return $this->backupCompleted;
}

/**
* @return string[]|null
*/
Expand Down Expand Up @@ -327,6 +336,14 @@ public function setBackupName(string $backupName): State
return $this;
}

public function setBackupCompleted(bool $completed): State
{
$this->backupCompleted = $completed;
$this->save();

return $this;
}

/**
* @param string[]|null $backup_lines
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UpdatePageBackupController extends AbstractPageWithStepController
const CURRENT_STEP = UpdateSteps::STEP_BACKUP;

/**
* @inheritdoc
* {@inheritdoc}
*/
public function index()
{
Expand All @@ -63,6 +63,13 @@ protected function displayRouteInUrl(): ?string
return Routes::UPDATE_PAGE_BACKUP;
}

public function saveBackupIsCompleted(): JsonResponse
{
$this->upgradeContainer->getState()->setBackupCompleted(true);

return AjaxResponseBuilder::nextRouteResponse(Routes::UPDATE_STEP_BACKUP_OPTIONS);
}

public function getDownloadLogsButton(): JsonResponse
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration;
use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
use PrestaShop\Module\AutoUpgrade\Router\Routes;
use PrestaShop\Module\AutoUpgrade\Task\TaskType;
use PrestaShop\Module\AutoUpgrade\Twig\PageSelectors;
use PrestaShop\Module\AutoUpgrade\Twig\UpdateSteps;
use PrestaShop\Module\AutoUpgrade\Twig\ValidatorToFormFormater;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function submitBackup(): JsonResponse
public function submitUpdate(): JsonResponse
{
return $this->displayDialog('dialog-update', [
'noBackUp' => !$this->request->request->getBoolean('backupDone', false),
'backup_completed' => $this->upgradeContainer->getState()->isBackupCompleted(),
'dialogId' => 'dialog-confirm-update',

'form_route_to_confirm' => Routes::UPDATE_STEP_BACKUP_CONFIRM_UPDATE,
Expand Down Expand Up @@ -118,9 +119,15 @@ protected function getParams(): array
$upgradeConfiguration = $this->upgradeContainer->getUpgradeConfiguration();
$updateSteps = new UpdateSteps($this->upgradeContainer->getTranslator());

$logsPath = $this->upgradeContainer->getDownloadLogsPath(TaskType::TASK_TYPE_BACKUP);

return array_merge(
$updateSteps->getStepParams($this::CURRENT_STEP),
[
'backup_completed' => $this->upgradeContainer->getState()->isBackupCompleted(),
'download_path' => $logsPath,
'filename' => basename($logsPath),

'form_route_to_save' => Routes::UPDATE_STEP_BACKUP_SAVE_OPTION,
'form_route_to_submit_backup' => Routes::UPDATE_STEP_BACKUP_SUBMIT_BACKUP,
'form_route_to_submit_update' => Routes::UPDATE_STEP_BACKUP_SUBMIT_UPDATE,
Expand Down
2 changes: 1 addition & 1 deletion storybook/stories/components/DialogUpdate.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export const Update = {
args: {
...Dialog.args,
dialogSize: "lg",
noBackUp: false,
backup_completed: true,
},
};
4 changes: 2 additions & 2 deletions views/templates/dialogs/dialog-update.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
id="form-confirm-update"
name="form-confirm-update"
>
{% if noBackUp %}
{% if not backup_completed %}
<p>
{{ 'Before starting the update, make sure you have a complete and recent backup of your store (database, files, and images).'|trans({}) }}
</p>
Expand All @@ -21,7 +21,7 @@
{% endblock %}

{% block dialog_extra_content %}
{% if noBackUp %}
{% if not backup_completed %}
<div class="dialog__no-backup checkbox">
<label>
<input type="checkbox" value="" id="dialog-start-update-own-backup" />
Expand Down
45 changes: 34 additions & 11 deletions views/templates/steps/backup-options.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@
</p>
</div>

<div class="backup-page__section">
{% if backup_completed %}
<div class="check-requirements check-requirements--success">
{% include "@ModuleAutoUpgrade/components/alert.html.twig" with {
title: 'Backup completed',
message: 'It is available at /your-admin-directory/autoupgrade/backup. You\'re ready to start the update now.'|trans({}),
alertStatus: 'success',
buttonLabel: 'Download backup logs'|trans({}),
buttonUrl: download_path,
buttonDownload: filename,
} %}
</div>
{% endif %}
<div class="
backup-page__section
{% if backup_completed %}hidden{% endif %}
">
<form
class="update-backup-page__field-list"
action=""
Expand All @@ -39,14 +54,22 @@
{% endblock %}

{% block buttons_inner %}
<button class="btn btn-lg btn-default" type="button"
id="update-backup-page-skip-btn"
>
{{ 'Update without backup'|trans({}) }}
</button>
<button class="btn btn-lg btn-primary" type="submit"
form="update-backup-page-form"
>
{{ 'Launch backup'|trans({}) }}
</button>
{% if backup_completed %}
<button class="btn btn-lg btn-primary" type="button"
id="update-backup-page-skip-btn"
>
{{ 'Start update'|trans({}) }}
</button>
{% else %}
<button class="btn btn-lg btn-default" type="button"
id="update-backup-page-skip-btn"
>
{{ 'Update without backup'|trans({}) }}
</button>
<button class="btn btn-lg btn-primary" type="submit"
form="update-backup-page-form"
>
{{ 'Launch backup'|trans({}) }}
</button>
{% endif %}
{% endblock %}
6 changes: 6 additions & 0 deletions views/templates/steps/backup.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
{% endblock %}

{% block content %}
<div class="backup-page__section">
<p>
{{ "Backing up your store's files, database, and images means you can restore to a previous version if something goes wrong during the update. This keeps your data safe and ensures your business stays up and running."|trans({}) }}
</p>
</div>

{% include "@ModuleAutoUpgrade/components/alert.html.twig" with {
id: 'error-alert',
hidden: true,
Expand Down

0 comments on commit 2b2d342

Please sign in to comment.