Fixed criteria handling
[core.git] / inc / classes / main / database / databases / class_LocalFileDatabase.php
index f4d855ff5e196faf08645e52e76e376eb1d4f505..2185039b5a814b21fd48beb59837c4bdcc8889eb 100644 (file)
@@ -348,36 +348,41 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
 
                                // Read the file
                                $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray,true));
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray, TRUE));
 
                                // Is this an array?
                                if (is_array($dataArray)) {
+                                       // Default is nothing found
+                                       $isFound = TRUE;
+
                                        // Search in the criteria with FMFW (First Matches, First Wins)
                                        foreach ($dataArray as $key => $value) {
-                                               // Is the criteria met or none set?
-                                               if ($searchInstance->isCriteriaMatching($key, $value)) {
-                                                       // Shall we skip this entry?
-                                                       if ($searchInstance->getSkip() > 0) {
-                                                               // We shall skip some entries
-                                                               if ($skipFound < $searchInstance->getSkip()) {
-                                                                       // Skip this entry
-                                                                       $skipFound++;
-                                                                       break;
-                                                               } // END - if
+                                               // Found one entry?
+                                               $isFound = (($isFound === TRUE) && ($searchInstance->isCriteriaMatching($key, $value)));
+                                       } // END - foreach
+
+                                       // Is all found?
+                                       if ($isFound === TRUE) {
+                                               // Shall we skip this entry?
+                                               if ($searchInstance->getSkip() > 0) {
+                                                       // We shall skip some entries
+                                                       if ($skipFound < $searchInstance->getSkip()) {
+                                                               // Skip this entry
+                                                               $skipFound++;
+                                                               break;
                                                        } // END - if
+                                               } // END - if
 
-                                                       // Set id number
-                                                       $dataArray[$this->getIndexKey()] = $idx;
+                                               // Set id number
+                                               $dataArray[$this->getIndexKey()] = $idx;
 
-                                                       // Entry found!
-                                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: indexKey=' . $this->getIndexKey() . ',idx=' . $idx . ',dataArray=' . print_r($dataArray, true));
-                                                       $resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS][] = $dataArray;
+                                               // Entry found!
+                                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: indexKey=' . $this->getIndexKey() . ',idx=' . $idx . ',dataArray=' . print_r($dataArray, TRUE));
+                                               $resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS][] = $dataArray;
 
-                                                       // Count found entries up
-                                                       $limitFound++;
-                                                       break;
-                                               } // END - if
-                                       } // END - foreach
+                                               // Count found entries up
+                                               $limitFound++;
+                                       } // END - if
                                } else {
                                        // Throw an exception here
                                        throw new SqlException(array($this, sprintf("File &#39;%s&#39; contains invalid data.", $dataFile), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
@@ -476,38 +481,43 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
 
                                // Open this file for reading
                                $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray,true));
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray, TRUE));
 
                                // Is this an array?
                                if (is_array($dataArray)) {
+                                       // Default is nothing found
+                                       $isFound = TRUE;
+
                                        // Search in the criteria with FMFW (First Matches, First Wins)
                                        foreach ($dataArray as $key => $value) {
-                                               // Is the criteria met?
-                                               if ($searchInstance->isCriteriaMatching($key, $value))  {
-                                                       // Shall we skip this entry?
-                                                       if ($searchInstance->getSkip() > 0) {
-                                                               // We shall skip some entries
-                                                               if ($skipFound < $searchInstance->getSkip()) {
-                                                                       // Skip this entry
-                                                                       $skipFound++;
-                                                                       break;
-                                                               } // END - if
+                                               // Found one entry?
+                                               $isFound = (($isFound === TRUE) && ($searchInstance->isCriteriaMatching($key, $value)));
+                                       } // END - foreach
+
+                                       // Is all found?
+                                       if ($isFound === TRUE) {
+                                               // Shall we skip this entry?
+                                               if ($searchInstance->getSkip() > 0) {
+                                                       // We shall skip some entries
+                                                       if ($skipFound < $searchInstance->getSkip()) {
+                                                               // Skip this entry
+                                                               $skipFound++;
+                                                               break;
                                                        } // END - if
+                                               } // END - if
 
-                                                       // Entry found, so update it
-                                                       foreach ($searchArray as $searchKey => $searchValue) {
-                                                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
-                                                               $dataArray[$searchKey] = $searchValue;
-                                                       } // END - foreach
+                                               // Entry found, so update it
+                                               foreach ($searchArray as $searchKey => $searchValue) {
+                                                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
+                                                       $dataArray[$searchKey] = $searchValue;
+                                               } // END - foreach
 
-                                                       // Write the data to a local file
-                                                       $this->writeDataArrayToFqfn($pathName . $dataFile, $dataArray);
+                                               // Write the data to a local file
+                                               $this->writeDataArrayToFqfn($pathName . $dataFile, $dataArray);
 
-                                                       // Count it
-                                                       $limitFound++;
-                                                       break;
-                                               } // END - if
-                                       } // END - foreach
+                                               // Count found entries up
+                                               $limitFound++;
+                                       } // END - if
                                } // END - if
                        } // END - while