fix: [metaTemplate] Repaired update_all

pull/93/head
Sami Mokaddem 2021-12-15 15:33:58 +01:00
parent 02cc0c30a3
commit fa364c2b2f
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 42 additions and 1 deletions

View File

@ -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
*

View File

@ -6,6 +6,7 @@ $modalType = 'confirm';
$modalSize = 'lg';
$tableHtml = '<table class="table"><thead><tr>';
$tableHtml .= sprintf('<th class="text-nowrap">%s</th>', __('ID'));
$tableHtml .= sprintf('<th class="text-nowrap">%s</th>', __('Template'));
$tableHtml .= sprintf('<th class="text-nowrap">%s</th>', __('Version'));
$tableHtml .= sprintf('<th class="text-nowrap">%s</th>', __('New Template'));
@ -17,6 +18,14 @@ $numberOfUpdates = 0;
$numberOfSkippedUpdates = 0;
foreach ($templatesUpdateStatus as $uuid => $status) {
$tableHtml .= '<tr>';
if (!empty($status['new'])) {
$tableHtml .= sprintf('<td>%s</td>', __('N/A'));
} else {
$tableHtml .= sprintf('<td><a href="%s">%s</a></td>',
Router::url(['controller' => 'MetaTemplates', 'action' => 'view', 'plugin' => null, h($status['existing_template']->id)]),
h($status['existing_template']->id)
);
}
if (!empty($status['new'])) {
$tableHtml .= sprintf('<td>%s</td>', h($uuid));
} else {
@ -53,7 +62,10 @@ foreach ($templatesUpdateStatus as $uuid => $status) {
if (!empty($status['new'])) {
$tableHtml .= sprintf('<td>%s</td>', $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('<td>%s</td>', $this->Bootstrap->icon('check', ['class' => 'text-success']));
} else {