<?php
// Own namespace
-namespace CoreFramework\Database\Backend\Lfdb;
+namespace Org\Mxchange\CoreFramework\Database\Backend\Lfdb;
// Import framework stuff
-use CoreFramework\Criteria\Criteria;
-use CoreFramework\Criteria\Local\LocalSearchCriteria;
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Database\Backend\BaseDatabaseBackend;
-use CoreFramework\Database\Backend\DatabaseBackend;
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Filesystem\FileNotFoundException;
-use CoreFramework\Generic\FrameworkException;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Criteria\Criteria;
+use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria;
+use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
+use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
+use Org\Mxchange\CoreFramework\Database\Backend\DatabaseBackend;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
+use Org\Mxchange\CoreFramework\Generic\FrameworkException;
+use Org\Mxchange\CoreFramework\Handler\Stream\IoHandler;
+use Org\Mxchange\CoreFramework\Middleware\Compressor\CompressorChannel;
// Import SPL stuff
use \SplFileInfo;
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
*/
private $indexKey = '__idx';
+ /**
+ * The file I/O instance for the template loader
+ */
+ private $fileIoInstance = NULL;
+
+ /**
+ * A Compressor instance
+ */
+ private $compressorChannelInstance = NULL;
+
/**
* The protected constructor. Do never instance from outside! You need to
* set a local file path. The class will then validate it.
$databaseInstance = new CachedLocalFileDatabase();
// Get a new compressor channel instance
- $compressorInstance = ObjectFactory::createObjectByConfiguredName('compressor_channel_class');
+ $compressorChannelInstance = ObjectFactory::createObjectByConfiguredName('compressor_channel_class');
// Set the compressor channel
- $databaseInstance->setCompressorChannel($compressorInstance);
+ $databaseInstance->setCompressorChannelInstance($compressorChannelInstance);
// Get a file IO handler
$fileIoInstance = ObjectFactory::createObjectByConfiguredName('file_io_class');
public final function getIndexKey () {
return $this->indexKey;
}
+ /**
+ * Private getter for file IO instance
+ *
+ * @return $fileIoInstance An instance to the file I/O sub-system
+ */
+ protected final function getFileIoInstance () {
+ return $this->fileIoInstance;
+ }
+
+ /**
+ * Setter for file I/O instance
+ *
+ * @param $fileIoInstance An instance to the file I/O sub-system
+ * @return void
+ */
+ public final function setFileIoInstance (IoHandler $fileIoInstance) {
+ $this->fileIoInstance = $fileIoInstance;
+ }
+
+ /**
+ * Setter for compressor channel
+ *
+ * @param $compressorChannelInstance An instance of a CompressorChannel class
+ * @return void
+ */
+ protected final function setCompressorChannelInstance (CompressorChannel $compressorChannelInstance) {
+ $this->compressorChannelInstance = $compressorChannelInstance;
+ }
+
+ /**
+ * Getter for compressor channel
+ *
+ * @return $compressorChannelInstance An instance of a CompressorChannel class
+ */
+ protected final function getCompressorChannelInstance () {
+ return $this->compressorChannelInstance;
+ }
/**
* Reads a local data file and returns it's contents in an array
* @return $dataArray
*/
private function getDataArrayFromFile (SplFileInfo $infoInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Reading elements from database file ' . $infoInstance . ' ...');
-
// Init compressed data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Reading elements from database file ' . $infoInstance . ' ...');
$compressedData = $this->getFileIoInstance()->loadFileContents($infoInstance);
$compressedData = $compressedData['data'];
// Decompress it
- $serializedData = $this->getCompressorChannel()->getCompressor()->decompressStream($compressedData);
+ $serializedData = $this->getCompressorChannelInstance()->getCompressor()->decompressStream($compressedData);
// Unserialize it
$dataArray = json_decode($serializedData, true);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $infoInstance . '.');
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, true));
-
// Finally return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Read ' . count($dataArray) . ' elements from database file ' . $infoInstance . '.');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: dataArray=' . print_r($dataArray, true));
return $dataArray;
}
* @return void
*/
private function writeDataArrayToFqfn (SplFileInfo $infoInstance, array $dataArray) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file ' . $infoInstance . ' ...');
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, true));
-
// Serialize and compress it
- $compressedData = $this->getCompressorChannel()->getCompressor()->compressStream(json_encode($dataArray));
-
- // Write data
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Writing ' . strlen($compressedData) . ' bytes ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Flushing ' . count($dataArray) . ' elements to database file ' . $infoInstance . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: dataArray=' . print_r($dataArray, true));
+ $compressedData = $this->getCompressorChannelInstance()->getCompressor()->compressStream(json_encode($dataArray));
// Write this data BASE64 encoded to the file
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Writing ' . strlen($compressedData) . ' bytes ...');
$this->getFileIoInstance()->saveStreamToFile($infoInstance, $compressedData, $this);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file completed.');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Flushing ' . count($dataArray) . ' elements to database file completed.');
}
/**
* @param $rowName Name of the row
* @return $infoInstance An instance of a SplFileInfo class
*/
- private function generateFileFromDataSet (Criteria $dataSetInstance, $rowName) {
+ private function generateFileFromDataSet (Criteria $dataSetInstance, string $rowName) {
// Instanciate new file object
- $infoInstance = new SplFileInfo($this->getConfigInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . DIRECTORY_SEPARATOR . $rowName . '.' . $this->getFileExtension());
+ $infoInstance = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . DIRECTORY_SEPARATOR . $rowName . '.' . $this->getFileExtension());
// Return it
return $infoInstance;
*/
private function updatePrimaryKey (StoreableCriteria $dataSetInstance) {
// Get table name from criteria
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: dataSetInstance=%s - CALLED!', $dataSetInstance->__toString()));
$tableName = $dataSetInstance->getTableName();
// Get the information array from lower method
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: tableName=%s', $tableName));
$infoArray = $this->getContentsFromTableInfoFile($dataSetInstance);
// Is the primary key there?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: tableInfo=' . print_r($this->tableInfo, true));
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: tableInfo=' . print_r($this->tableInfo, true));
if (!isset($this->tableInfo[$tableName]['primary'])) {
// Then create the info file
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Creating info table for tableName=%s ...', $tableName));
$this->createTableInfoFile($dataSetInstance);
- } elseif (($this->getConfigInstance()->getConfigEntry('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo[$tableName]['primary'])) {
+ } elseif ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo[$tableName]['primary'])) {
// Set the array element
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Setting primaryKey=%s for tableName=%s ...', $dataSetInstance->getPrimaryKey(), $tableName));
$this->tableInfo[$tableName]['primary'] = $dataSetInstance->getPrimaryKey();
// Update the entry
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Updating info table for tableName=%s ...', $tableName));
$this->updateTableInfoFile($dataSetInstance);
}
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: EXIT!');
}
/**
* @throws UnsupportedCriteriaException If the criteria is unsupported
* @throws SqlException If an 'SQL error' occurs
*/
- public function querySelect ($tableName, LocalSearchCriteria $searchInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: tableName=' . $tableName . ' - CALLED!');
-
+ public function querySelect (string $tableName, LocalSearchCriteria $searchInstance) {
// The result is null by any errors
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: tableName=%s,searchInstance=%s - CALLED!', $tableName, $searchInstance->__toString()));
$resultData = NULL;
// Create full path name
- $pathName = $this->getConfigInstance()->getConfigEntry('local_database_path') . $tableName . DIRECTORY_SEPARATOR;
+ $pathName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . $tableName . DIRECTORY_SEPARATOR;
/*
* A 'select' query is not that easy on local files, so first try to
*/
try {
// Get a directory pointer instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Getting directory_class for pathName=%s ...', $pathName));
$directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($pathName));
// Initialize the result data, this need to be rewritten e.g. if a local file cannot be read
$idx = 1;
// 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__, __LINE__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',this->getFileExtension()=' . $this->getFileExtension());
-
+ while (($fileInfoInstance = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
// Does the extension match?
- if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: fileInfoInstance->extension=%s,this->fileExtension=%s', $fileInfoInstance->getExtension(), $this->getFileExtension()));
+ if ($fileInfoInstance->getExtension() !== $this->getFileExtension()) {
// Skip this file!
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Skipping fileInfoInstance->filename=%s ...', $fileInfoInstance->getFilename()));
+ $directoryInstance->getDirectoryIteratorInstance()->next();
continue;
} // END - if
// Read the file
- $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray, true));
+ $dataArray = $this->getDataArrayFromFile($fileInfoInstance);
// Is this an array?
+ //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.pathname=' . $fileInfoInstance->getPathname() . ',dataArray='.print_r($dataArray, true));
if (is_array($dataArray)) {
// Default is nothing found
$isFound = true;
// Search in the criteria with FMFW (First Matches, First Wins)
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: dataArray()=%d', count($dataArray)));
foreach ($dataArray as $key => $value) {
// Make sure value is not bool
assert(!is_bool($value));
// Found one entry?
$isFound = (($isFound === true) && ($searchInstance->isCriteriaMatching($key, $value)));
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: key=' . $key . ',value=' . $value . ',isFound=' . intval($isFound));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: key=%s,value[%s]=%s,isFound=%s', $key, gettype($value), $value, intval($isFound)));
} // END - foreach
// Is all found?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: isFound=' . intval($isFound) . ',limitFound=' . $limitFound . ',limit=' . $searchInstance->getLimit());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: isFound=%d,limitFound=%d,limit=%d', intval($isFound), $limitFound, $searchInstance->getLimit()));
if ($isFound === true) {
// Shall we skip this entry?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: searchInstance->skip=%d', $searchInstance->getSkip()));
if ($searchInstance->getSkip() > 0) {
// We shall skip some entries
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: skipFound=%s', $skipFound));
if ($skipFound < $searchInstance->getSkip()) {
// Skip this entry
$skipFound++;
} // END - if
// Set id number
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Setting dataArray[%s]=%d', $this->getIndexKey(), $idx));
$dataArray[$this->getIndexKey()] = $idx;
// Entry found!
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: indexKey=' . $this->getIndexKey() . ',idx=' . $idx . ',dataArray=' . print_r($dataArray, true));
array_push($resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS], $dataArray);
// Count found entries up
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: resultData[%s]()=%d', BaseDatabaseBackend::RESULT_INDEX_ROWS, count($resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS])));
$limitFound++;
} // END - if
} else {
// Throw an exception here
- throw new SqlException(array($this, sprintf('File '%s' contains invalid data.', $dataFile), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
+ throw new SqlException(array($this, sprintf('File '%s' contains invalid data.', $fileInfoInstance->getPathname()), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
}
// Count entry up
$idx++;
+
+ // Advance to next entry
+ $directoryInstance->getDirectoryIteratorInstance()->next();
} // END - while
// Close directory and throw the instance away
*/
public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
// Try to save the request away
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: dataSetInstance=%s - CALLED!', $dataSetInstance->__toString()));
try {
// Create full path name
$infoInstance = $this->generateFileFromDataSet($dataSetInstance, md5($dataSetInstance->getUniqueValue()));
$this->setLastException($e);
// 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
+ );
}
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: EXIT!');
}
/**
* "Updates" a data set instance with a database layer
*
- * @param $dataSetInstance A storeable data set
+ * @param $dataSetInstance An instance of a StorableCriteria class
* @return void
* @throws SqlException If an SQL error occurs
*/
public function queryUpdateDataSet (StoreableCriteria $dataSetInstance) {
// Create full path name
- $pathName = $this->getConfigInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . DIRECTORY_SEPARATOR;
+ $pathName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . DIRECTORY_SEPARATOR;
// Try all the requests
try {
$searchInstance = $dataSetInstance->getSearchInstance();
// Read the directory with some exceptions
- while (($dataFile = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
+ while (($fileInfoInstance = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
// Does the extension match?
- if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance->extension=' . $fileInfoInstance->getExtension() . ',this->getFileExtension()=' . $this->getFileExtension());
+ if ($fileInfoInstance->getExtension() !== $this->getFileExtension()) {
// Skip this file!
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.extension=' . $fileInfoInstance->getExtension() . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
+ $directoryInstance->getDirectoryIteratorInstance()->next();
continue;
} // END - if
// Open this file for reading
- $dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray, true));
+ $dataArray = $this->getDataArrayFromFile($fileInfoInstance);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.pathname=' . $fileInfoInstance->getPathname() . ',dataArray='.print_r($dataArray, true));
// Is this an array?
if (is_array($dataArray)) {
} // END - foreach
// Is all found?
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: isFound=' . intval($isFound));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: isFound=' . intval($isFound));
if ($isFound === true) {
// Shall we skip this entry?
if ($searchInstance->getSkip() > 0) {
// We shall skip some entries
if ($skipFound < $searchInstance->getSkip()) {
// Skip this entry
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Found entry, but skipping ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Found entry, but skipping ...');
$skipFound++;
break;
} // END - if
assert($searchKey != $this->indexKey);
// Debug message + add/update it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
$dataArray[$searchKey] = $searchValue;
} // END - foreach
// Write the data to a local file
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: Writing dataArray()=' . count($dataArray) . ' to ' . $dataFile . ' ...');
- $this->writeDataArrayToFqfn($pathName . $dataFile, $dataArray);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Writing dataArray()=' . count($dataArray) . ' to ' . $fileInfoInstance->getPathname() . ' ...');
+ $this->writeDataArrayToFqfn($fileInfoInstance, $dataArray);
// Count found entries up
$limitFound++;
} // END - if
} // END - if
+
+ // Advance to next entry
+ $directoryInstance->getDirectoryIteratorInstance()->next();
} // END - while
// Close the file pointer
*
* @param $tableName Name of the table we need the primary key from
* @return $primaryKey Primary key column of the given table
+ * @todo Rename method to getPrimaryKeyFromTableInfo()
*/
- public function getPrimaryKeyOfTable ($tableName) {
+ public function getPrimaryKeyOfTable (string $tableName) {
// Default key is null
$primaryKey = NULL;
unset($data[$this->indexKey]);
// Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: data[' . gettype($data) . ']='.print_r($data, true));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: data[' . gettype($data) . ']='.print_r($data, true));
return $data;
}
* @param $tableName Table name
* @return $count Total rows of given table
*/
- public function countTotalRows($tableName) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: tableName=' . $tableName . ' - CALLED!');
+ public function countTotalRows (string $tableName) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: tableName=' . $tableName . ' - CALLED!');
// Create full path name
- $pathName = $this->getConfigInstance()->getConfigEntry('local_database_path') . $tableName . DIRECTORY_SEPARATOR;
+ $pathName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . $tableName . DIRECTORY_SEPARATOR;
// Try all the requests
try {
$count = 0;
// Read the directory with some exceptions
- while ($dataFile = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) {
+ while ($fileInfoInstance = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) {
// Does the extension match?
- if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance->extension=' . $fileInfoInstance->getExtension() . ',this->getFileExtension()=' . $this->getFileExtension());
+ if ($fileInfoInstance->getExtension() !== $this->getFileExtension()) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.extension=' . $fileInfoInstance->getExtension() . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
// Skip this file!
continue;
} // END - if
// Count this row up
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',getFileExtension()=' . $this->getFileExtension() . ' - COUNTED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.pathname=' . $fileInfoInstance->getPathname() . ',getFileExtension()=' . $this->getFileExtension() . ' - COUNTED!');
$count++;
} // END - while
} catch (FrameworkException $e) {
}
// Return count
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: tableName=' . $tableName . ',count=' . $count . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: tableName=' . $tableName . ',count=' . $count . ' - EXIT!');
return $count;
}