chg: [metaTemplate:updateStrategyDelete] Restored strategy to update a template and delete conflicting metafields
parent
97a151aff5
commit
adad45baf6
|
@ -22,13 +22,14 @@ class MetaTemplatesTable extends AppTable
|
|||
public const UPDATE_STRATEGY_CREATE_NEW = 'create_new';
|
||||
public const UPDATE_STRATEGY_UPDATE_EXISTING = 'update_existing';
|
||||
public const UPDATE_STRATEGY_KEEP_BOTH = 'keep_both';
|
||||
public const UPDATE_STRATEGY_DELETE = 'delete_all';
|
||||
public const UPDATE_STRATEGY_DELETE_ALL = 'delete_all';
|
||||
|
||||
public const DEFAULT_STRATEGY = MetaTemplatesTable::UPDATE_STRATEGY_UPDATE_EXISTING;
|
||||
public const ALLOWED_STRATEGIES = [
|
||||
MetaTemplatesTable::UPDATE_STRATEGY_CREATE_NEW,
|
||||
MetaTemplatesTable::UPDATE_STRATEGY_UPDATE_EXISTING,
|
||||
MetaTemplatesTable::UPDATE_STRATEGY_KEEP_BOTH,
|
||||
MetaTemplatesTable::UPDATE_STRATEGY_DELETE_ALL,
|
||||
];
|
||||
|
||||
private $templatesOnDisk = null;
|
||||
|
@ -159,7 +160,7 @@ class MetaTemplatesTable extends AppTable
|
|||
$files_processed[] = $templateOnDisk['uuid'];
|
||||
}
|
||||
if (!empty($result['errors'])) {
|
||||
$updatesErrors[] = $errors;
|
||||
$updatesErrors[] = implode(', ', Hash::extract($result['errors'], '{n}.message'));
|
||||
}
|
||||
$results = [
|
||||
'update_errors' => $updatesErrors,
|
||||
|
@ -868,6 +869,8 @@ class MetaTemplatesTable extends AppTable
|
|||
$result = $this->updateMetaTemplate($metaTemplate, $template);
|
||||
} else if ($strategy == MetaTemplatesTable::UPDATE_STRATEGY_CREATE_NEW) {
|
||||
$result = $this->executeStrategyCreateNew($template, $metaTemplate);
|
||||
} else if ($strategy == MetaTemplatesTable::UPDATE_STRATEGY_DELETE_ALL) {
|
||||
$result = $this->executeStrategyDeleteAll($template, $metaTemplate);
|
||||
} else {
|
||||
$errors[] = new UpdateError(false, __('Invalid strategy {0}', $strategy));
|
||||
return false;
|
||||
|
@ -969,7 +972,7 @@ class MetaTemplatesTable extends AppTable
|
|||
unset($entity->meta_fields[$i]);
|
||||
}
|
||||
}
|
||||
$this->MetaTemplateFields->MetaFields->unlink($entity, $metaFieldsToDelete); // FIXME
|
||||
$this->MetaTemplateFields->MetaFields->unlink($entity, $metaFieldsToDelete);
|
||||
}
|
||||
}
|
||||
$success = $this->supersedeMetaFieldsWithMetaTemplateField($entity->meta_fields, $newestMetaTemplate);
|
||||
|
@ -1013,9 +1016,7 @@ class MetaTemplatesTable extends AppTable
|
|||
|
||||
foreach ($entities as $entity) {
|
||||
$conflicts = $this->getMetaFieldsConflictsUnderTemplate($entity['meta_fields'], $template);
|
||||
$deletedCount = $this->MetaTemplateFields->MetaFields->deleteAll([
|
||||
'id IN' => $conflicts
|
||||
]);
|
||||
$this->MetaTemplateFields->MetaFields->unlink($entity, $conflicts);
|
||||
}
|
||||
$this->updateMetaTemplate($metaTemplate, $template, $errors);
|
||||
return !empty($errors) ? $errors[0] : true;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
$create_new_allowed = true;
|
||||
$update_allowed = true;
|
||||
$delete_all_allowed = false;
|
||||
$delete_all_allowed = true;
|
||||
$totalAllowed = $create_new_allowed + $update_allowed + $delete_all_allowed;
|
||||
$maxWidth = 99 - ($create_new_allowed ? 33 : 0) - ($update_allowed ? 33 : 0) - ($delete_all_allowed ? 33 : 0);
|
||||
$defaultStrategy = 'update_existing';
|
||||
|
@ -19,7 +19,7 @@ $form = $this->element('genericElements/Form/genericForm', [
|
|||
'options' => [
|
||||
['value' => 'create_new', 'text' => 'create_new', 'id' => 'radio_create_new'],
|
||||
['value' => 'update_existing', 'text' => 'update', 'id' => 'radio_update'],
|
||||
['value' => 'delete', 'text' => 'delete', 'id' => 'radio_delete'],
|
||||
['value' => 'delete_all', 'text' => 'delete_all', 'id' => 'radio_delete_all'],
|
||||
],
|
||||
]
|
||||
],
|
||||
|
@ -33,6 +33,22 @@ $form = $this->element('genericElements/Form/genericForm', [
|
|||
<div class="conflict-resolution-picker">
|
||||
<div class="mt-3 d-flex justify-content-center">
|
||||
<div class="btn-group justify-content-center" role="group" aria-label="Basic radio toggle button group">
|
||||
<?php if ($delete_all_allowed) : ?>
|
||||
<input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off" value="delete" <?= $defaultStrategy == 'delete' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-danger mw-<?= $maxWidth ?>" for="btnradio3">
|
||||
<div>
|
||||
<h5 class="mb-3">
|
||||
<?= $defaultStrategy == 'delete' ? $this->Bootstrap->badge(['text' => 'recommended', 'variant' => 'success', 'class' => ['mb-3', 'fs-8']]) : '' ?>
|
||||
<?= __('Delete conflicting fields') ?>
|
||||
</h5>
|
||||
<ul class="text-start fs-7">
|
||||
<li><?= __('Meta-fields not satisfying the new meta-template definition will be deleted.') ?></li>
|
||||
<li><?= __('All other meta-fields will be upgraded to the new meta-template.') ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($create_new_allowed) : ?>
|
||||
<input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" value="create_new" <?= $defaultStrategy == 'create_new' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-warning mw-<?= $maxWidth ?>" for="btnradio1">
|
||||
|
@ -66,22 +82,6 @@ $form = $this->element('genericElements/Form/genericForm', [
|
|||
</div>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($delete_all_allowed) : ?>
|
||||
<input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off" value="delete" <?= $defaultStrategy == 'delete' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-danger mw-<?= $maxWidth ?>" for="btnradio3">
|
||||
<div>
|
||||
<h5 class="mb-3">
|
||||
<?= $defaultStrategy == 'delete' ? $this->Bootstrap->badge(['text' => 'recommended', 'variant' => 'success', 'class' => ['mb-3', 'fs-8']]) : '' ?>
|
||||
<?= __('Delete conflicting fields') ?>
|
||||
</h5>
|
||||
<ul class="text-start fs-7">
|
||||
<li><?= __('Meta-fields not satisfying the new meta-template definition will be deleted.') ?></li>
|
||||
<li><?= __('All other meta-fields will be upgraded to the new meta-template.') ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -95,7 +95,7 @@ $form = $this->element('genericElements/Form/genericForm', [
|
|||
const $form = $('.conflict-resolution-form-container form')
|
||||
const $create = $form.find('input#radio_create_new')
|
||||
const $keep = $form.find('input#radio_update')
|
||||
const $delete = $form.find('input#radio_delete')
|
||||
const $delete = $form.find('input#radio_delete_all')
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.conflict-resolution-picker').find('input[type="radio"]').change(function() {
|
||||
|
|
Loading…
Reference in New Issue