commit 969d8be907d2c5bf239a1404871aa0a54f94e8dd
parent 3956430f4570fd3eaed49e80b12f70ba51877a8b
Author: Jan Dankert <develop@jandankert.de>
Date: Tue, 9 Nov 2021 23:52:56 +0100
Some fixes for reading content from the new content table.
Diffstat:
10 files changed, 117 insertions(+), 43 deletions(-)
diff --git a/modules/cms/action/PageelementAction.class.php b/modules/cms/action/PageelementAction.class.php
@@ -361,7 +361,7 @@ class PageelementAction extends BaseAction
// Inhalt sofort freigegeben, wenn
// - Recht vorhanden
// - Freigabe gewuenscht
- $value->publish = $value->page->hasRight( Permission::ACL_RELEASE ) && $this->request->has('release') );
+ $value->publish = $value->page->hasRight( Permission::ACL_RELEASE ) && $this->request->has('release');
// Up-To-Date-Check
$lastChangeTime = $value->getLastChangeSinceByAnotherUser( $this->request->getText('value_time'), Session::getUser()->userid );
diff --git a/modules/cms/action/template/TemplateSrcAction.class.php b/modules/cms/action/template/TemplateSrcAction.class.php
@@ -48,8 +48,8 @@ class TemplateSrcAction extends TemplateAction implements Method {
$text );
}
- $this->setTemplateVar( 'modelid',$modelId );
- $this->setTemplateVar( 'source' ,$text );
+ $this->setTemplateVar( 'modelid',$modelId );
+ $this->setTemplateVar( 'source' ,$text );
$this->setTemplateVar( 'extension',$templatemodel->extension );
}
diff --git a/modules/cms/generator/FileGenerator.class.php b/modules/cms/generator/FileGenerator.class.php
@@ -6,6 +6,7 @@ namespace cms\generator;
use cms\generator\filter\AbstractFilter;
use cms\model\File;
+use cms\model\Value;
use logger\Logger;
use util\exception\GeneratorException;
@@ -45,14 +46,26 @@ class FileGenerator extends BaseGenerator
*/
private function filterValue( $file )
{
- $totalSettings = $file->getTotalSettings();
+ $contentId = $file->contentid;
+ $totalSettings = $file->getTotalSettings();
$proxyFileId = @$totalSettings['proxy-file-id'];
- if ( $proxyFileId )
- $value = (new File( $proxyFileId ))->loadValue(); // This is a proxy for another file.
+ if ( $proxyFileId ) {
+ $proxyFile = new File( $proxyFileId ); // This is a proxy for another file.
+ $proxyFile->load();
+ $contentId = $proxyFile->contentid;
+ }
+
+ $v = new Value();
+ $v->contentid = $contentId;
+
+ if ( $this->context->scheme == Producer::SCHEME_PREVIEW )
+ $v->load();
else
- $value = $file->loadValue();
+ $v->loadPublished();
+
+ $value = $v->file;
foreach(\util\ArrayUtils::getSubArray($totalSettings, array( 'filter')) as $filterEntry )
{
diff --git a/modules/cms/generator/PageGenerator.class.php b/modules/cms/generator/PageGenerator.class.php
@@ -95,7 +95,11 @@ class PageGenerator extends BaseGenerator
},$page->getElements() );
$templatemodel = new TemplateModel( $template->templateid, $this->context->modelId );
- $templatemodel->load();
+ if ( $this->context->scheme == Producer::SCHEME_PREVIEW )
+ $templatemodel->load();
+ else
+ $templatemodel->loadForPublic();
+
$src = $templatemodel->src;
$data = array();
diff --git a/modules/cms/generator/ValueGenerator.class.php b/modules/cms/generator/ValueGenerator.class.php
@@ -17,6 +17,7 @@ use cms\model\Image;
use cms\model\Language;
use cms\model\Link;
use cms\model\Page;
+use cms\model\PageContent;
use cms\model\Project;
use cms\model\Template;
use cms\model\Value;
@@ -72,14 +73,22 @@ class ValueGenerator extends BaseGenerator
$element = new Element( $this->context->elementid );
$element->load();
+ $pageContent = new PageContent();
+
+ $pageContent->pageId = $page->pageid;
+ $pageContent->elementId = $this->context->elementid;
+ $pageContent->languageid = $pageContext->languageId;
+ $pageContent->load();
+
$value = new Value();
- $value->pageid = $page->pageid;
- $value->elementid = $this->context->elementid;
- $value->languageid = $pageContext->languageId;
- $value->load();
- $value->element = $element;
+ $value->contentid = $pageContent->contentId;
+
+ if ( $this->context->scheme == Producer::SCHEME_PREVIEW )
+ $value->load();
+ else
+ $value->loadPublished();
- if ( ! $this->isValueHasContent( $value ) )
+ if ( ! $this->isValueHasContent( $value,$element ) )
{
$pageForDefaultValue = $page->getPageAsDefault();
@@ -1030,24 +1039,24 @@ class ValueGenerator extends BaseGenerator
*
* @param $value Value
*/
- protected function isValueHasContent( $value ) {
+ protected function isValueHasContent( $value,$element ) {
- return in_array($value->element->typeid,[
+ return in_array($element->typeid,[
Element::ELEMENT_TYPE_TEXT,
Element::ELEMENT_TYPE_LONGTEXT,
Element::ELEMENT_TYPE_SELECT,
]) && $value->text != '' && $value->text != null ||
- in_array($value->element->typeid,[
+ in_array($element->typeid,[
Element::ELEMENT_TYPE_NUMBER
]) && $value->number != null ||
- in_array($value->element->typeid,[
+ in_array($element->typeid,[
Element::ELEMENT_TYPE_LINK,
Element::ELEMENT_TYPE_INSERT,
]) && $value->linkToObjectId != null && $value->linkToObjectId != 0 ||
- in_array($value->element->typeid,[
+ in_array($element->typeid,[
Element::ELEMENT_TYPE_DATE,
]) && $value->date != null && $value->date != 0 ||
- in_array($value->element->typeid,[
+ in_array($element->typeid,[
Element::ELEMENT_TYPE_CODE,
Element::ELEMENT_TYPE_COPY,
Element::ELEMENT_TYPE_DYNAMIC,
diff --git a/modules/cms/model/File.class.php b/modules/cms/model/File.class.php
@@ -448,11 +448,15 @@ class File extends BaseObject
*/
function delete()
{
- $db = \cms\base\DB::get();
+ $content = new Content( $this->contentid );
+ $content->delete();
- // Datei l?schen
- $sql = $db->sql( 'DELETE FROM {{file}} '.
- ' WHERE objectid={objectid}' );
+ // Delete file
+ $sql = DB::sql( <<<SQL
+ DELETE FROM {{file}}
+ WHERE objectid={objectid}
+SQL
+ );
$sql->setInt( 'objectid',$this->objectid );
$sql->execute();
diff --git a/modules/cms/model/Page.class.php b/modules/cms/model/Page.class.php
@@ -176,17 +176,15 @@ SQL
}
- function delete()
+ public function delete()
{
- $db = \cms\base\DB::get();
-
- $sql = $db->sql( 'DELETE FROM {{value}} '.
- ' WHERE pageid={pageid}' );
- $sql->setInt('pageid',$this->pageid);
- $sql->execute();
-
- $sql = $db->sql( 'DELETE FROM {{page}} '.
- ' WHERE objectid={objectid}' );
+ $this->deleteContent();
+ // Delete the page
+ $sql = DB::sql( <<<SQL
+ DELETE FROM {{page}}
+ WHERE objectid={objectid}
+SQL
+ );
$sql->setInt('objectid',$this->objectid);
$sql->execute();
@@ -227,8 +225,6 @@ SQL
}
-
-
function save()
{
$db = \cms\base\DB::get();
@@ -404,4 +400,26 @@ SQL
{
return 'Id '.$this->pageid.' (filename='.$this->filename.', templateid='.$this->templateid.')';
}
+
+
+ /**
+ * Deletes all content of the page
+ */
+ private function deleteContent()
+ {
+ // Delete all page contents.
+ $project = $this->getProject();
+ $languageIds = $project->getLanguageIds();
+ $elementIds = $this->getElementIds();
+
+ foreach( $languageIds as $languageId )
+ foreach ( $elementIds as $elementId ) {
+ $pageContent = new PageContent();
+ $pageContent->pageId = $this->pageid;
+ $pageContent->elementId = $elementId;
+ $pageContent->languageid = $languageId;
+ $pageContent->load();
+ $pageContent->delete();
+ }
+ }
}
diff --git a/modules/cms/model/PageContent.class.php b/modules/cms/model/PageContent.class.php
@@ -136,9 +136,13 @@ SQL
*/
function delete()
{
+
+ $content = new Content( $this->contentId );
+ $content->delete();
+
$stmt = DB::sql( <<<SQL
- DELETE * FROM {{pagecontent}}
- WHERE id ={id}
+ DELETE * FROM {{pagecontent}}
+ WHERE id ={id}
SQL
);
$stmt->setInt( 'id' ,$this->id );
diff --git a/modules/cms/model/TemplateModel.class.php b/modules/cms/model/TemplateModel.class.php
@@ -85,6 +85,16 @@ SQL
+ public function loadForPublic() {
+ $this->load();
+
+ $value = new Value();
+ $value->contentid = $this->contentid;
+ $value->loadPublished();
+ $this->src = $value->text;
+ }
+
+
public function isPersistent()
{
return intval( $this->templatemodelid ) > 0;
@@ -155,9 +165,15 @@ SQL
public function delete()
{
$db = \cms\base\DB::get();
-
- $stmt = $db->sql( 'DELETE FROM {{templatemodel}}'.
- ' WHERE id={id}' );
+
+ $content = new Content( $this->contentid );
+ $content->delete();
+
+ $stmt = $db->sql(<<<SQL
+ DELETE FROM {{templatemodel}}
+ WHERE id={id}
+SQL
+ );
$stmt->setInt( 'id',$this->templatemodelid );
$stmt->execute();
}
diff --git a/modules/cms/model/Value.class.php b/modules/cms/model/Value.class.php
@@ -168,7 +168,7 @@ class Value extends ModelBase
{
$stmt = Db::sql( <<<SQL
SELECT * FROM {{value}}
- WHERE contentid = {{contentid}}
+ WHERE contentid = {contentid}
AND publish = 1
SQL
);
@@ -180,15 +180,21 @@ SQL
private function bindRow( $row ) {
- if ( count($row) > 0 ) // Wenn Inhalt gefunden
+ if ( $row ) // Wenn Inhalt gefunden
{
$this->text = $row['text' ];
+ $this->file = $row['file' ];
$this->format = $row['format'];
$this->valueid = intval($row['id'] );
$this->linkToObjectId = intval($row['linkobjectid']);
$this->number = intval($row['number' ]);
$this->date = intval($row['date' ]);
+ $storeValueAsBase64 = DB::get()->conf['base64'];
+
+ if ( $storeValueAsBase64 )
+ $this->file = base64_decode( $this->file );
+
$this->active = ( $row['active' ]=='1' );
$this->publish = ( $row['publish']=='1' );