openrat-cms

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

commit 4da408ff55e4069ac5fb02ed9ebaabd3cac41d03
parent 494425054102f4683e16a96f7ca29de9ef9d0565
Author: dankert <openrat@jandankert.de>
Date:   Thu, 10 Mar 2022 10:28:14 +0100

Fix: Fulltext-Search was broken due to the last Content-Refactoring

Diffstat:
Mmodules/cms/action/SearchAction.class.php | 33++++++++++++++++++++++-----------
Mmodules/cms/model/Content.class.php | 12++++++++----
Mmodules/cms/model/Template.class.php | 19+++++++++++--------
3 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/modules/cms/action/SearchAction.class.php b/modules/cms/action/SearchAction.class.php @@ -3,6 +3,7 @@ namespace cms\action; use cms\base\Configuration as C; +use cms\model\Content; use cms\model\Permission; use cms\model\BaseObject; use cms\model\File; @@ -101,7 +102,7 @@ class SearchAction extends BaseAction 'lastchange_date' => 0 ); $resultList['u'.$user->userid] = $userResult; } - catch( \util\exception\ObjectNotFoundException $e) { + catch( \util\exception\ObjectNotFoundException $content) { ; // userid is unknown } } @@ -141,8 +142,7 @@ class SearchAction extends BaseAction // Inhalte durchsuchen if ( $searchFlag & self::FLAG_VALUE ) { - $e = new Value(); - $listObjectIds += $e->getObjectIdsByValue( $searchText ); + $listObjectIds += Content::getObjectIdsByValue( $searchText ); $listTemplateIds += Template::getTemplateIdsByValue( $searchText ); } @@ -151,10 +151,15 @@ class SearchAction extends BaseAction $this->setTemplateVar( 'result',$resultList ); } - - + + /** + * Transforms the found objects into an array of search results. * + * @param $listObjectIds Object ids + * @param $listTemplateIds template ids + * @return array + * @throws \util\exception\ObjectNotFoundException */ private function explainResult( $listObjectIds, $listTemplateIds ) { @@ -165,13 +170,13 @@ class SearchAction extends BaseAction $o = new BaseObject( $objectid ); $o->load(); if ($o->hasRight( Permission::ACL_READ )) - $resultList['o'.$objectid] = array( + $resultList['o'.$objectid] = [ 'id' => $objectid, 'type' => $o->getType(), 'name' => $o->filename, 'lastchange_date' => $o->lastchangeDate, 'desc' => '' - ); + ]; } foreach( $listTemplateIds as $templateid ) @@ -179,21 +184,27 @@ class SearchAction extends BaseAction $t = new Template( $templateid ); $t->load(); $p = new Project( $t->projectid ); - $o = new BaseObject( $p->getRootObjectId() ); - if ($o->hasRight( Permission::ACL_PROP )) - $resultList['t'.$templateid] = array( + $rootObject = new BaseObject( $p->getRootObjectId() ); + if ($rootObject->hasRight( Permission::ACL_PROP )) // only project admins may read the templates + $resultList['t'.$templateid] = [ 'id' => $templateid, 'type'=> 'template', 'name'=> $t->name, 'desc'=> '', 'lastchange_date'=> 0 - ); + ]; } return $resultList; } + /** + * The search is executable for all users. + * But the search results are filtered. + * + * @return true + */ public function checkAccess() { return true; } diff --git a/modules/cms/model/Content.class.php b/modules/cms/model/Content.class.php @@ -344,14 +344,18 @@ SQL * @param String Suchbegriff * @return array Liste der gefundenen Objekt-IDs */ - function getObjectIdsByValue( $text ) + public static function getObjectIdsByValue( $text ) { $sql = DB::sql( <<<SQL - SELECT {{object}}.id FROM {{value}} + SELECT {{object}}.id FROM {{object}} LEFT JOIN {{page}} - ON {{page}}.id={{value}}.pageid - LEFT JOIN {{object}} ON {{object}}.id={{page}}.objectid + LEFT JOIN {{pagecontent}} + ON {{page}}.id={{pagecontent}}.pageid + LEFT JOIN {{content}} + ON {{pagecontent}}.contentid={{content}}.id + LEFT JOIN {{value}} + ON {{content}}.id={{value}}.contentid WHERE {{value}}.text LIKE {text} ORDER BY {{object}}.lastchange_date DESC SQL diff --git a/modules/cms/model/Template.class.php b/modules/cms/model/Template.class.php @@ -126,10 +126,15 @@ SQL */ public static function getTemplateIdsByValue( $text ) { - $db = \cms\base\DB::get(); - - $stmt = $db->sql( 'SELECT templateid FROM {{templatemodel}}'. - ' WHERE text LIKE {text} ' ); + $stmt = DB::sql( <<<SQL + SELECT templateid FROM {{templatemodel}} + LEFT JOIN {{content}} + ON {{content}}.id = {{templatemodel}}.contentid + LEFT JOIN {{value}} + ON {{value}}.contentid = {{content}}.id + WHERE {{value}}.text LIKE {text} +SQL + ); $stmt->setString( 'text' ,'%'.$text.'%' ); @@ -142,11 +147,9 @@ SQL * Es wird eine Liste nur mit den Element-IDs ermittelt und zur?ckgegeben * @return array */ - function getElementIds() + public function getElementIds() { - $db = \cms\base\DB::get(); - - $stmt = $db->sql( 'SELECT id FROM {{element}}'. + $stmt = DB::sql( 'SELECT id FROM {{element}}'. ' WHERE templateid={templateid}'. ' ORDER BY name ASC' ); $stmt->setInt( 'templateid',$this->templateid );