openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d99d7e49eb5a9e8a7c253a5bfa53eb34965344a7
parent 8524eb26dc50ccb5b3553a6bc3241bd46871d7dd
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 27 Nov 2021 01:52:24 +0100

New: Releasing and Restoring for file and template values.

Diffstat:
Mmodules/cms/action/PageelementAction.class.php | 40+++++++++++++++++++++++++++++++++++++++-
Mmodules/cms/action/TemplateAction.class.php | 34++++++++++++++++++++++++++++++++++
Amodules/cms/action/file/FileReleaseAction.class.php | 44++++++++++++++++++++++++++++++++++++++++++++
Amodules/cms/action/file/FileRestoreAction.class.php | 45+++++++++++++++++++++++++++++++++++++++++++++
Mmodules/cms/action/pageelement/PageelementReleaseAction.class.php | 27+++++++++++----------------
Mmodules/cms/action/pageelement/PageelementRestoreAction.class.php | 23++++++++++++-----------
Mmodules/cms/action/pageelement/PageelementValueAction.class.php | 3+++
Amodules/cms/action/template/TemplateReleaseAction.class.php | 37+++++++++++++++++++++++++++++++++++++
Amodules/cms/action/template/TemplateRestoreAction.class.php | 44++++++++++++++++++++++++++++++++++++++++++++
Amodules/cms/action/text/TextDiffAction.class.php | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/cms/ui/themes/default/html/views/file/history.php | 25-------------------------
Mmodules/cms/ui/themes/default/html/views/file/history.tpl.src.xml | 25-------------------------
Mmodules/cms/ui/themes/default/html/views/image/history.php | 21+--------------------
Mmodules/cms/ui/themes/default/html/views/image/history.tpl.src.xml | 21+--------------------
14 files changed, 327 insertions(+), 118 deletions(-)

