private function __restore($context) { if (Symphony::Configuration()->get('restore', 'dump_db') !== 'yes') { // make sure the user knows what he's doing return; } require_once dirname(__FILE__) . '/lib/class.mysqlrestore.php'; $restore = new MySQLRestore(Symphony::Database()); $mode = NULL; $mode = isset($_POST['action']['restore']['authors']) ? 'authors' : 'data'; if ($mode == NULL) { return; } $filename = $this->generateFilename($mode); $return = $restore->import(file_get_contents(DOCROOT . $this->path . '/' . $filename)); if (FALSE !== $return) { Administration::instance()->Page->pageAlert(__('%s successfully restored from <code>%s/%s</code> in %d queries.', array(__(ucfirst($mode)), $this->path, $filename, $return)), Alert::SUCCESS); Symphony::Configuration()->set('last_sync', date('c'), 'dump_db'); Symphony::Configuration()->write(); } else { Administration::instance()->Page->pageAlert(__('An error occurred while trying to import from <code>%s/%s</code>.', array($this->path, $filename)), Alert::ERROR); } }
public static function restore() { // We should only backup the database when the extension is enabled and version 1.09 of the Dump_DB extension is installed. if((!class_exists('Administration')) || !CdiUtil::isEnabled()) { throw new Exception("You can only restore the Symphony database from the Preferences page"); } if(!CdiUtil::hasDumpDBInstalled()) { throw new Exception('No valid version of <a href="http://symphony-cms.com/download/extensions/view/40986/">Dump DB</a> found. Please make sure it is installed.'); } else { require_once(EXTENSIONS . '/dump_db/lib/class.mysqlrestore.php'); // Prevent the CdiLogQuery::log() from persisting queries that are executed by CDI itself CdiLogQuery::isUpdating(true); // COPIED FROM Dump_DB version 1.09 // Adjust to only support FULL database dump $restore = new MySQLRestore(Symphony::Database()); $filename = CDI_BACKUP_ROOT . '/' . $_POST["ref"]; if(isset($_FILES['dumpdb_restore_file'])) { $filename = self::getFileName('manual'); rename($_FILES['dumpdb_restore_file']['tmp_name'],$filename); } if(file_exists($filename)) { $data = file_get_contents($filename); $data = str_replace('tbl_', Symphony::Configuration()->get('tbl_prefix', 'database'), $data); $restore->import($data); } else { throw new Exception("The provided restore file '" . $filename . "' could not be found."); } // Re-enable CdiLogQuery::log() to persist queries CdiLogQuery::isUpdating(false); } }