/** exdoc * This function restores a database (overwriting all data in * any existing tables) from an EQL object dump. Returns true if * the restore was a success and false if something went horribly wrong * (unable to read file, etc.) Even if true is returned, there is a chance * that some errors were encountered. Check $errors to be sure everything * was fine. * * @param Database $db The database to restore to * @param string $file The filename of the EQL file to restore from * @param array $errors A referenced array that stores errors. Whatever * variable is passed in this argument will contain all errors encountered * during the parse/restore. * @param null $force_version * @return bool * @node Model:expFile */ public static function restoreDatabase($db, $file, &$errors, $force_version = null) { $errors = array(); if (is_readable($file)) { $lines = @file($file); // Sanity check if (count($lines) < 2 || trim($lines[0]) != EQL_HEADER) { $errors[] = gt('Not a valid EQL file'); return false; } if ($force_version == null) { $version = explode(':', trim($lines[1])); $eql_version = $version[1] + 0; } else { $eql_version = $force_version; } $current_version = EXPONENT + 0; $clear_function = ''; $fprefix = ''; // Check version and include necessary converters //FIXME We reject v1.0 eql files if ($eql_version != $current_version) { $errors[] = gt('EQL file was Not a valid EQL version'); return false; // $fprefix = 'expFile::'.implode('',explode('.',$eql_version)).'_'; // if (function_exists($fprefix.'clearedTable')) { // $clear_function = $fprefix.'clearedTable'; // } } // make sure the database tables are up to date administrationController::install_dbtables(); $table = ''; $table_function = ''; for ($i = 2; $i < count($lines); $i++) { $line_number = $i; $line = trim($lines[$i]); if ($line != '') { $pair = explode(':', $line); $pair[1] = implode(':', array_slice($pair, 1)); $pair = array_slice($pair, 0, 2); if ($pair[0] == 'TABLE') { $table = $pair[1]; if ($fprefix != '') { $table_function = $fprefix . $table; } if ($db->tableExists($table)) { $db->delete($table); if ($clear_function != '') { $clear_function($db, $table); } } else { // if (!file_exists(BASE.'framework/core/definitions/'.$table.'.php')) { $errors[] = sprintf(gt('Table "%s" not found in the system (line %d)'), $table, $line_number); // } else if (!is_readable(BASE.'framework/core/definitions/'.$table.'.php')) { // $errors[] = sprintf(gt('Data definition file for %s (%s) is not readable (line %d)'),$table,'framework/core/definitions/'.$table.'.php',$line_number); // } else { // $dd = include(BASE.'framework/core/definitions/'.$table.'.php'); // $info = (is_readable(BASE.'framework/core/definitions/'.$table.'.info.php') ? include(BASE.'framework/core/definitions/'.$table.'.info.php') : array()); // $db->createTable($table,$dd,$info); // } } } else { if ($pair[0] == 'RECORD') { // Here we need to check the conversion scripts. $pair[1] = str_replace('\\r\\n', "\r\n", $pair[1]); $object = unserialize($pair[1]); if (function_exists($table_function)) { $table_function($db, $object); } else { $db->insertObject($object, $table); } } else { $errors[] = sprintf(gt('Invalid specifier type "%s" (line %d)'), $pair[0], $line_number); } } } } if ($eql_version != $current_version) { $errors[] = gt('EQL file was Not a valid EQL version'); return false; } return true; } else { $errors[] = gt('Unable to read EQL file'); return false; } }
# # GPL: http://www.gnu.org/licenses/gpl.txt # ################################################## if (!defined('EXPONENT')) { exit(''); } ?> <h2><?php echo gt('Installing and Upgrading tables'); ?> </h2> <?php global $db; $tables = administrationController::install_dbtables(); ksort($tables); ?> <table cellpadding="2" cellspacing="0" width="100%" border="0" class="exp-skin-table"> <thead> <tr> <th> <?php echo gt('Table Name'); ?> </th> <th> <?php echo gt('Status'); ?>