public static function persistQuery($query) { $line = ''; if(self::$meta_written == FALSE) { $line .= "\n" . CdiUtil::getMetaData(); self::$meta_written = TRUE; } $line .= $query . "\n"; $handle = @fopen(CDI_DB_SYNC_FILE, 'a'); fwrite($handle, $line); fclose($handle); }
/** /** * Backup the current state of the Symphony database * This function can only be called from the Symphony backend, the CDI extension must be enabled and running in Database Synchronisation mode. * @param $mode The mode of backup: 'manual' or 'automatic'. This is used to determine which configuration setting should apply. */ public static function backup($mode) { // 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 import the Database Synchroniser file 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.mysqldump.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 $sql = CdiUtil::getMetaData(); $dump = new MySQLDump(Symphony::Database()); $rows = Symphony::Database()->fetch("SHOW TABLES LIKE 'tbl_%';"); $rows = array_map (create_function ('$x', 'return array_values ($x);'), $rows); $tables = array_map (create_function ('$x', 'return $x[0];'), $rows); // Get DATA from all tables foreach ($tables as $table){ $table = str_replace(Symphony::Configuration()->get('tbl_prefix', 'database'), 'tbl_', $table); $sql .= $dump->export($table, MySQLDump::ALL); $sql = str_replace(Symphony::Configuration()->get('tbl_prefix', 'database'), 'tbl_', $sql); } // Persist SQL data to file if(($mode == 'automatic' && Symphony::Configuration()->get('backup-overwrite', 'cdi') == 'yes') || ($mode == 'manual' && Symphony::Configuration()->get('manual-backup-overwrite', 'cdi') == 'yes')) { self::uninstall(); } $filename = self::getFileName($mode); file_put_contents($filename,$sql); // Re-enable CdiLogQuery::log() to persist queries CdiLogQuery::isUpdating(false); // Return the filename of the backup for automatic restore return $filename; } }