From fa364c2b2f9e4e9e6f509cda324afc0d7c286112 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Wed, 15 Dec 2021 15:33:58 +0100 Subject: [PATCH] fix: [metaTemplate] Repaired update_all --- src/Controller/MetaTemplatesController.php | 29 ++++++++++++++++++++++ templates/MetaTemplates/update_all.php | 14 ++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Controller/MetaTemplatesController.php b/src/Controller/MetaTemplatesController.php index 32bef92..0c4277c 100644 --- a/src/Controller/MetaTemplatesController.php +++ b/src/Controller/MetaTemplatesController.php @@ -61,6 +61,35 @@ class MetaTemplatesController extends AppController // } // } + public function updateAllTemplates() + { + if ($this->request->is('post')) { + $result = $this->MetaTemplates->updateAllTemplates(); + if ($this->ParamHandler->isRest()) { + return $this->RestResponse->viewData($result, 'json'); + } else { + if ($result['success']) { + $message = __n('{0} templates updated.', 'The template has been updated.', empty($template_id), $result['files_processed']); + } else { + $message = __n('{0} templates could not be updated.', 'The template could not be updated.', empty($template_id), $result['files_processed']); + } + $this->CRUD->setResponseForController('updateAllTemplate', $result['success'], $message, $result['files_processed'], $result['update_errors'], ['redirect' => $this->referer()]); + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; + } + } + } else { + if (!$this->ParamHandler->isRest()) { + $this->set('title', __('Update All Meta Templates')); + $this->set('question', __('Are you sure you wish to update all the Meta Template definitions')); + $templatesUpdateStatus = $this->MetaTemplates->getUpdateStatusForTemplates(); + $this->set('templatesUpdateStatus', $templatesUpdateStatus); + $this->render('updateAll'); + } + } + } + /** * Update the provided template or all templates * diff --git a/templates/MetaTemplates/update_all.php b/templates/MetaTemplates/update_all.php index 3e7a425..643af88 100644 --- a/templates/MetaTemplates/update_all.php +++ b/templates/MetaTemplates/update_all.php @@ -6,6 +6,7 @@ $modalType = 'confirm'; $modalSize = 'lg'; $tableHtml = ''; +$tableHtml .= sprintf('', __('ID')); $tableHtml .= sprintf('', __('Template')); $tableHtml .= sprintf('', __('Version')); $tableHtml .= sprintf('', __('New Template')); @@ -17,6 +18,14 @@ $numberOfUpdates = 0; $numberOfSkippedUpdates = 0; foreach ($templatesUpdateStatus as $uuid => $status) { $tableHtml .= ''; + if (!empty($status['new'])) { + $tableHtml .= sprintf('', __('N/A')); + } else { + $tableHtml .= sprintf('', + Router::url(['controller' => 'MetaTemplates', 'action' => 'view', 'plugin' => null, h($status['existing_template']->id)]), + h($status['existing_template']->id) + ); + } if (!empty($status['new'])) { $tableHtml .= sprintf('', h($uuid)); } else { @@ -53,7 +62,10 @@ foreach ($templatesUpdateStatus as $uuid => $status) { if (!empty($status['new'])) { $tableHtml .= sprintf('', $this->Bootstrap->icon('check', ['class' => 'text-success'])); } else { - if (!empty($status['new']) || !empty($status['automatically-updateable'])) { + // Depends on the strategy used by the update_all function. Right now, every update create a brand new template + // leaving existing data untouched. So regardless of the conflict, the new template will be created + // if (!empty($status['new']) || !empty($status['automatically-updateable'])) { + if (!empty($status['new']) || empty($status['up-to-date'])) { $numberOfUpdates += 1; $tableHtml .= sprintf('', $this->Bootstrap->icon('check', ['class' => 'text-success'])); } else {
%s%s%s%s
%s%s%s%s%s