[+BUGFIX] Extbase (Persistence): Fixed typo in Exception class.
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Storage / Typo3DbBackend.php
index 003fec7..6aecfd7 100644 (file)
@@ -172,7 +172,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         */
        public function getRows(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query) {
                $statement = $this->parseQuery($query);
-//             debug($statement, -2); // FIXME remove debug code
+               // debug($statement, -2); // FIXME remove debug code
                $result = $this->databaseHandle->sql_query($statement);
                $this->checkSqlErrors();
                if ($result) {
@@ -235,9 +235,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                                $statement .= ' LIMIT ' . $sql['limit'];
                        }
                }
-
                $this->replacePlaceholders($statement, $parameters);
-               // debug($statement,-2);
                return $statement;
        }
 
@@ -260,10 +258,10 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                }
                $sql = array();
                $sql['additionalWhereClause'] = array();
-               
+
                $tableName = $dataMap->getTableName();
                $this->addEnableFieldsStatement($tableName, $sql);
-               
+
                $statement = 'SELECT * FROM ' . $tableName;
                $statement .= ' WHERE ' . implode(' AND ', $fields);
                if (!empty($sql['additionalWhereClause'])) {
@@ -362,6 +360,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         * @return void
         */
        protected function parseConstraint(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint = NULL, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, array $boundVariableValues) {
+               if ($constraint === NULL) return;
                if ($constraint instanceof Tx_Extbase_Persistence_QOM_AndInterface) {
                        $sql['where'][] = '(';
                        $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters, $boundVariableValues);
@@ -548,7 +547,8 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         * @return void
         */
        protected function addPageIdStatement($tableName, array &$sql) {
-               if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
+               $columns = $this->databaseHandle->admin_get_fields($tableName);         
+               if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $columns)) {
                        $extbaseFrameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
                        $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', t3lib_div::intExplode(',', $extbaseFrameworkConfiguration['persistence']['storagePid'])) . ')';
                }
@@ -578,10 +578,11 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                                                throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
                                }
                                $tableName = $operand->getSelectorName();
-                               if ((strlen($tableName) == 0) && (source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface)) {
-                                       $tableName = $source->getSelectorName();
+                               $className = '';
+                               if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
+                                       $className = $source->getNodeTypeName();
                                }
-                               $columnName = $this->dataMapper->convertPropertyNameToColumnName($operand->getPropertyName(), $tableName);
+                               $columnName = $this->dataMapper->convertPropertyNameToColumnName($operand->getPropertyName(), $className);
                                if (strlen($tableName) > 0) {
                                        $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
                                } else {
@@ -691,6 +692,9 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
 
        /**
         * Clear the TYPO3 page cache for the given record.
+        * If the record lies on a page, then we clear the cache of this page.
+        * If the record has no PID column, we clear the cache of the current page as best-effort.
+        *
         * Much of this functionality is taken from t3lib_tcemain::clear_cache() which unfortunately only works with logged-in BE user.
         *
         * @param $tableName Table name of the record
@@ -705,14 +709,24 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                        return;
                }
 
-               $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid='.intval($uid));
-
                $pageIdsToClear = array();
-               if ($row = $this->databaseHandle->sql_fetch_assoc($result))     {
-                       $storagePage = $row['pid'];
+               $storagePage = NULL;
+
+               $columns = $this->databaseHandle->admin_get_fields($tableName);
+               if (array_key_exists('pid', $columns)) {
+                       $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid='.intval($uid));
+                       if ($row = $this->databaseHandle->sql_fetch_assoc($result))     {
+                               $storagePage = $row['pid'];
+                               $pageIdsToClear[] = $storagePage;
+                       }
+               } elseif (isset($GLOBALS['TSFE'])) {
+                       // No PID column - we can do a best-effort to clear the cache of the current page if in FE
+                       $storagePage = $GLOBALS['TSFE']->id;
                        $pageIdsToClear[] = $storagePage;
                }
-               if (!$storagePage) {
+
+
+               if ($storagePage === NULL) {
                        return;
                }