2021-12-01 11:01:31 +01:00
< ? php
2022-03-09 08:21:27 +01:00
use App\Model\Table\MetaTemplatesTable ;
2021-12-01 11:01:31 +01:00
$bodyHtml = '' ;
$modalType = 'confirm' ;
$modalSize = 'lg' ;
2021-12-14 15:09:40 +01:00
if ( $updateStatus [ 'up-to-date' ]) {
2021-12-01 11:01:31 +01:00
$bodyHtml .= $this -> Bootstrap -> alert ([
'variant' => 'success' ,
'text' => __ ( 'This meta-template is already up-to-date!' ),
'dismissible' => false ,
]);
$modalType = 'ok-only' ;
2023-03-13 11:37:58 +01:00
} else if ( empty ( $updateStatus [ 'templateOnDisk' ])) {
$diskTemplateError = $templateStatus [ 'error' ] ? ? __ ( 'Unknown' );
$bodyHtml .= $this -> Bootstrap -> alert ([
'variant' => 'danger' ,
'html' => sprintf ( '<strong>%s</strong> %s<p>%s</p>' , __ ( 'Could not get template on disk.' ), __ ( 'Reason:' ), h ( $diskTemplateError )),
'dismissible' => false ,
]);
$modalType = 'ok-only' ;
2021-12-01 11:01:31 +01:00
} else {
2021-12-14 15:09:40 +01:00
if ( $updateStatus [ 'automatically-updateable' ]) {
2021-12-01 11:01:31 +01:00
$bodyHtml .= $this -> Bootstrap -> alert ([
'variant' => 'success' ,
'html' => __ ( 'This meta-template can be updated to version {0} (current: {1}).' , sprintf ( '<strong>%s</strong>' , h ( $templateOnDisk [ 'version' ])), h ( $metaTemplate -> version )),
'dismissible' => false ,
]);
2023-02-14 14:42:35 +01:00
$bodyHtml .= $this -> Bootstrap -> alert ([
'variant' => 'success' ,
'text' => __ ( 'All meta-fields will be migrated to the newest version.' ),
'dismissible' => false ,
]);
2021-12-08 11:11:46 +01:00
$form = $this -> element ( 'genericElements/Form/genericForm' , [
'entity' => null ,
'ajax' => false ,
'raw' => true ,
'data' => [
'model' => 'MetaTemplate' ,
'fields' => [
[
'field' => 'update_strategy' ,
'type' => 'checkbox' ,
2023-02-14 14:42:35 +01:00
'value' => MetaTemplatesTable :: UPDATE_STRATEGY_UPDATE_EXISTING ,
2021-12-08 11:11:46 +01:00
'checked' => true ,
2023-02-14 14:42:35 +01:00
],
2021-12-08 11:11:46 +01:00
],
'submit' => [
'action' => $this -> request -> getParam ( 'action' )
],
]
]);
$bodyHtml .= sprintf ( '<div class="d-none">%s</div>' , $form );
2021-12-01 11:01:31 +01:00
} else {
$modalSize = 'xl' ;
$bodyHtml .= $this -> Bootstrap -> alert ([
'variant' => 'warning' ,
2023-02-14 14:42:35 +01:00
'html' => __ ( 'Updating to version {0} cannot be done automatically as it introduces some conflicts.' , sprintf ( '<strong>%s</strong>' , h ( $templateOnDisk [ 'version' ]))),
2021-12-01 11:01:31 +01:00
'dismissible' => false ,
]);
$conflictTable = $this -> element ( 'MetaTemplates/conflictTable' , [
2021-12-14 15:09:40 +01:00
'templateStatus' => $templateStatus ,
2021-12-01 11:01:31 +01:00
'metaTemplate' => $metaTemplate ,
'templateOnDisk' => $templateOnDisk ,
]);
2023-02-14 14:42:35 +01:00
$conflictCount = array_reduce ( $templateStatus [ 'conflicts' ], function ( $carry , $conflict ) {
return $carry + count ( $conflict [ 'conflictingEntities' ]);
}, 0 );
2021-12-01 11:01:31 +01:00
$bodyHtml .= $this -> Bootstrap -> collapse ([
2023-02-14 14:42:35 +01:00
'text' => __ ( 'View conflicts ({0})' , $conflictCount ),
2021-12-01 11:01:31 +01:00
'open' => false
], $conflictTable );
$bodyHtml .= $this -> element ( 'MetaTemplates/conflictResolution' , [
2021-12-14 15:09:40 +01:00
'templateStatus' => $templateStatus ,
2021-12-01 11:01:31 +01:00
'metaTemplate' => $metaTemplate ,
'templateOnDisk' => $templateOnDisk ,
]);
}
}
echo $this -> Bootstrap -> modal ([
'title' => __ ( 'Update Meta Templates #{0} ?' , h ( $metaTemplate -> id )),
'bodyHtml' => $bodyHtml ,
'size' => $modalSize ,
'type' => $modalType ,
'confirmText' => __ ( 'Update meta-templates' ),
]);
?>