/** * Utility function to migrate previous snapshot items to new data structure and filename format * * @since 1.0.2 * @see * * @param blog_id * @param IS_SUPER_BLOG true is for multisite primary blog ID 1 * * @return none */ function snapshot_migrate_config_proc($blog_id = 0) { // if (is_multisite()) { // if (!$blog_id) return; // // $blog_id = intval($blog_id); // if ($IS_SUPER_BLOG == true) { // // // If this is the Primary Blog and we already have the updated // $config_data = get_blog_option($blog_id, $this->_settings['options_key']); // if ($config_data) // return; // } // // } else { // // // Single WordPress (Not Multisite) // $config_data = get_option($this->_settings['options_key']); // if ($config_data) // return; // } // // // else we need to pull the previous version and convert. // if (is_multisite()) // $config_data = get_blog_option($blog_id, 'snapshot_1.0'); // else // $config_data = get_option( 'snapshot_1.0'); $ret_value = false; $config_data = get_option('snapshot_1.0'); if ($config_data) { foreach ($config_data['items'] as $item_key => $item) { // Need to update filename to reflect new filename formats $backupFile = trailingslashit($this->_settings['backupBaseFolderFull']) . $item['file']; if (file_exists($backupFile)) { $path_filename = pathinfo($item['file'], PATHINFO_FILENAME); if (!$path_filename) { // PHP Not supported. Do it old school $path_filename = substr($item['file'], 0, strlen($item['file']) - 4); } $snapshot_file_parts = explode('-', $path_filename); if (count($snapshot_file_parts) == 3) { // Old style snapshot-yymmdd-hhmms format // Need to convert to snapshot-{blog_id}-yymmdd-hhmmss-{checksum}.zip while (true) { $checksum = Snapshot_Helper_Utility::get_file_checksum($backupFile); $snapshot_new_filename = $snapshot_file_parts[0] . '-' . $item_key . '-' . $snapshot_file_parts[1] . '-' . $snapshot_file_parts[2] . '-' . $checksum . '.zip'; $masterFile = trailingslashit($this->_settings['backupBaseFolderFull']) . $snapshot_new_filename; // File does not exist so break and save file. if (!file_exists($masterFile)) { break; } } rename($backupFile, $masterFile); $item['blog-id'] = $blog_id; $item['interval'] = ''; unset($item['file']); $item_data = array(); $item_data['filename'] = $snapshot_new_filename; $item_data['timestamp'] = $item_key; $item_data['tables'] = $item['tables']; $item['data'] = array(); $item['data'][$item_key] = $item_data; $this->config_data['items'][$item_key] = $item; } } } //echo "config_data<pre>"; print_r($this->config_data); echo "</pre>"; //exit; if (isset($config_data['config']['tables'])) { $this->config_data['config']['tables_last'][$blog_id] = $config_data['config']['tables']; } // Now we want to archive the old style options to get them out of the database. $configFile = trailingslashit($this->_settings['backupBaseFolderFull']) . "_configs"; wp_mkdir_p($configFile); $configFile = trailingslashit($this->_settings['backupBaseFolderFull']) . "_configs/blog_" . $blog_id . ".conf"; $fp = fopen($configFile, 'w'); fwrite($fp, serialize($config_data)); fclose($fp); $ret_value = true; delete_option('snapshot_1.0'); } return $ret_value; }