chg: [meta-template:update] Default update strategy to be `create_new`

pull/89/head
Sami Mokaddem 2022-03-09 08:21:27 +01:00
parent 7a16c2c792
commit 39d89efb53
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 9 additions and 6 deletions

View File

@ -24,7 +24,8 @@ class MetaTemplatesTable extends AppTable
public const UPDATE_STRATEGY_KEEP_BOTH = 'keep_both'; public const UPDATE_STRATEGY_KEEP_BOTH = 'keep_both';
public const UPDATE_STRATEGY_DELETE = 'delete_all'; public const UPDATE_STRATEGY_DELETE = 'delete_all';
public $ALLOWED_STRATEGIES = [MetaTemplatesTable::UPDATE_STRATEGY_CREATE_NEW]; public const DEFAULT_STRATEGY = MetaTemplatesTable::UPDATE_STRATEGY_CREATE_NEW;
public const ALLOWED_STRATEGIES = [MetaTemplatesTable::UPDATE_STRATEGY_CREATE_NEW];
private $templatesOnDisk = null; private $templatesOnDisk = null;
@ -59,7 +60,7 @@ class MetaTemplatesTable extends AppTable
public function isStrategyAllowed(string $strategy): bool public function isStrategyAllowed(string $strategy): bool
{ {
return in_array($strategy, $this->ALLOWED_STRATEGIES); return in_array($strategy, MetaTemplatesTable::ALLOWED_STRATEGIES);
} }
/** /**
@ -118,9 +119,10 @@ class MetaTemplatesTable extends AppTable
$success = $this->saveNewMetaTemplate($templateOnDisk, $errors); $success = $this->saveNewMetaTemplate($templateOnDisk, $errors);
} else if ($this->isStrategyAllowed(MetaTemplatesTable::UPDATE_STRATEGY_UPDATE_EXISTING) && $updateStatus['automatically-updateable']) { } else if ($this->isStrategyAllowed(MetaTemplatesTable::UPDATE_STRATEGY_UPDATE_EXISTING) && $updateStatus['automatically-updateable']) {
$success = $this->updateMetaTemplate($metaTemplate, $templateOnDisk, $errors); $success = $this->updateMetaTemplate($metaTemplate, $templateOnDisk, $errors);
} else if (!$updateStatus['up-to-date'] && (is_null($strategy) || !$this->isStrategyAllowed($strategy))) { } else if (!$updateStatus['up-to-date'] && (!is_null($strategy) && !$this->isStrategyAllowed($strategy))) {
$errors['message'] = __('Cannot update meta-template, update strategy not provided or not allowed'); $errors['message'] = __('Cannot update meta-template, update strategy not allowed');
} else if (!$updateStatus['up-to-date'] && !is_null($strategy)) { } else if (!$updateStatus['up-to-date']) {
$strategy = is_null($strategy) ? MetaTemplatesTable::DEFAULT_STRATEGY : $strategy;
$success = $this->updateMetaTemplateWithStrategyRouter($metaTemplate, $templateOnDisk, $strategy, $errors); $success = $this->updateMetaTemplateWithStrategyRouter($metaTemplate, $templateOnDisk, $strategy, $errors);
} else { } else {
$errors['message'] = __('Could not update. Something went wrong.'); $errors['message'] = __('Could not update. Something went wrong.');

View File

@ -1,4 +1,5 @@
<?php <?php
use App\Model\Table\MetaTemplatesTable;
$bodyHtml = ''; $bodyHtml = '';
$modalType = 'confirm'; $modalType = 'confirm';
@ -27,7 +28,7 @@ if ($updateStatus['up-to-date']) {
[ [
'field' => 'update_strategy', 'field' => 'update_strategy',
'type' => 'checkbox', 'type' => 'checkbox',
'value' => 'update', 'value' => MetaTemplatesTable::UPDATE_STRATEGY_CREATE_NEW,
'checked' => true, 'checked' => true,
] ]
], ],