[+BUGFIX][~API] Extbase (Persistence): Cleaned up implementation of TYPO3-specific...
authorSebastian Kurfürst <sebastian@typo3.org>
Sun, 19 Jul 2009 09:16:34 +0000 (09:16 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Sun, 19 Jul 2009 09:16:34 +0000 (09:16 +0000)
typo3/sysext/extbase/Classes/Persistence/QOM/QueryObjectModel.php
typo3/sysext/extbase/Classes/Persistence/QOM/QueryObjectModelFactory.php
typo3/sysext/extbase/Classes/Persistence/QOM/QueryObjectModelFactoryInterface.php
typo3/sysext/extbase/Classes/Persistence/QOM/QueryObjectModelInterface.php
typo3/sysext/extbase/Classes/Persistence/Query.php
typo3/sysext/extbase/Classes/Persistence/QueryFactory.php
typo3/sysext/extbase/Classes/Persistence/Storage/BackendSpecificQuerySettingsInterface.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbSpecificQuerySettings.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Typo3Query.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Typo3QueryInterface.php [new file with mode: 0644]

index a7ee944..761a2a1 100644 (file)
@@ -105,6 +105,12 @@ class Tx_Extbase_Persistence_QOM_QueryObjectModel extends Tx_Extbase_Persistence
         * @var array
         */
        protected $boundVariables = array();
+       
+       /**
+        * Backend specific query settings
+        * @var Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface
+        */
+       protected $backendSpecificQuerySettings;
 
        /**
         * Constructs this QueryObjectModel instance
@@ -113,12 +119,14 @@ class Tx_Extbase_Persistence_QOM_QueryObjectModel extends Tx_Extbase_Persistence
         * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint (null if none)
         * @param array $orderings
         * @param array $columns
+        * @param Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface $backendSpecificQuerySettings Storage backend specific query settings (or NULL)
         */
-       public function __construct(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns) {
+       public function __construct(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns, $backendSpecificQuerySettings) {
                $this->source = $selectorOrSource;
                $this->constraint = $constraint;
                $this->orderings = $orderings;
                $this->columns = $columns;
+               $this->backendSpecificQuerySettings = $backendSpecificQuerySettings;
 
                if ($this->constraint !== NULL) {
                        $this->constraint->collectBoundVariableNames($this->boundVariables);
@@ -190,6 +198,15 @@ class Tx_Extbase_Persistence_QOM_QueryObjectModel extends Tx_Extbase_Persistence
                return $this->columns;
        }
 
+       /**
+        * Backend specific query settings
+        * 
+        * @return Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface Backend specific query settings
+        */
+       public function getBackendSpecificQuerySettings() {
+               return $this->backendSpecificQuerySettings;
+       }
+
        /**
         * Binds the given value to the variable named $varName.
         *
index e62685e..b48ce6c 100644 (file)
@@ -64,12 +64,13 @@ class Tx_Extbase_Persistence_QOM_QueryObjectModelFactory implements Tx_Extbase_P
         * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
         * @param array $orderings zero or more orderings; null is equivalent to a zero-length array
         * @param array $columns the columns; null is equivalent to a zero-length array
+        * @param Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface $backendSpecificQuerySettings Backend specific query settings (or NULL)
         * @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
         * @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test and the parameters given fail that test. See the individual QOM factory methods for the validity criteria of each query element.
         * @throws Tx_Extbase_Persistence_Exception_RepositoryException if another error occurs.
         */
-       public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns) {
-               $query =  new Tx_Extbase_Persistence_QOM_QueryObjectModel($selectorOrSource, $constraint, $orderings, $columns);
+       public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns, $backendSpecificQuerySettings) {
+               $query =  new Tx_Extbase_Persistence_QOM_QueryObjectModel($selectorOrSource, $constraint, $orderings, $columns, $backendSpecificQuerySettings);
                $query->injectStorageBackend($this->storageBackend);
                $query->injectDataMapper($this->dataMapper);
                return $query;
index 0a4b80b..d77de87 100644 (file)
@@ -49,9 +49,10 @@ interface Tx_Extbase_Persistence_QOM_QueryObjectModelFactoryInterface extends Tx
         * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
         * @param array $orderings zero or more orderings; null is equivalent to a zero-length array
         * @param array $columns the columns; null is equivalent to a zero-length array
+        * @param Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface $backendSpecificQuerySettings Backend specific query settings (or NULL)
         * @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
         */
-       public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns);
+       public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns, $backendSpecificQuerySettings);
 
        /**
         * Selects a subset of the nodes in the repository based on node type.
index eb5824c..9a29c24 100644 (file)
@@ -88,6 +88,13 @@ interface Tx_Extbase_Persistence_QOM_QueryObjectModelInterface {
        */
        public function getColumns();
 
+       /**
+        * Backend specific query settings
+        * 
+        * @return Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface Backend specific query settings
+        */
+       public function getBackendSpecificQuerySettings();
+
        /**
         * Binds the given value to the variable named $varName.
         *
index 8c5eea3..0df0f5d 100644 (file)
@@ -95,12 +95,13 @@ class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterf
         * @var int
         */
        protected $offset;
-
+       
        /**
-        * Storage page ID. If set, will be automatically added to the query on execute.
-        * @var integer
+        * backend specific query settings. Must be instanciated in subclasses.
+        * 
+        * @var Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface
         */
-       protected $storagePageId = NULL;
+       protected $backendSpecificQuerySettings;
        
        /**
         * Constructs a query object working on the given class name
@@ -132,19 +133,6 @@ class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterf
        public function injectDataMapper(Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper) {
                $this->dataMapper = $dataMapper;
        }
-
-       /**
-        * Sets the storage page ID.
-        * 
-        * Do NOT call this method yourself! It is automatically called in QueryFactory.
-        * 
-        * @param integer $storagePageId Storage page ID to be used.
-        * @return void
-        * @internal
-        */
-       public function setStoragePageId($storagePageId) {
-               $this->storagePageId = $storagePageId;
-       }
        
        /**
         * Returns the class name the query handles
@@ -182,27 +170,12 @@ class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterf
         * @return Tx_Extbase_Persistence_QueryResultInterface The query result
         */
        public function execute() {
-               if ($this->storagePageId !== NULL) {
-                       // storage Page ID has been set, so we have to add this to the query!
-                       if ($this->constraint !== NULL) {
-                               $this->matching(
-                                       $this->logicalAnd(
-                                               $this->equals('pid', $this->storagePageId),
-                                               $this->constraint
-                                       )
-                               );
-                       } else {
-                               $this->matching(
-                                       $this->equals('pid', $this->storagePageId)
-                               );
-                       }
-               }
-               
                $query = $this->QOMFactory->createQuery(
                        $this->getSource(),
                        $this->constraint,
                        $this->orderings,
-                       $this->columns // TODO implement selection of columns
+                       $this->columns, // TODO implement selection of columns
+                       $this->backendSpecificQuerySettings
                );
                foreach ($this->operands as $name => $value) {
                        $query->bindValue($name, $this->valueFactory->createValue($value));
index 37d9969..1b27bf4 100644 (file)
@@ -55,21 +55,18 @@ class Tx_Extbase_Persistence_QueryFactory implements Tx_Extbase_Persistence_Quer
         * @param boolean $useStoragePageId TRUE if queries should automatically be restricted to the current storage PID, FALSE otherwise.
         * @return Tx_Extbase_Persistence_QueryInterface
         */
-       public function create($className, $useStoragePageId = TRUE) {
+       public function create($className) {
                $persistenceManager = Tx_Extbase_Dispatcher::getPersistenceManager();
 
                $dataMapper = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapper');
                $dataMapper->injectIdentityMap($persistenceManager->getBackend()->getIdentityMap());
                $dataMapper->injectPersistenceManager($persistenceManager);
 
-               $query = t3lib_div::makeInstance('Tx_Extbase_Persistence_Query', $className);
+               $query = t3lib_div::makeInstance('Tx_Extbase_Persistence_Typo3Query', $className);
                $query->injectPersistenceManager($persistenceManager);
                $query->injectDataMapper($dataMapper);
-               if ($useStoragePageId) {
-                       $query->setStoragePageId($this->storagePageId);
-               }
+               $query->setStoragePageId($this->storagePageId);
                return $query;
        }
-
 }
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Classes/Persistence/Storage/BackendSpecificQuerySettingsInterface.php b/typo3/sysext/extbase/Classes/Persistence/Storage/BackendSpecificQuerySettingsInterface.php
new file mode 100644 (file)
index 0000000..8d4195b
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Marker interface for backend specific query options
+ *
+ * @package Extbase
+ * @subpackage Persistence
+ * @version $Id: BackendInterface.php 2120 2009-04-02 10:06:31Z k-fish $
+ */
+interface Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface {
+
+}
+?>
\ No newline at end of file
index 805518a..ff40dff 100644 (file)
@@ -51,13 +51,6 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         */
        protected $pageSelectObject;
 
-       /**
-        * TRUE if the framework should add the "enable fields" (e.g. checking for hidden or deleted records)
-        *
-        * @var boolean
-        */
-       protected $useEnableFields = TRUE;
-
        /**
         * TRUE if automatic cache clearing in TCEMAIN should be done on insert/update/delete, FALSE otherwise.
         *  
@@ -186,6 +179,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                $sqlString = 'SELECT ' . implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']);
 
                $this->parseConstraint($query->getConstraint(), $sql, $parameters, $query->getBoundVariableValues());
+
                if (!empty($sql['where'])) {
                        $sqlString .= ' WHERE ' . implode('', $sql['where']);
                        if (!empty($sql['enableFields'])) {
@@ -249,16 +243,18 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         * @param array &$parameters
         * @return void
         */
-       protected function parseSource(Tx_Extbase_Persistence_QOM_QueryObjectModel $query, array &$sql, array &$parameters) {
+       protected function parseSource(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, array &$sql, array &$parameters) {
                $source = $query->getSource();
                if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
                        $selectorName = $source->getSelectorName();
                        $sql['fields'][] = $selectorName . '.*';
                        $sql['tables'][] = $selectorName;
-                       // TODO Should we make the usage of enableFields configurable? And how? Because the Query object and even the QOM should be abstracted from the storage backend.
-                       if ($this->useEnableFields === TRUE) {
+                       if ($query->getBackendSpecificQuerySettings()->enableFieldsEnabled()) {
                                $this->addEnableFieldsStatement($selectorName, $sql);
                        }
+                       if ($query->getBackendSpecificQuerySettings()->storagePageEnabled()) {
+                               $sql['enableFields'][] = $selectorName . '.pid=' . intval($query->getBackendSpecificQuerySettings()->getStoragePageId());
+                       }
                } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
                        $this->parseJoin($source, $sql, $parameters);
                }
diff --git a/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbSpecificQuerySettings.php b/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbSpecificQuerySettings.php
new file mode 100644 (file)
index 0000000..e2c54e7
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3.
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * TYPO3 DB specific query settings like use of a PID
+ *
+ * @package Extbase
+ * @subpackage Persistence
+ * @version $Id: BackendInterface.php 2120 2009-04-02 10:06:31Z k-fish $
+ */
+class Tx_Extbase_Persistence_Storage_Typo3DbSpecificQuerySettings implements Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface {
+
+       protected $useStoragePage = TRUE;
+
+       protected $useEnableFields = TRUE;
+       
+       protected $storagePageId;
+       
+       public function useStoragePage($useStoragePage) {
+               $this->useStoragePage = (boolean)$useStoragePage;
+       }
+       
+       public function storagePageEnabled() {
+               return $this->useStoragePage;
+       }
+
+       public function getStoragePageId() {
+               return $this->storagePageId;
+       }
+       public function setStoragePageId($storagePageId) {
+               $this->storagePageId = $storagePageId;
+       }
+       public function enableFieldsEnabled() {
+               return $this->useEnableFields;
+       }
+       public function useEnableFields($useEnableFields) {
+               $this->useEnableFields = $useEnableFields;
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Classes/Persistence/Typo3Query.php b/typo3/sysext/extbase/Classes/Persistence/Typo3Query.php
new file mode 100644 (file)
index 0000000..f4fc410
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3. 
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * A persistence query interface
+ *
+ * @package TYPO3
+ * @subpackage Extbase
+ * @version $Id: QueryInterface.php 658 2009-05-16 13:54:16Z jocrau $
+ */
+class Tx_Extbase_Persistence_Typo3Query extends Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_Typo3QueryInterface {
+       
+       /**
+        * Constructs a query object working on the given class name
+        *
+        * @param string $className
+        */
+       public function __construct($className) {
+               parent::__construct($className);
+               $this->backendSpecificQuerySettings = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbSpecificQuerySettings');
+       }
+       
+       /**
+        * Sets the storage page ID.
+        * 
+        * Do NOT call this method yourself! It is automatically called in QueryFactory.
+        * 
+        * @param integer $storagePageId Storage page ID to be used.
+        * @return void
+        * @internal
+        */
+       public function setStoragePageId($storagePageId) {
+               $this->backendSpecificQuerySettings->setStoragePageId($storagePageId);
+       }
+       
+       /**
+        * (non-PHPdoc)
+        * @see Classes/Persistence/Tx_Extbase_Persistence_Typo3QueryInterface#useStoragePage($useStoragePage)
+        */
+       public function useStoragePage($useStoragePage) {
+               $this->backendSpecificQuerySettings->useStoragePage($useStoragePage);
+               return this;
+       }
+       
+       /**
+        * (non-PHPdoc)
+        * @see Classes/Persistence/Tx_Extbase_Persistence_Typo3QueryInterface#useEnableFields($useEnableFields)
+        */
+       public function useEnableFields($useEnableFields) {
+               $this->backendSpecificQuerySettings->useEnableFields($useEnableFields);
+               return this;
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Classes/Persistence/Typo3QueryInterface.php b/typo3/sysext/extbase/Classes/Persistence/Typo3QueryInterface.php
new file mode 100644 (file)
index 0000000..d45ec69
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This class is a backport of the corresponding class of FLOW3. 
+*  All credits go to the v5 team.
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * A persistence query interface
+ *
+ * @package TYPO3
+ * @subpackage Extbase
+ * @version $Id: QueryInterface.php 658 2009-05-16 13:54:16Z jocrau $
+ */
+interface Tx_Extbase_Persistence_Typo3QueryInterface extends Tx_Extbase_Persistence_QueryInterface {
+       /**
+        * Sets the storage page ID.
+        * 
+        * Do NOT call this method yourself! It is automatically called in QueryFactory.
+        * 
+        * @param integer $storagePageId Storage page ID to be used.
+        * @return void
+        * @internal
+        */
+       public function setStoragePageId($storagePageId);
+               
+       /**
+        * Use storage page
+        * 
+        * @param $useStoragePage if TRUE, should use storage PID. use FALSE to disable the storage Page ID checking 
+        * @return void
+        */
+       public function useStoragePage($useStoragePage);
+       
+       /**
+        * Use enable fields
+        * 
+        * @param $useEnableFields if TRUE, will add enable fields. use FALSE to disable the enable fields checking
+        * @return void
+        */
+       public function useEnableFields($useEnableFields);
+}
+?>
\ No newline at end of file