commit ae2e6ee7ca6affd6440dfa26e49af73860d84cf2
parent ef13049206581d5d5a1d237b7b95c542d2e73be4
Author: Jan Dankert <develop@jandankert.de>
Date: Mon, 8 Nov 2021 01:05:19 +0100
Refactoring: Reading values from the new content table.
Diffstat:
3 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/modules/cms/model/File.class.php b/modules/cms/model/File.class.php
@@ -547,16 +547,23 @@ EOF
*/
private function loadValueFromDatabase()
{
- $sql = Db::sql( 'SELECT size,value'.
- ' FROM {{file}}'.
- ' WHERE objectid={objectid}' );
+ $sql = Db::sql( <<<SQL
+ SELECT {{file}}.size,{{value}}.file
+ FROM {{file}}
+ LEFT JOIN {{content}}
+ ON {{file}}.contentid = {{content}}.id
+ LEFT JOIN {{value}}
+ ON {{value}}.contentid = {{content}}.id AND {{value}}.active = 1
+ WHERE objectid={objectid}
+SQL
+ );
$sql->setInt( 'objectid', $this->objectid);
$row = $sql->getRow();
if ( count($row) != 0 )
{
- $this->value = $row['value'];
- $this->size = $row['size' ];
+ $this->value = $row['file'];
+ $this->size = $row['size'];
}
if ( $this->storeValueAsBase64 )
diff --git a/modules/cms/model/TemplateModel.class.php b/modules/cms/model/TemplateModel.class.php
@@ -53,18 +53,23 @@ class TemplateModel extends ModelBase
{
$db = \cms\base\DB::get();
- $stmt = $db->sql( 'SELECT * FROM {{templatemodel}}'.
- ' WHERE templateid={templateid}'.
- ' AND projectmodelid={modelid}' );
+ $stmt = $db->sql( <<<SQL
+ SELECT {{templatemodel}}.*,{{value}}.text FROM {{templatemodel}}
+ LEFT JOIN {{value}}
+ ON {{value}}.contentid = {{templatemodel}}.contentid AND {{value}}.active = 1
+ WHERE templateid = {templateid}
+ AND projectmodelid = {modelid}
+SQL
+);
$stmt->setInt( 'templateid',$this->templateid );
$stmt->setInt( 'modelid' ,$this->modelid );
$row = $stmt->getRow();
if ( isset($row['id']) )
{
- $this->templatemodelid = $row['id'];
+ $this->templatemodelid = $row['id' ];
$this->extension = $row['extension'];
- $this->src = $row['text'];
+ $this->src = $row['text' ];
}
else
{
diff --git a/modules/cms/model/Value.class.php b/modules/cms/model/Value.class.php
@@ -178,11 +178,15 @@ class Value extends ModelBase
function loadForPublic()
{
$stmt = Db::sql( <<<SQL
- SELECT * FROM {{value}}
- WHERE elementid ={elementid}
- AND pageid ={pageid}
- AND languageid={languageid}
- AND publish =1
+ SELECT {{value}}.* FROM {{pagecontent}}
+ LEFT JOIN {{content}}
+ ON {{pagecontent}}.contentid = {{content}}.id
+ LEFT JOIN {{value}}
+ ON {{value}}.contentid = {{content}}.id AND {{value}}.active = 1
+ WHERE elementid = {elementid}
+ AND pageid = {pageid}
+ AND languageid = {languageid}
+ AND {{value}}.publish = 1
SQL
);
$stmt->setInt( 'elementid' ,$this->elementid );
@@ -213,11 +217,14 @@ SQL
function load()
{
$stmt = Db::sql( <<<SQL
- SELECT * FROM {{value}}
+ SELECT {{value}}.* FROM {{pagecontent}}
+ LEFT JOIN {{content}}
+ ON {{pagecontent}}.contentid = {{content}}.id
+ LEFT JOIN {{value}}
+ ON {{value}}.contentid = {{content}}.id AND {{value}}.active = 1
WHERE elementid ={elementid}
AND pageid ={pageid}
AND languageid={languageid}
- AND active=1
SQL
);
$stmt->setInt( 'elementid' ,$this->elementid );