Continued with file i/o:
[core.git] / inc / classes / main / database / databases / class_LocalFileDatabase.php
index 1bb31f4d0db823470b86d81e446f550d81192740..16e6bee0047b3c1e01de9a23b6b5ab3be1c444aa 100644 (file)
@@ -8,11 +8,11 @@
  *
  * A configurable 'file_io_class' is being used as "storage backend".
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendInterface {
+class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackend {
        /**
         * The file's extension
         */
@@ -206,7 +206,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Writing ' . strlen($compressedData) . ' bytes ...');
 
                // Write this data BASE64 encoded to the file
-               $this->getFileIoInstance()->saveFile($fqfn, $compressedData, $this);
+               $this->getFileIoInstance()->saveStreamToFile($fqfn, $compressedData, $this);
 
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Flushing ' . count($dataArray) . ' elements to database file completed.');
@@ -350,7 +350,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                // find the 'table' which is in fact a directory on the server
                try {
                        // Get a directory pointer instance
-                       $directoryInstance = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($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
                        $resultData = array(
@@ -364,7 +364,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                        $idx = 1;
 
                        // Read the directory with some exceptions
-                       while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
+                       while (($dataFile = $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()) {
                                        // Skip this file!
@@ -415,7 +415,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                                        } // 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);
+                                       throw new SqlException(array($this, sprintf('File &#39;%s&#39; contains invalid data.', $dataFile), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
                                }
 
                                // Count entry up
@@ -433,7 +433,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                        $this->setLastException($e);
 
                        // So throw an SqlException here with faked error message
-                       throw new SqlException (array($this, sprintf("Table &#39;%s&#39; not found", $tableName), self::DB_CODE_TABLE_MISSING), self::EXCEPTION_SQL_QUERY);
+                       throw new SqlException (array($this, sprintf('Table &#39;%s&#39; 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->setLastException($e);
@@ -469,7 +469,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                        $this->setLastException($e);
 
                        // Throw an SQL exception
-                       throw new SqlException(array($this, sprintf("Cannot write data to table &#39;%s&#39;, 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 &#39;%s&#39;, is the table created?', $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
                }
        }
 
@@ -487,7 +487,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                // Try all the requests
                try {
                        // Get a file pointer instance
-                       $directoryInstance = FrameworkDirectoryPointer::createFrameworkDirectoryPointer($pathName);
+                       $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($pathName));
 
                        // Initialize limit/skip
                        $limitFound = 0;
@@ -500,7 +500,7 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                        $searchInstance = $dataSetInstance->getSearchInstance();
 
                        // Read the directory with some exceptions
-                       while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && (($limitFound < $searchInstance->getLimit()) || ($searchInstance->getLimit() == 0))) {
+                       while (($dataFile = $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
@@ -596,6 +596,22 @@ class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendIn
                // Return the column
                return $primaryKey;
        }
+
+       /**
+        * Removes non-public data from given array.
+        *
+        * @param       $data   An array with possible non-public data that needs to be removed.
+        * @return      $data   A cleaned up array with only public data.
+        * @todo        Add more generic non-public data for removal
+        */
+       public function removeNonPublicDataFromArray (array $data) {
+               // Remove '__idx'
+               unset($data[$this->indexKey]);
+
+               // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: data[' . gettype($data) . ']='.print_r($data, TRUE));
+               return $data;
+       }
 }
 
 // [EOF]