From 3f998a2d3aa2c4c16185c556d89cf755125cc699 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 1 Sep 2011 07:42:12 +0000 Subject: [PATCH] Some 'static' array elements rewritten to constant, other cleanups --- .../interfaces/cache/class_Cacheable.php | 29 +++- inc/classes/main/cache/class_MemoryCache.php | 23 +++- .../main/class_BaseFrameworkSystem.php | 19 +++ .../main/criteria/class_BaseCriteria.php | 128 ++++++++++++++++++ .../dataset/class_DataSetCriteria.php | 40 +----- .../criteria/search/class_SearchCriteria.php | 104 +------------- .../database/class_BaseDatabaseFrontend.php | 8 +- .../database/class_BaseDatabaseWrapper.php | 108 +++++++++++---- .../databases/class_LocalFileDatabase.php | 19 +-- .../wrapper/class_UserDatabaseWrapper.php | 2 +- .../class_UserPointsDatabaseWrapper.php | 2 +- .../main/filter/class_BaseFilterDecorator.php | 2 +- .../main/result/class_DatabaseResult.php | 17 ++- 13 files changed, 302 insertions(+), 199 deletions(-) diff --git a/inc/classes/interfaces/cache/class_Cacheable.php b/inc/classes/interfaces/cache/class_Cacheable.php index 6380f22b..4c9ee077 100644 --- a/inc/classes/interfaces/cache/class_Cacheable.php +++ b/inc/classes/interfaces/cache/class_Cacheable.php @@ -25,10 +25,35 @@ interface Cacheable extends FrameworkInterface { /** * Does the specified offset exist in cache? * - * @param $offset The offsrt we are looking for + * @param $offset The offset we are looking for * @return $exists Wether the offset exists */ - function offsetExists ($offset); + function offsetExists($offset); + + /** + * Setter for cache offset + * + * @param $offset The offset we shall set + * @param $data Data to store in cache + * @return void + */ + function offsetSet($offset, $data); + + /** + * Getter for cache offset or "null" if not found + * + * @param $offset The offset we shall set + * @return $data Data to store in cache + */ + function offsetGet($offset); + + /** + * Purges the given cache entry + * + * @param $offset The offset we shall set + * @return void + */ + function purgeOffset($offset); } // [EOF] diff --git a/inc/classes/main/cache/class_MemoryCache.php b/inc/classes/main/cache/class_MemoryCache.php index a38a65ba..c3e24cc1 100644 --- a/inc/classes/main/cache/class_MemoryCache.php +++ b/inc/classes/main/cache/class_MemoryCache.php @@ -69,7 +69,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable { * @param $offset The offset we are looking for * @return $exists Wether the offset exists */ - public final function offsetExists ($offset) { + public function offsetExists ($offset) { $exists = $this->dataCache->offsetExists($offset); return $exists; } @@ -81,7 +81,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable { * @param $data Data to store in cache * @return void */ - public final function offsetSet ($offset, $data) { + public function offsetSet ($offset, $data) { $this->dataCache->offsetSet($offset, $data); } @@ -91,7 +91,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable { * @param $offset The offset we shall set * @return $data Data to store in cache */ - public final function offsetGet ($offset) { + public function offsetGet ($offset) { // Default is offset not found $data = NULL; @@ -99,11 +99,26 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable { if ($this->offsetExists($offset)) { // Then get the data from it $data = $this->dataCache->offsetGet($offset); - } + } // END - if // Return data return $data; } + + /** + * Purges the given cache entry + * + * @param $offset The offset we shall set + * @return void + */ + public function purgeOffset ($offset) { + // Is the offset there? + if ($this->offsetExists($offset)) { + // Purge only existing keys + /* DEBUG: */ $this->debugOutput('CACHE: Unsetting cache ' . $offset); + $this->dataCache->offsetUnset($offset); + } // END - if + } } // [EOF] diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index f9474ca7..bdc442ee 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1897,6 +1897,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Return it return $responseType; } + + /** + * Gets a cache key from Criteria instance + * + * @param $criteriaInstance An instance of a Criteria class + * @param $onlyKeys Only use these keys for a cache key + * @return $cacheKey A cache key suitable for lookup/storage purposes + */ + protected function getCacheKeyByCriteria (Criteria $criteriaInstance, $onlyKeys = array()) { + // Generate it + $cacheKey = sprintf("%s@%s", + $this->__toString(), + $criteriaInstance->getCacheKey($onlyKeys) + ); + + // And return it + //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey); + return $cacheKey; + } } // [EOF] diff --git a/inc/classes/main/criteria/class_BaseCriteria.php b/inc/classes/main/criteria/class_BaseCriteria.php index 5c94e1eb..4bec36a6 100644 --- a/inc/classes/main/criteria/class_BaseCriteria.php +++ b/inc/classes/main/criteria/class_BaseCriteria.php @@ -27,6 +27,10 @@ class BaseCriteria extends BaseFrameworkSystem { */ private $wrapperConfigEntry = ''; + /** + * Criteria to handle + */ + private $criteria = array(); /** * Protected constructor * @@ -56,6 +60,130 @@ class BaseCriteria extends BaseFrameworkSystem { public final function getWrapperConfigEntry () { return $this->wrapperConfigEntry; } + + /** + * Getter for criteria array + * + * @return $criteria + */ + public final function getCriteriaArray () { + return $this->criteria; + } + + /** + * Add criteria + * + * @param $criteriaKey Criteria key + * @param $criteriaValue Criteria value + * @return void + */ + public final function addCriteria ($criteriaKey, $criteriaValue) { + $this->criteria[(string)$criteriaKey] = (string)$criteriaValue; + } + + /** + * Add configured criteria + * + * @param $criteriaKey Criteria key + * @param $configEntry Configuration entry + * @return void + */ + public final function addConfiguredCriteria ($criteriaKey, $configEntry) { + // Add the configuration entry as a criteria + $value = $this->getConfigInstance()->getConfigEntry($configEntry); + $this->addCriteria($criteriaKey, $value); + } + + /** + * Get criteria element or null if not found + * + * @param $criteria The criteria we want to have + * @return $value Wether the value of the critera or null + */ + public function getCriteriaElemnent ($criteria) { + // Default is not found + $value = NULL; + + // Is the criteria there? + if (isset($this->criteria[$criteria])) { + // Then use it + $value = $this->criteria[$criteria]; + } + + // Return the value + return $value; + } + + /** + * Checks wether given array entry matches + * + * @param $entryArray Array with the entries to find + * @return $matches Wether the entry matches or not + */ + public function ifEntryMatches (array $entryArray) { + // First nothing matches and nothing is counted + $matches = false; + $counted = 0; + + // Walk through all entries + foreach ($entryArray as $key => $entry) { + // Then walk through all search criteria + foreach ($this->criteria as $criteriaKey => $criteriaValue) { + // Is the element found and does it match? + if (($key == $criteriaKey) && ($criteriaValue == $entry)) { + // Then count this one up + $counted++; + } // END - if + } // END - foreach + } // END - foreach + + // Now check if expected criteria counts match + $matches = ($counted == count($this->criteria)); + + // Return the result + return $matches; + } + + /** + * "Getter" for a cache key + * + * @param $onlyKeys Only use these keys for a cache key + * @return $cacheKey The key suitable for the cache system + */ + public function getCacheKey ($onlyKeys = array()) { + // Initialize the key + $cacheKey = ''; + + // Now walk through all criterias + foreach ($this->criteria as $criteriaKey => $criteriaValue) { + // Is the value in array or is $onlyKeys empty? + if ((isset($onlyKeys[$criteriaKey])) || (count($onlyKeys) == 0)) { + // Add the value URL encoded to avoid any trouble with special characters + $cacheKey .= sprintf("%s=%s;", + $criteriaKey, + urlencode($criteriaValue) + ); + } // END - if + } // END - foreach + + // Remove last semicolon + $cacheKey = substr($cacheKey, 0, -1); + + // Is the instance SearchCriteria? + if ($this instanceof SearchCriteria) { + // Check if 'limit' and 'skip' are in + if (((isset($onlyKeys['limit'])) && (isset($onlyKeys['skip']))) || (count($onlyKeys) == 0)) { + // Add limit and skip values + $cacheKey .= sprintf(";%%limit%%=%s;%%skip%%=%s", + $this->getLimit(), + $this->getSkip() + ); + } // END - if + } // END - if + + // Return the cache key + return $cacheKey; + } } // [EOF] diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php index cf4fdc96..516f007e 100644 --- a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php +++ b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php @@ -28,11 +28,6 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { */ private $tableName = ''; - /** - * Table columns (criteria) to store - */ - private $tableColumns = array(); - /** * Unique key */ @@ -70,30 +65,6 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { return $criteriaInstance; } - /** - * Add criteria - * - * @param $criteriaKey Criteria key - * @param $criteriaValue Criteria value - * @return void - */ - public function addCriteria ($criteriaKey, $criteriaValue) { - $this->tableColumns[(string) $criteriaKey] = $criteriaValue; - } - - /** - * Add configured criteria - * - * @param $criteriaKey Criteria key - * @param $configEntry Configuration entry - * @return void - */ - public function addConfiguredCriteria ($criteriaKey, $configEntry) { - // Add configuration entry as criteria - $value = $this->getConfigInstance()->getConfigEntry($configEntry); - $this->addCriteria($criteriaKey, $value); - } - /** * Setter for table name * @@ -138,16 +109,7 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria { * @return $uniqueValue Value of the unique key */ public final function getUniqueValue () { - return $this->tableColumns[$this->getUniqueKey()]; - } - - /** - * Getter for criteria array - * - * @return $tableColumns - */ - public final function getCriteriaArray () { - return $this->tableColumns; + return $this->getCriteriaElemnent($this->getUniqueKey()); } /** diff --git a/inc/classes/main/criteria/search/class_SearchCriteria.php b/inc/classes/main/criteria/search/class_SearchCriteria.php index 9692b713..eddc63e6 100644 --- a/inc/classes/main/criteria/search/class_SearchCriteria.php +++ b/inc/classes/main/criteria/search/class_SearchCriteria.php @@ -27,7 +27,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { /** * Criteria to handle */ - private $searchCriteria = array(); + private $criteria = array(); /** * Limitation for the search @@ -62,30 +62,6 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { return $criteriaInstance; } - /** - * Add criteria - * - * @param $criteriaKey Criteria key - * @param $criteriaValue Criteria value - * @return void - */ - public final function addCriteria ($criteriaKey, $criteriaValue) { - $this->searchCriteria[(string)$criteriaKey] = (string)$criteriaValue; - } - - /** - * Add configured criteria - * - * @param $criteriaKey Criteria key - * @param $configEntry Configuration entry - * @return void - */ - public final function addConfiguredCriteria ($criteriaKey, $configEntry) { - // Add the configuration entry as a criteria - $value = $this->getConfigInstance()->getConfigEntry($configEntry); - $this->addCriteria($criteriaKey, $value); - } - /** * Setter for limit * @@ -137,84 +113,6 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria { public final function getSkip () { return $this->skip; } - - /** - * "Getter" for a cache key - * - * @return $cacheKey The key suitable for the cache system - */ - public function getCacheKey () { - // Initialize the key - $cacheKey = ''; - - // Now walk through all criterias - foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) { - // Add the value URL encoded to avoid any trouble with special characters - $cacheKey .= sprintf("%s=%s;", - $criteriaKey, - urlencode($criteriaValue) - ); - } - - // Add limit and skip values - $cacheKey .= sprintf("%%limit%%=%s;%%skip%%=%s", - $this->limit, - $this->skip - ); - - // Return the cache key - return $cacheKey; - } - - /** - * Get criteria element or null if not found - * - * @param $criteria The criteria we want to have - * @return $value Wether the value of the critera or null - */ - public function getCriteriaElemnent ($criteria) { - // Default is not found - $value = NULL; - - // Is the criteria there? - if (isset($this->searchCriteria[$criteria])) { - // Then use it - $value = $this->searchCriteria[$criteria]; - } - - // Return the value - return $value; - } - - /** - * Checks wether given array entry matches - * - * @param $entryArray Array with the entries to find - * @return $matches Wether the entry matches or not - */ - public function ifEntryMatches (array $entryArray) { - // First nothing matches and nothing is counted - $matches = false; - $counted = 0; - - // Walk through all entries - foreach ($entryArray as $key => $entry) { - // Then walk through all search criteria - foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) { - // Is the element found and does it match? - if (($key == $criteriaKey) && ($criteriaValue == $entry)) { - // Then count this one up - $counted++; - } // END - if - } // END - foreach - } // END - foreach - - // Now check if expected criteria counts match - $matches = ($counted == count($this->searchCriteria)); - - // Return the result - return $matches; - } } // [EOF] diff --git a/inc/classes/main/database/class_BaseDatabaseFrontend.php b/inc/classes/main/database/class_BaseDatabaseFrontend.php index 2001a11f..40d563b4 100644 --- a/inc/classes/main/database/class_BaseDatabaseFrontend.php +++ b/inc/classes/main/database/class_BaseDatabaseFrontend.php @@ -26,10 +26,10 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements Datab // Constants for exceptions const EXCEPTION_SQL_QUERY = 0x140; - /** - * The limiter instance - */ - private $limitInstance = NULL; + // Result array indexes + const RESULT_INDEX_ROWS = 'rows'; + const RESULT_INDEX_STATUS = 'status'; + const RESULT_INDEX_EXCEPTION = 'exception'; /** * Protected constructor diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index 76d486e2..25b34774 100644 --- a/inc/classes/main/database/class_BaseDatabaseWrapper.php +++ b/inc/classes/main/database/class_BaseDatabaseWrapper.php @@ -55,25 +55,92 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache(); } + /** + * Setter for table name + * + * @param $tableName Name of table name to set + * @return void + */ + protected final function setTableName ($tableName) { + $this->tableName = (string) $tableName; + } + + /** + * Getter for table name + * + * @return $tableName Name of table name to set + */ + protected final function getTableName () { + return $this->tableName; + } + + /** + * 'Inserts' a data set instance into a local file database folder + * + * @param $dataSetInstance A storeable data set + * @param $onlyKeys Only use these keys for a cache key + * @return void + */ + protected function queryInsertDataSet (StoreableCriteria $dataSetInstance, $onlyKeys = array()) { + // First get a key suitable for our cache and extend it with this class name + $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys); + //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...'); + + // Does this key exists in cache? + if ($this->cacheInstance->offsetExists($cacheKey)) { + // Purge the cache + $this->cacheInstance->purgeOffset($cacheKey); + } // END - if + + // Handle it over to the middleware + $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance); + } + + /** + * 'Updates' a data set instance with a database layer + * + * @param $dataSetInstance A storeable data set + * @param $onlyKeys Only use these keys for a cache key + * @return void + */ + protected function queryUpdateDataSet (StoreableCriteria $dataSetInstance, $onlyKeys = array()) { + // First get a key suitable for our cache and extend it with this class name + $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys); + //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...'); + + // Does this key exists in cache? + if ($this->cacheInstance->offsetExists($cacheKey)) { + // Purge the cache + $this->cacheInstance->purgeOffset($cacheKey); + } // END - if + + // Handle it over to the middleware + $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance); + } + /** * Do a "select" query on the current table with the given search criteria and * store it in cache for later usage * * @param $criteriaInstance An instance of a Criteria class + * @param $onlyKeys Only use these keys for a cache key * @return $resultInstance An instance of a database result class */ - public function doSelectByCriteria (Criteria $criteriaInstance) { + public function doSelectByCriteria (Criteria $criteriaInstance, $onlyKeys = array()) { // First get a key suitable for our cache and extend it with this class name - $cacheKey = sprintf("%s@%s", - $this->__toString(), - $criteriaInstance->getCacheKey() - ); + $cacheKey = $this->getCacheKeyByCriteria($criteriaInstance, $onlyKeys); // Does this key exists in cache? if ($this->cacheInstance->offsetExists($cacheKey)) { + // Debug message + //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey); + // Then use this result $result = $this->cacheInstance->offsetGet($cacheKey); } else { + // Debug message + //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Quering database, cacheKey=' . $cacheKey); + // Now it's time to ask the database layer for this select statement $result = $this->getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance); @@ -84,8 +151,8 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { } else { // This invalid result must be wrapped $result = array( - 'status' => 'invalid', - 'exception' => $this->getDatabaseInstance()->getLastException() + BaseDatabaseFrontend::RESULT_INDEX_STATUS => 'invalid', + BaseDatabaseFrontend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException() ); } } @@ -101,44 +168,29 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { * Count the numbers of rows we shall receive * * @param $criteriaInstance An instance of a Criteria class + * @param $onlyKeys Only use these keys for a cache key * @return $numRows Numbers of rows of database entries */ - public function doSelectCountByCriteria (Criteria $criteriaInstance) { + public function doSelectCountByCriteria (Criteria $criteriaInstance, $onlyKeys = array()) { // Total numbers is -1 so we can distinglish between failed and valid queries $numRows = 0; // Get the result from above method - $resultInstance = $this->doSelectByCriteria($criteriaInstance); + $resultInstance = $this->doSelectByCriteria($criteriaInstance, $onlyKeys); // Was that query fine? if ($resultInstance->ifStatusIsOkay()) { // Then get the number of rows $numRows = $resultInstance->getAffectedRows(); + + // Debug message + //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: numRows=' . $numRows); } // END - if // Return the result return $numRows; } - /** - * Setter for table name - * - * @param $tableName Name of table name to set - * @return void - */ - protected final function setTableName ($tableName) { - $this->tableName = (string) $tableName; - } - - /** - * Getter for table name - * - * @return $tableName Name of table name to set - */ - protected final function getTableName () { - return $this->tableName; - } - /** * Getter for primary key used in wrapped table * diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index 083729ef..37dca8fc 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -359,8 +359,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Initialize the result data, this need to be rewritten e.g. if a local file cannot be read $resultData = array( - 'status' => LocalfileDatabase::RESULT_OKAY, - 'rows' => array() + BaseDatabaseFrontend::RESULT_INDEX_STATUS => LocalfileDatabase::RESULT_OKAY, + BaseDatabaseFrontend::RESULT_INDEX_ROWS => array() ); // Initialize limit/skip @@ -369,7 +369,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $idx = 1; // Read the directory with some exceptions - while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', "info." . $this->getFileExtension()))) && ($limitFound < $criteriaInstance->getLimit())) { + while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && (($limitFound < $criteriaInstance->getLimit()) || ($criteriaInstance->getLimit() == 0))) { // Does the extension match? if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) { // Skip this file! @@ -387,8 +387,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $criteria = $criteriaInstance->getCriteriaElemnent($key); // Is the criteria met? + //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: criteria[' . gettype($criteria) . ']=' . $criteria . ',()=' . strlen($criteria) . ',value=' . $value . ',()=' . strlen($value)); if ((!is_null($criteria)) && ($criteria == $value)) { - // Shall we skip this entry? if ($criteriaInstance->getSkip() > 0) { // We shall skip some entries @@ -403,7 +403,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $dataArray[$this->getIndexKey()] = $idx; // Entry found! - $resultData['rows'][] = $dataArray; + //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: indexKey=' . $this->getIndexKey() . ',idx=' . $idx . ',dataArray=' . print_r($dataArray, true)); + $resultData[BaseDatabaseFrontend::RESULT_INDEX_ROWS][] = $dataArray; // Count found entries up $limitFound++; @@ -428,14 +429,14 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend } catch (PathIsNoDirectoryException $e) { // Path not found means "table not found" for real databases... $this->lastException = $e; - $this->lastError = $e->getMessage(); + $this->lastError = $e->getMessage(); // So throw an SqlException here with faked error message throw new SqlException (array($this, sprintf("Table '%s' not found", $tableName), self::DB_CODE_TABLE_MISSING), self::EXCEPTION_SQL_QUERY); } catch (FrameworkException $e) { // Catch all exceptions and store them in last error $this->lastException = $e; - $this->lastError = $e->getMessage(); + $this->lastError = $e->getMessage(); } // Return the gathered result @@ -469,7 +470,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $this->lastError = $e->getMessage(); // Throw an SQL exception - throw new SqlException (array($this, sprintf("Cannot write data to table '%s', is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY); + throw new SqlException(array($this, sprintf("Cannot write data to table '%s', is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY); } } @@ -560,7 +561,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend $this->lastError = $e->getMessage(); // Throw an SQL exception - throw new SqlException (array($this, sprintf("Cannot write data to table '%s', is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY); + throw new SqlException(array($this, sprintf("Cannot write data to table '%s', is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY); } } diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index 557ab085..73e4c23a 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -87,7 +87,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccou $registrationInstance->addElementsToDataSet($dataSetInstance); // "Insert" this request instance completely into the database - $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance); + $this->queryInsertDataSet($dataSetInstance); } /** diff --git a/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php index f0cfb873..054a51b9 100644 --- a/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php @@ -80,7 +80,7 @@ class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookableP $pointsInstance->addElementsToDataSet($dataSetInstance); // "Insert" this request instance completely into the database - $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance); + $this->queryInsertDataSet($dataSetInstance); } /** diff --git a/inc/classes/main/filter/class_BaseFilterDecorator.php b/inc/classes/main/filter/class_BaseFilterDecorator.php index a3a23693..338f0cb0 100644 --- a/inc/classes/main/filter/class_BaseFilterDecorator.php +++ b/inc/classes/main/filter/class_BaseFilterDecorator.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -abstract class BaseFilterDecorator extends BaseFrameworkSystem implements Filterable { +class BaseFilterDecorator extends BaseFrameworkSystem implements Filterable { /** * The decorated filter instance */ diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index e2505df0..0d3f8180 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -79,6 +79,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up // Set the result array $resultInstance->setResultArray($resultArray); + // Set affected rows + $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS])); + // Return the instance return $resultInstance; } @@ -106,7 +109,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up // Now get the update criteria array and update all entries foreach ($updateInstance->getUpdateCriteria() as $criteriaKey => $criteriaValue) { // Update data - $this->resultArray['rows'][$entryKey][$criteriaKey] = $criteriaValue; + $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue; // Mark it as out-dated $this->outDated[$criteriaKey] = 1; @@ -127,7 +130,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up if ($this->valid()) { // Next entry found, so count one up and cache it $this->currentPos++; - $this->currentRow = $this->resultArray['rows'][$this->currentPos]; + $this->currentRow = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos]; $nextValid = true; } // END - if @@ -162,9 +165,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $current = NULL; // Does the current enty exist? - if (isset($this->resultArray['rows'][$this->currentPos])) { + if (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos])) { // Then get it - $current = $this->resultArray['rows'][$this->currentPos]; + $current = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos]; } // END - if // Return the result @@ -181,7 +184,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $isValid = false; // Check if - if (($this->ifStatusIsOkay()) && (isset($this->resultArray['rows'][($this->currentPos + 1)])) && (isset($this->resultArray['rows'][0]))) { + if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][0]))) { // All fine! $isValid = true; } // END - if @@ -196,7 +199,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up * @return $ifStatusOkay Wether the status of the query was okay */ public function ifStatusIsOkay () { - return ((isset($this->resultArray['status'])) && ($this->resultArray['status'] === LocalfileDatabase::RESULT_OKAY)); + return ((isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS] === LocalfileDatabase::RESULT_OKAY)); } /** @@ -226,7 +229,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up * @todo 0% done */ public function searchEntry (LocalSearchCriteria $criteriaInstance) { - die(__METHOD__.": Unfinished!"); + die(__METHOD__.': Unfinished!'); } /** -- 2.30.2