';
$tableHtml .= sprintf('%s | ', __('ID'));
$tableHtml .= sprintf('%s | ', __('Template'));
$tableHtml .= sprintf('%s | ', __('Version'));
$tableHtml .= sprintf('%s | ', __('New Template'));
$tableHtml .= sprintf('%s | ', __('Update available'));
$tableHtml .= sprintf('%s | ', __('Has Conflicts'));
$tableHtml .= sprintf('%s | ', __('Will be updated'));
$tableHtml .= '
';
$numberOfUpdates = 0;
$numberOfSkippedUpdates = 0;
foreach ($templatesUpdateStatus as $uuid => $status) {
$tableHtml .= '';
if (!empty($status['new'])) {
$tableHtml .= sprintf('%s | ', __('N/A'));
} else {
$tableHtml .= sprintf(
'%s | ',
Router::url(['controller' => 'MetaTemplates', 'action' => 'view', 'plugin' => null, h($status['existing_template']->id)]),
h($status['existing_template']->id)
);
}
if (!empty($status['new'])) {
$tableHtml .= sprintf('%s | ', h($uuid));
} else {
$tableHtml .= sprintf(
'%s | ',
Router::url(['controller' => 'MetaTemplates', 'action' => 'view', 'plugin' => null, h($status['existing_template']->id)]),
h($status['existing_template']->name)
);
}
if (!empty($status['new'])) {
$tableHtml .= sprintf('%s | ', __('N/A'));
} else {
if ($status['current_version'] == $status['next_version']) {
$tableHtml .= sprintf(
'%s | ',
h($status['current_version'])
);
} else {
$tableHtml .= sprintf(
'%s %s %s | ',
h($status['current_version']),
$this->Bootstrap->icon('arrow-right', ['class' => 'fs-8']),
h($status['next_version'])
);
}
}
if (!empty($status['new'])) {
$numberOfUpdates += 1;
$tableHtml .= sprintf('%s | ', $this->Bootstrap->icon('check'));
} else {
$tableHtml .= sprintf('%s | ', $this->Bootstrap->icon('times'));
}
if (!empty($status['new'])) {
$tableHtml .= sprintf('%s | ', __('N/A'));
} else {
$tableHtml .= sprintf('%s | ', empty($status['up-to-date']) ? $this->Bootstrap->icon('check') : $this->Bootstrap->icon('times'));
}
if (!empty($status['new'])) {
$tableHtml .= sprintf('%s | ', __('N/A'));
} elseif (!empty($status['up-to-date'])) {
$tableHtml .= sprintf('%s | ', __('N/A'));
} else {
$tableHtml .= sprintf('%s | ', !empty($status['conflicts']) ? $this->Bootstrap->icon('check') : $this->Bootstrap->icon('times'));
}
if (!empty($status['new'])) {
$tableHtml .= sprintf('%s | ', $this->Bootstrap->icon('check', ['class' => 'text-success']));
} else {
// 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['up-to-date'])) {
$numberOfUpdates += 1;
$tableHtml .= sprintf('%s | ', $this->Bootstrap->icon('check', ['class' => 'text-success']));
} else {
$numberOfSkippedUpdates += 1;
$tableHtml .= sprintf('%s | ', $this->Bootstrap->icon('times', ['class' => 'text-danger']));
}
}
$tableHtml .= '
';
}
$tableHtml .= '';
if (empty($numberOfSkippedUpdates) && empty($numberOfUpdates)) {
$bodyHtml .= $this->Bootstrap->alert([
'variant' => 'success',
'text' => __('All meta-templates are already up-to-date!'),
'dismissible' => false,
]);
$modalType = 'ok-only';
} elseif ($numberOfSkippedUpdates == 0) {
$bodyHtml .= $this->Bootstrap->alert([
'variant' => 'success',
'text' => __('All {0} meta-templates can be updated', $numberOfUpdates),
'dismissible' => false,
]);
} else {
$modalSize = 'xl';
$alertHtml = '';
if (!empty($numberOfUpdates)) {
$alertHtml .= sprintf('%s
', __('{0} meta-templates can be updated.', sprintf('%s', $numberOfUpdates)));
}
if (!empty($numberOfSkippedUpdates)) {
$alertHtml .= sprintf('%s
', __('{0} meta-templates will be skipped.', sprintf('%s', $numberOfSkippedUpdates)));
$alertHtml .= sprintf('%s
', __('You can still choose the update strategy when updating each conflicting template manually.'));
}
$bodyHtml .= $this->Bootstrap->alert([
'variant' => 'warning',
'html' => $alertHtml,
'dismissible' => false,
]);
}
$bodyHtml .= $tableHtml;
$form = sprintf(
'%s%s
',
$this->Form->create(null),
$this->Form->end()
);
$bodyHtml .= $form;
echo $this->Bootstrap->modal([
'title' => h($title),
'bodyHtml' => $bodyHtml,
'size' => $modalSize,
'type' => $modalType,
'confirmText' => __('Update meta-templates'),
'confirmFunction' => 'updateMetaTemplate',
]);
?>