Example #1
0
 /** exdoc
  * This function takes a database object and dumps
  * all of the records in all of the tables into a string.
  * The contents of the string are suitable for storage
  * in a file or other permanent mechanism, and is in
  * the EQL format naively handled by the current
  * implementation.
  *
  * @param Database $db The database object to dump to EQL.
  * @param null $tables
  * @param null $force_version
  * @return string
  * @node Model:expFile
  */
 public static function dumpDatabase($db, $tables = null, $force_version = null)
 {
     $dump = EQL_HEADER . "\r\n";
     if ($force_version == null) {
         $dump .= 'VERSION:' . EXPONENT . "\r\n\r\n";
     } else {
         $dump .= 'VERSION:' . $force_version . "\r\n\r\n";
     }
     if (!is_array($tables)) {
         $tables = $db->getTables();
         if (!function_exists('tmp_removePrefix')) {
             function tmp_removePrefix($tbl)
             {
                 return substr($tbl, strlen(DB_TABLE_PREFIX) + 1);
                 // we add 1, because DB_TABLE_PREFIX  no longer has the trailing
                 // '_' character - that is automatically added by the database class.
             }
         }
         $tables = array_map('tmp_removePrefix', $tables);
     }
     usort($tables, 'strnatcmp');
     foreach ($tables as $table) {
         $dump .= 'TABLE:' . $table . "\r\n";
         foreach ($db->selectObjects($table) as $obj) {
             $dump .= 'RECORD:' . str_replace(array("\r", "\n"), array('\\r', '\\n'), serialize($obj)) . "\r\n";
         }
         $dump .= "\r\n";
     }
     return $dump;
 }