From e6352b71e923a760d626d6fd32f6223e4c8740fd Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 22 Jul 2014 22:14:07 +0200 Subject: [PATCH] Some fixes. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../database/class_BaseDatabaseWrapper.php | 5 ++- .../databases/class_LocalFileDatabase.php | 12 +++++- .../class_FrameworkDirectoryPointer.php | 40 +++++++++++-------- .../main/result/class_DatabaseResult.php | 9 ++++- 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index da4fa274..733fda69 100644 --- a/inc/classes/main/database/class_BaseDatabaseWrapper.php +++ b/inc/classes/main/database/class_BaseDatabaseWrapper.php @@ -151,16 +151,17 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { // Does this key exists in cache? if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) && ($this->cacheInstance->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1))) { // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey . ':' . print_r($this->cacheInstance->offsetGet($cacheKey), TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey . ':' . print_r($this->cacheInstance->offsetGet($cacheKey), TRUE)); // Then use this result $result = $this->cacheInstance->offsetGet($cacheKey); } else { // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Quering database, cacheKey=' . $cacheKey); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->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); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: result[]=' . gettype($result)); // Cache the result if not null if (!is_null($result)) { diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index 16e6bee0..88183105 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -340,14 +340,19 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackend { * @throws SqlException If an 'SQL error' occurs */ public function querySelect ($tableName, LocalSearchCriteria $searchInstance) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: tableName=' . $tableName . ' - CALLED!'); + // The result is null by any errors $resultData = NULL; // Create full path name $pathName = $this->getConfigInstance()->getConfigEntry('local_db_path') . $tableName . '/'; - // A 'select' query is not that easy on local files, so first try to - // find the 'table' which is in fact a directory on the server + /* + * A 'select' query is not that easy on local files, so first try to + * find the 'table' which is in fact a directory on the server + */ try { // Get a directory pointer instance $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($pathName)); @@ -365,6 +370,9 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackend { // Read the directory with some exceptions while (($dataFile = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',this->getFileExtension()=' . $this->getFileExtension()); + // Does the extension match? if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) { // Skip this file! diff --git a/inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php b/inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php index 7fe69cb8..a267c63f 100644 --- a/inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php +++ b/inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php @@ -116,26 +116,26 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem { /** * Read raw lines of data from a directory pointer and return the data * - * @return $current Current entry from encapsulated iterator + * @return $currentEntry Current entry from encapsulated iterator */ public function readRawDirectory () { // Can the next entry be read? assert($this->getDirectoryInstance()->valid()); // Default is FALSE - $current = FALSE; + $currentEntry = FALSE; // Is it a dot directory? if (!$this->getDirectoryInstance()->isDot()) { // Read data from the directory pointer and return it - $current = $this->getDirectoryInstance()->current(); + $currentEntry = $this->getDirectoryInstance()->current(); } // END - if // Advance to next entry $this->getDirectoryInstance()->next(); // Return found entry - return $current; + return $currentEntry; } /** @@ -152,24 +152,30 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem { return $this->readRawDirectory(); } // END - if + // Init raw line + $rawLine = NULL; + // Read a raw line... - $rawLine = $this->readRawDirectory(); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine); + $currentEntry = $this->readRawDirectory(); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: currentEntry[]=' . gettype($currentEntry)); // Shall we exclude directories? - if ((!is_null($rawLine)) && ($rawLine !== FALSE) && (!in_array($rawLine, $except))) { - // Return read data + if (is_object($currentEntry)) { + // Get file name + $rawLine = $currentEntry->getFilename(); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine); - return $rawLine; - } elseif ((!is_null($rawLine)) && ($rawLine !== FALSE)) { - // Exclude this part - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawline[' . gettype($rawLine) . ']=' . $rawLine . ' - Recursive call!'); - return $this->readDirectoryExcept($except); - } - // End pointer reached - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: Returning NULL!'); - return NULL; + // Is it not excluded? + if (in_array($rawLine, $except)) { + // Exclude this part + $rawLine = $this->readDirectoryExcept($except); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawline[' . gettype($rawLine) . ']=' . $rawLine . ' - Recursive call!'); + } // END - if + } // END - if + + // Return read line + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECTORY[' . __METHOD__ . ':' . __LINE__ . ']: rawLine[' . gettype($rawLine) . ']=' . $rawLine); + return $rawLine; } /** diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index 1d7b9305..4b2c073b 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -183,7 +183,10 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up // By default nothing is valid $isValid = FALSE; - // Check if + // Debug message + //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] this->currentPos=' . $this->currentPos); + + // Check if all is fine ... if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][0]))) { // All fine! $isValid = TRUE; @@ -209,7 +212,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up * @return $ifStatusOkay Whether the status of the query was okay */ public function ifStatusIsOkay () { - return ((isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS] === BaseDatabaseBackend::RESULT_OKAY)); + $ifStatusOkay = ((isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS] === BaseDatabaseBackend::RESULT_OKAY)); + //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] ifStatusOkay=' . intval($ifStatusOkay)); + return $ifStatusOkay; } /** -- 2.39.5