diff --git a/modules/cms/action/PageelementAction.class.php b/modules/cms/action/PageelementAction.class.php @@ -10,6 +10,8 @@ use cms\generator\Publisher; use cms\generator\PublishOrder; use cms\generator\ValueContext; use cms\generator\ValueGenerator; +use cms\model\Content; +use cms\model\PageContent; use cms\model\Permission; use cms\model\BaseObject; use cms\model\Element; @@ -722,4 +724,39 @@ class PageelementAction extends BaseAction throw new SecurityException(); } -} + + + protected function getContents() + { + $this->page->load(); + $this->element->load(); + + $contents = array(); + + foreach ($this->page->getProject()->getLanguages() as $languageId => $languageName) { + $pageContent = new PageContent(); + $pageContent->languageid = $languageId; + $pageContent->elementId = $this->element->elementid; + $pageContent->pageId = $this->page->pageid; + $pageContent->load(); + + $contents[] = new Content($pageContent->contentId); + } + + return $contents; + } + + + + + protected function ensureValueIdIsInAnyContent( $valueId ) + { + foreach ($this->getContents() as $content ) { + if ( in_array( $valueId,$content->getVersionList() ) ) + return; + } + + throw new SecurityException('valueId is not valid in this context'); + } + +} +\ No newline at end of file diff --git a/modules/cms/action/TemplateAction.class.php b/modules/cms/action/TemplateAction.class.php @@ -3,6 +3,7 @@ namespace cms\action; namespace cms\action; +use cms\model\Content; use cms\model\Folder; use cms\model\Permission; use cms\model\Element; @@ -10,6 +11,7 @@ use cms\model\Page; use cms\model\Project; use cms\model\Template; use cms\model\TemplateModel; +use cms\model\Value; use language\Messages; use util\exception\SecurityException; use util\exception\ValidationException; @@ -90,4 +92,36 @@ class TemplateAction extends BaseAction throw new SecurityException(); } + + protected function getTemplateModels() + { + $project = new Project($this->template->projectid); + $versions = []; + + $templatemodels = []; + foreach ($project->getModels() as $modelId => $modelName) { + $templatemodels[] = new TemplateModel($this->template->templateid, $modelId); + } + + return $templatemodels; + } + + + + protected function ensureValueIdIsInAnyTemplate( $valueId ) { + + $versions = []; + + foreach( $this->getTemplateModels() as $templateModel ) + { + $templateModel->load(); + + $content = new Content( $templateModel->getContentid() ); + + $versions = array_merge( $versions, $content->getVersionList() ); + } + + if ( ! in_array( $valueId, $versions )) + throw new SecurityException( 'value-id is not contained in the version list of this file' ); + } } \ No newline at end of file diff --git a/modules/cms/action/file/FileReleaseAction.class.php b/modules/cms/action/file/FileReleaseAction.class.php @@ -0,0 +1,44 @@ +<?php +namespace cms\action\file; +use cms\action\ContentAction; +use cms\action\FileAction; +use cms\action\Method; +use cms\action\PageelementAction; +use cms\model\Content; +use cms\model\Permission; +use cms\model\Value; +use language\Messages; +use LogicException; +use util\exception\SecurityException; + +class FileReleaseAction extends FileAction implements Method { + + public function getRequiredPermission() + { + return Permission::ACL_RELEASE; + } + + public function view() { + } + + public function post() { + + $content = new Content( $this->file->contentid ); + $versionList = $content->getVersionList(); + + $value = new Value(); + $value->valueid = $this->request->getRequiredNumber('valueid'); + + if ( ! in_array( $value->valueid, $versionList )) + throw new SecurityException( 'value-id is not contained in the version list of this file' ); + + $value->loadWithId( $value->valueid ); + + // Inhalt wieder herstellen, in dem er neu gespeichert wird. + $value->valueid = null; + $value->publish = true; + $value->persist(); + + $this->addNoticeFor( $this->file,Messages::PAGEELEMENT_RELEASED ); + } +} diff --git a/modules/cms/action/file/FileRestoreAction.class.php b/modules/cms/action/file/FileRestoreAction.class.php @@ -0,0 +1,45 @@ +<?php +namespace cms\action\file; +use cms\action\Action; +use cms\action\FileAction; +use cms\action\Method; +use cms\action\PageelementAction; +use cms\model\Content; +use cms\model\Element; +use cms\model\Permission; +use cms\model\Value; +use language\Messages; +use util\exception\SecurityException; + +class FileRestoreAction extends FileAction implements Method { + + public function getRequiredPermission() + { + return Permission::ACL_WRITE; + } + + + public function view() { + } + + public function post() { + + $content = new Content( $this->file->contentid ); + $versionList = $content->getVersionList(); + + $value = new Value(); + $value->valueid = $this->request->getRequiredNumber('valueid'); + + if ( ! in_array( $value->valueid, $versionList )) + throw new SecurityException( 'value-id is not contained in the version list of this file' ); + + $value->loadWithId( $value->valueid ); + + // Inhalt wieder herstellen, in dem er neu gespeichert wird. + $value->valueid = null; + $value->publish = false; + $value->persist(); + + $this->addNoticeFor( $this->file,Messages::PAGEELEMENT_USE_FROM_ARCHIVE ); + } +} diff --git a/modules/cms/action/pageelement/PageelementReleaseAction.class.php b/modules/cms/action/pageelement/PageelementReleaseAction.class.php @@ -3,6 +3,7 @@ namespace cms\action\pageelement; use cms\action\Method; use cms\action\PageelementAction; use cms\model\Permission; +use cms\model\Value; use language\Messages; use LogicException; use util\exception\SecurityException; @@ -18,26 +19,20 @@ class PageelementReleaseAction extends PageelementAction implements Method { public function view() { } public function post() { - $this->value->objectid = $this->page->objectid; - $this->value->pageid = $this->page->pageid; - $this->value->page = $this->page; - $this->value->element = &$this->element; - $this->value->elementid = $this->element->elementid; - $this->value->element->load(); - $this->value->valueid = $this->request->getNumber('valueid'); - $this->value->loadWithId(); + $valueId = $this->request->getRequiredNumber('valueid'); - if ( $this->value->pageid != $this->page->pageid ) - throw new LogicException( 'cannot release, bad page' ); + $this->ensureValueIdIsInAnyContent( $valueId ); - // Pruefen, ob Berechtigung zum Freigeben besteht - if ( !$this->page->hasRight(Permission::ACL_RELEASE) ) - throw new SecurityException( 'Cannot release','no right' ); + $value = new Value(); + $value->valueid = $valueId; + $value->loadWithId( $value->valueid ); - // Inhalt freigeben - $this->value->release(); + // Restore value. + $value->valueid = null; + $value->publish = true; + $value->persist(); - $this->addNoticeFor($this->value, Messages::PAGEELEMENT_RELEASED ); + $this->addNoticeFor( $this->template,Messages::PAGEELEMENT_RELEASED ); } } diff --git a/modules/cms/action/pageelement/PageelementRestoreAction.class.php b/modules/cms/action/pageelement/PageelementRestoreAction.class.php @@ -5,6 +5,7 @@ use cms\action\Method; use cms\action\PageelementAction; use cms\model\Element; use cms\model\Permission; +use cms\model\Value; use language\Messages; class PageelementRestoreAction extends PageelementAction implements Method { @@ -19,20 +20,20 @@ class PageelementRestoreAction extends PageelementAction implements Method { } public function post() { - $this->value->valueid = $this->request->getText('valueid'); - $this->value->loadWithId(); - $this->value->element = new Element( $this->value->elementid ); + $valueId = $this->request->getRequiredNumber('valueid'); - if ( $this->value->pageid != $this->page->pageid ) - throw new \LogicException( 'Cannot find value','page-id does not match' ); + $this->ensureValueIdIsInAnyContent( $valueId ); - // Pruefen, ob Berechtigung zum Freigeben besteht - //$this->value->release = $this->page->hasRight(Acl::ACL_RELEASE); - $this->value->release = false; + $value = new Value(); + $value->valueid = $valueId; + $value->loadWithId( $value->valueid ); - // Inhalt wieder herstellen, in dem er neu gespeichert wird. - $this->value->add(); + // Restore value. + $value->valueid = null; + $value->publish = false; + $value->persist(); + + $this->addNoticeFor( $this->template,Messages::PAGEELEMENT_USE_FROM_ARCHIVE ); - $this->addNoticeFor( $this->pageelement,Messages::PAGEELEMENT_USE_FROM_ARCHIVE ); } } diff --git a/modules/cms/action/pageelement/PageelementValueAction.class.php b/modules/cms/action/pageelement/PageelementValueAction.class.php @@ -32,7 +32,10 @@ class PageelementValueAction extends PageelementAction implements Method { $valueId =$this->request->getNumber('valueid'); + if ( $valueId ) { + $this->ensureValueIdIsInAnyContent( $valueId ); + $this->value->valueid = $valueId; $this->value->loadWithId(); } diff --git a/modules/cms/action/template/TemplateReleaseAction.class.php b/modules/cms/action/template/TemplateReleaseAction.class.php @@ -0,0 +1,37 @@ +<?php +namespace cms\action\template; +use cms\action\ContentAction; +use cms\action\Method; +use cms\action\PageelementAction; +use cms\action\TemplateAction; +use cms\model\Permission; +use cms\model\Value; +use language\Messages; +use LogicException; +use util\exception\SecurityException; + +class TemplateReleaseAction extends TemplateAction implements Method { + + + public function view() { + } + + + public function post() { + + $valueId = $this->request->getRequiredNumber('valueid'); + + $this->ensureValueIdIsInAnyTemplate( $valueId ); + + $value = new Value(); + $value->valueid = $valueId; + $value->loadWithId( $value->valueid ); + + // Publish value. + $value->valueid = null; + $value->publish = true; + $value->persist(); + + $this->addNoticeFor($this->template, Messages::PAGEELEMENT_RELEASED ); + } +} diff --git a/modules/cms/action/template/TemplateRestoreAction.class.php b/modules/cms/action/template/TemplateRestoreAction.class.php @@ -0,0 +1,44 @@ +<?php +namespace cms\action\template; +use cms\action\Action; +use cms\action\Method; +use cms\action\PageelementAction; +use cms\action\TemplateAction; +use cms\model\Content; +use cms\model\Element; +use cms\model\Permission; +use cms\model\Project; +use cms\model\TemplateModel; +use cms\model\Value; +use language\Messages; +use util\exception\SecurityException; + +class TemplateRestoreAction extends TemplateAction implements Method { + + public function getRequiredPermission() + { + return Permission::ACL_WRITE; + } + + + public function view() { + } + + public function post() { + + $valueId = $this->request->getRequiredNumber('valueid'); + + $this->ensureValueIdIsInAnyTemplate( $valueId ); + + $value = new Value(); + $value->valueid = $valueId; + $value->loadWithId( $value->valueid ); + + // Restore value. + $value->valueid = null; + $value->publish = false; + $value->persist(); + + $this->addNoticeFor( $this->template,Messages::PAGEELEMENT_USE_FROM_ARCHIVE ); + } +} diff --git a/modules/cms/action/text/TextDiffAction.class.php b/modules/cms/action/text/TextDiffAction.class.php @@ -0,0 +1,56 @@ +<?php +namespace cms\action\text; +use cms\action\Method; +use cms\action\PageelementAction; +use cms\generator\PublishEdit; +use cms\generator\PublishPreview; +use cms\model\Value; +use util\exception\ValidationException; +use util\Text; + +class TextDiffAction extends PageelementAction implements Method { + + public function view() { + $value1id = $this->request->getNumber('compareid'); + $value2id = $this->request->getNumber('withid' ); + + // Wenn Value1-Id = Value2-Id + if ( $value1id == $value2id ) + throw new ValidationException('withid' ); + + // Wenn Value1-Id groesser als Value2-Id, dann Variablen tauschen + if ( $value1id > $value2id ) + list($value1id,$value2id) = array( $value2id,$value1id ); + + + $value1 = new Value( $value1id ); + $value2 = new Value( $value2id ); + $value1->valueid = $value1id; + $value2->valueid = $value2id; + + $value1->loadWithId(); + $value2->loadWithId(); + + $this->setTemplateVar('date_left' ,$value1->lastchangeTimeStamp); + $this->setTemplateVar('date_right',$value2->lastchangeTimeStamp); + + $text1 = explode("\n",$value1->text); + $text2 = explode("\n",$value2->text); + + // Unterschiede feststellen. + $diffResult = Text::diff($text1,$text2); + + $outputResult = array_map( function( $left,$right) { + return [ + 'left' => $left, + 'right'=> $right + ]; + },$diffResult[0],$diffResult[1] ); + + $this->setTemplateVar('diff',$outputResult ); + } + + + public function post() { + } +} diff --git a/modules/cms/ui/themes/default/html/views/file/history.php b/modules/cms/ui/themes/default/html/views/file/history.php @@ -20,12 +20,6 @@ <div class="<?php echo O::escapeHtml('or-table-area') ?>"><?php echo O::escapeHtml('') ?> <table class="<?php echo O::escapeHtml('or-table') ?>"><?php echo O::escapeHtml('') ?> <tr class="<?php echo O::escapeHtml('or-table-header') ?>"><?php echo O::escapeHtml('') ?> - <td colspan="<?php echo O::escapeHtml('2') ?>" class="<?php echo O::escapeHtml('or-table-column-action') ?>"><?php echo O::escapeHtml('') ?> - <span><?php echo O::escapeHtml(''.@O::lang('COMPARE').'') ?></span> - </td> - <td class="<?php echo O::escapeHtml('or-table-column-auto') ?>"><?php echo O::escapeHtml('') ?> - <span><?php echo O::escapeHtml(''.@O::lang('VALUE').'') ?></span> - </td> <td class="<?php echo O::escapeHtml('or--visible-on-desktop or-table-column-date') ?>"><?php echo O::escapeHtml('') ?> <span><?php echo O::escapeHtml(''.@O::lang('DATE').'') ?></span> </td> @@ -48,25 +42,6 @@ <?php } ?> <?php foreach((array)@$values as $list_key=>$list_value) { extract($list_value); ?> <tr class="<?php echo O::escapeHtml('or-data') ?>"><?php echo O::escapeHtml('') ?> - <td class="<?php echo O::escapeHtml('or-table-column-action') ?>"><?php echo O::escapeHtml('') ?> - <?php $if8=($comparable); if($if8) { ?> - <input type="<?php echo O::escapeHtml('radio') ?>" name="<?php echo O::escapeHtml('compareid') ?>" value="<?php echo O::escapeHtml(''.@$id.'') ?>" <?php if(@$compareid=='${id}'){ ?>checked="<?php echo O::escapeHtml('checked') ?>"<?php } ?> class="<?php echo O::escapeHtml('or-form-radio') ?>" /><?php echo O::escapeHtml('') ?> - <?php } ?> - <?php if(!$if8) { ?> - <span><?php echo O::escapeHtml(' ') ?></span> - <?php } ?> - </td> - <td><?php echo O::escapeHtml('') ?> - <?php $if8=($comparable); if($if8) { ?> - <input type="<?php echo O::escapeHtml('radio') ?>" name="<?php echo O::escapeHtml('withid') ?>" value="<?php echo O::escapeHtml(''.@$id.'') ?>" <?php if(@$withid=='${id}'){ ?>checked="<?php echo O::escapeHtml('checked') ?>"<?php } ?> class="<?php echo O::escapeHtml('or-form-radio') ?>" /><?php echo O::escapeHtml('') ?> - <?php } ?> - <?php if(!$if8) { ?> - <span><?php echo O::escapeHtml(' ') ?></span> - <?php } ?> - </td> - <td><?php echo O::escapeHtml('') ?> - <span title="<?php echo O::escapeHtml(''.@$text.'') ?>"><?php echo O::escapeHtml(''.@$text.'') ?></span> - </td> <td class="<?php echo O::escapeHtml('or--visible-on-desktop') ?>"><?php echo O::escapeHtml('') ?> <?php include_once( 'modules/template_engine/components/html/component_date/component-date.php'); { component_date($date); ?> <?php } ?> diff --git a/modules/cms/ui/themes/default/html/views/file/history.tpl.src.xml b/modules/cms/ui/themes/default/html/views/file/history.tpl.src.xml @@ -6,12 +6,6 @@ <table> <row header="true"> - <column class="table-column-action" colspan="2"> - <text value="${message:COMPARE}"/> - </column> - <column class="table-column-auto"> - <text value="${message:VALUE}"/> - </column> <column class="-visible-on-desktop,table-column-date"> <text class="" value="${message:DATE}"/> </column> @@ -35,25 +29,6 @@ </if> <list list="${values}" extract="true"> <row class="data"> - <column class="table-column-action"> - <if true="${comparable}"> - <radio name="compareid" value="${id}"/> - </if> - <else> - <text value=" "/> - </else> - </column> - <column> - <if true="${comparable}"> - <radio name="withid" value="${id}"/> - </if> - <else> - <text value=" "/> - </else> - </column> - <column> - <text value="${text}" title="${text}"/> - </column> <column class="-visible-on-desktop"> <date date="${date}"/> </column> diff --git a/modules/cms/ui/themes/default/html/views/image/history.php b/modules/cms/ui/themes/default/html/views/image/history.php @@ -20,9 +20,6 @@ <div class="<?php echo O::escapeHtml('or-table-area') ?>"><?php echo O::escapeHtml('') ?> <table class="<?php echo O::escapeHtml('or-table') ?>"><?php echo O::escapeHtml('') ?> <tr class="<?php echo O::escapeHtml('or-table-header') ?>"><?php echo O::escapeHtml('') ?> - <td colspan="<?php echo O::escapeHtml('2') ?>" class="<?php echo O::escapeHtml('or-table-column-action') ?>"><?php echo O::escapeHtml('') ?> - <span><?php echo O::escapeHtml(''.@O::lang('COMPARE').'') ?></span> - </td> <td class="<?php echo O::escapeHtml('or-table-column-auto') ?>"><?php echo O::escapeHtml('') ?> <span><?php echo O::escapeHtml(''.@O::lang('VALUE').'') ?></span> </td> @@ -48,24 +45,8 @@ <?php } ?> <?php foreach((array)@$values as $list_key=>$list_value) { extract($list_value); ?> <tr class="<?php echo O::escapeHtml('or-data') ?>"><?php echo O::escapeHtml('') ?> - <td class="<?php echo O::escapeHtml('or-table-column-action') ?>"><?php echo O::escapeHtml('') ?> - <?php $if8=($comparable); if($if8) { ?> - <input type="<?php echo O::escapeHtml('radio') ?>" name="<?php echo O::escapeHtml('compareid') ?>" value="<?php echo O::escapeHtml(''.@$id.'') ?>" <?php if(@$compareid=='${id}'){ ?>checked="<?php echo O::escapeHtml('checked') ?>"<?php } ?> class="<?php echo O::escapeHtml('or-form-radio') ?>" /><?php echo O::escapeHtml('') ?> - <?php } ?> - <?php if(!$if8) { ?> - <span><?php echo O::escapeHtml(' ') ?></span> - <?php } ?> - </td> - <td><?php echo O::escapeHtml('') ?> - <?php $if8=($comparable); if($if8) { ?> - <input type="<?php echo O::escapeHtml('radio') ?>" name="<?php echo O::escapeHtml('withid') ?>" value="<?php echo O::escapeHtml(''.@$id.'') ?>" <?php if(@$withid=='${id}'){ ?>checked="<?php echo O::escapeHtml('checked') ?>"<?php } ?> class="<?php echo O::escapeHtml('or-form-radio') ?>" /><?php echo O::escapeHtml('') ?> - <?php } ?> - <?php if(!$if8) { ?> - <span><?php echo O::escapeHtml(' ') ?></span> - <?php } ?> - </td> <td><?php echo O::escapeHtml('') ?> - <span title="<?php echo O::escapeHtml(''.@$text.'') ?>"><?php echo O::escapeHtml(''.@$text.'') ?></span> + <i class="<?php echo O::escapeHtml('or-image-icon or-image-icon--action-image') ?>"><?php echo O::escapeHtml('') ?></i> </td> <td class="<?php echo O::escapeHtml('or--visible-on-desktop') ?>"><?php echo O::escapeHtml('') ?> <?php include_once( 'modules/template_engine/components/html/component_date/component-date.php'); { component_date($date); ?> diff --git a/modules/cms/ui/themes/default/html/views/image/history.tpl.src.xml b/modules/cms/ui/themes/default/html/views/image/history.tpl.src.xml @@ -7,9 +7,6 @@ <table> <row header="true"> - <column class="table-column-action" colspan="2"> - <text value="${message:COMPARE}"/> - </column> <column class="table-column-auto"> <text value="${message:VALUE}"/> </column> @@ -36,24 +33,8 @@ </if> <list list="${values}" extract="true"> <row class="data"> - <column class="table-column-action"> - <if true="${comparable}"> - <radio name="compareid" value="${id}"/> - </if> - <else> - <text value=" "/> - </else> - </column> - <column> - <if true="${comparable}"> - <radio name="withid" value="${id}"/> - </if> - <else> - <text value=" "/> - </else> - </column> <column> - <text value="${text}" title="${text}"/> + <image action="image" /> </column> <column class="-visible-on-desktop"> <date date="${date}"/>