Esempio n. 1
0
function snapshot_utility_consume_archive_manifest($manifestFile) {

	$snapshot_manifest = array();
	$manifest_array = file($manifestFile);
	if ($manifest_array) {

		foreach($manifest_array as $file_line) {
			list($key, $value) = explode(':', $file_line, 2);
			$key = trim($key);

			if ($key == "TABLES") {
				if (is_serialized_snapshot($value)) {
					$value = maybe_unserialize_snapshot($value);
				} else {
					$table_values = explode(',', $value);

					foreach($table_values as $idx => $table_name) {
						$table_values[$idx] = trim($table_name);
					}

					$value = $table_values;
				}
			} else if (($key == "TABLES-DATA") || ($key == "ITEM") || ($key == "FILES-DATA")) {
				$value = maybe_unserialize_snapshot($value);
			} else {
				$value = trim($value);
			}

			$snapshot_manifest[$key] = $value;
		}
		//echo "snapshot_manifest<pre>"; print_r($snapshot_manifest); echo "</pre>";

		if (isset($snapshot_manifest['VERSION'])) {
			if (($snapshot_manifest['VERSION'] == "1.0") && (!isset($snapshot_manifest['TABLES-DATA']))) {

				$backupFile = trailingslashit_snapshot($sessionRestoreFolder) . 'snapshot_backups.sql';
				$table_segments = snapshot_utility_get_table_segments_from_single($backupFile);

				if ($table_segments) {
					$snapshot_manifest['TABLES-DATA'] = $table_segments;
					unlink($backupFile);
				}
			}
		}
		return $snapshot_manifest;
	}
}
Esempio n. 2
0
function step_4_show_form($form_errors) {

	?>
	<h2>Processing Step: 4 - Database Import</h2>

	<form action="?step=4" method="post" class="restore_form">
		<?php
			$db_link = mysql_connect($_SESSION['restore_form']['wordpress']['wp-config-db']['DB_HOST'],
				$_SESSION['restore_form']['wordpress']['wp-config-db']['DB_USER'],
				$_SESSION['restore_form']['wordpress']['wp-config-db']['DB_PASSWORD']);

			if (!$db_link) {
				echo "Could not connect to MySQL: ". mysql_error();
				die();
			}

			$db_selected = mysql_select_db($_SESSION['restore_form']['wordpress']['wp-config-db']['DB_NAME'], $db_link);
			if (!$db_selected) {
				echo "Can't select database [". $_SESSION['restore_form']['wordpress']['wp-config-db']['DB_NAME'] ."]: ". mysql_error();
			}
			if ($_SESSION['restore_form']['wordpress']['wp-config-db']['DB_PREFIX'] !== $_SESSION['restore_form']['snapshot']['manifest-data']['PREFIX']) {
				$TABLE_REPLACE_PREFIX_STR = $_SESSION['restore_form']['wordpress']['wp-config-db']['DB_PREFIX'];
			} else {
				$TABLE_REPLACE_PREFIX_STR = '';
			}
			//$TABLE_REPLACE_PREFIX_STR = 'wp_br549_';

			if ((isset($_SESSION['restore_form']['snapshot']['manifest-data']['TABLES']))
			 && (is_array($_SESSION['restore_form']['snapshot']['manifest-data']['TABLES']))
			 && (count($_SESSION['restore_form']['snapshot']['manifest-data']['TABLES']))) {

				foreach($_SESSION['restore_form']['snapshot']['manifest-data']['TABLES'] as $tables_set_idx => $tables_set_data ) {
					if ((is_array($tables_set_data)) && (count($tables_set_data))) {
						foreach($tables_set_data as $table_name) {

							$table_file = trailingslashit_snapshot($_SESSION['restore_form']['snapshot']['extract-path']) . $table_name .".sql";
							if (!file_exists($table_file)) {
								echo "table_file not found [". $table_file ."]<br />";
								continue;
							}

							$table_file_handle = fopen($table_file, "r");
							if (!$table_file_handle) {
								echo "unable to open table_file [". $table_file ."]<br />";
								continue;
							}

							$table_name_new = '';
							$table_name_base = str_replace($_SESSION['restore_form']['snapshot']['manifest-data']['PREFIX'], '', $table_name);
							if (strlen($TABLE_REPLACE_PREFIX_STR)) {
								$table_name_new = $TABLE_REPLACE_PREFIX_STR . $table_name_base;
								echo "Processing database table: ". $table_name ." to ". $table_name_new;
							} else {
								echo "Processing database table: ". $table_name;
							}

							$table_file_create_sql 		= '';
							$table_file_create_done 	= false;
							$table_record_count 		= 0;
							while (($table_file_buffer = fgets($table_file_handle, 4096)) !== false) {

								if (!strlen( trim($table_file_buffer) )) {
									if ( ($table_file_create_done == false) && (strlen($table_file_create_sql)) ) {
										$table_file_create_done = true;
										$sql_split = explode(';', $table_file_create_sql);

										foreach($sql_split as $sql_str) {
											if (strlen($table_name_new)) {
												$sql_str = str_replace('`'. $table_name .'`', '`'.$table_name_new.'`', $sql_str);
											}
											$result = mysql_query($sql_str, $db_link);
										}
									}
								} else {
									if ($table_file_create_done == false) {
										$table_file_create_sql .= $table_file_buffer;
									} else {
										if (strlen($table_name_new)) {
											$table_file_buffer = str_replace('`'. $table_name .'`', '`'.$table_name_new.'`', $table_file_buffer);
										}
										$result = mysql_query($table_file_buffer, $db_link);
										$table_record_count += 1;
									}
								}
							}
							fclose($table_file_handle);
							echo " : total rows: ". $table_record_count ."<br />";

							//echo "table_name_base=[". $table_name_base ."]<br />";
							//echo "table_name_new=[". $table_name_new ."]<br />";
							//echo "table_name=[". $table_name ."]<br />";

							//echo "site_url=[". $_SESSION['restore_form']['wordpress']['site-url'] ."] [". $_SESSION['restore_form']['snapshot']['manifest-data']['SITEURL']."]<br />";
							//echo "home_url=[". $_SESSION['restore_form']['wordpress']['home-url'] ."] [". $_SESSION['restore_form']['snapshot']['manifest-data']['HOME']."]<br />";

							if (($_SESSION['restore_form']['wordpress']['site-url'] != $_SESSION['restore_form']['snapshot']['manifest-data']['SITEURL'])
							 || ($_SESSION['restore_form']['wordpress']['home-url'] != $_SESSION['restore_form']['snapshot']['manifest-data']['HOME'])) {

								if ($table_name_base == "options") {
									if (strlen($table_name_new))
										$table_name_replace = $table_name_new;
									else
										$table_name_replace = $table_name;
									//echo "table_name_replace=[". $table_name_replace ."]<br />";

									search_replace_table_data( $table_name_replace, $db_link,
										$_SESSION['restore_form']['snapshot']['manifest-data']['SITEURL'], $_SESSION['restore_form']['wordpress']['site-url'] );

									//die();
								}
							}
							flush();
						}
					}
				}
			} else {
				echo "Snapshot Archive manifest item 'TABLES' not set. Aborting";
			}
			mysql_close($db_link);
		?>
		<p><input type="submit" value="Finished" /></p>
	</form>
	<?php
}
Esempio n. 3
0
 /**
  * @param $from_dir - Source Directory
  * @param $dest_dir Destination Directory
  * @param bool $move_files (true) will move each file individually. (false) will remove destination sub-directories and move entire source sub-directory
  */
 public static function move_tree($from_dir, $dest_dir, $move_files = false)
 {
     if (!is_dir($from_dir)) {
         echo "Source Directory does not exists [" . $from_dir . "]<br />";
         die;
     }
     if (!is_dir($dest_dir)) {
         echo "Destination Directory does not exists [" . $dest_dir . "]<br />";
         die;
     }
     if ($move_files == true) {
         $from_files = Snapshot_Helper_Utility::scandir($from_dir);
         if (is_array($from_files) && count($from_files)) {
             foreach ($from_files as $from_file_full) {
                 $from_file = str_replace(trailingslashit_snapshot($from_dir), '', $from_file_full);
                 $dest_file_full = self::trailingslashit_snapshot($dest_dir) . $from_file;
                 if (!file_exists(dirname($dest_file_full))) {
                     mkdir(dirname($dest_file_full), 0777, true);
                 }
                 if (file_exists($dest_file_full)) {
                     unlink($dest_file_full);
                 }
                 $rename_ret = rename($from_file_full, $dest_file_full);
                 if ($rename_ret === false) {
                     die;
                 }
             }
         }
     } else {
         if ($from_dh = opendir($from_dir)) {
             while (($from_file = readdir($from_dh)) !== false) {
                 if ($from_file == '.' || $from_file == '..') {
                     continue;
                 }
                 $from_file_full = self::trailingslashit_snapshot($from_dir) . $from_file;
                 $dest_file_full = self::trailingslashit_snapshot($dest_dir) . $from_file;
                 if (file_exists($dest_file_full)) {
                     if (is_dir($dest_file_full)) {
                         Snapshot_Helper_Utility::recursive_rmdir($dest_file_full);
                     } else {
                         unlink($dest_file_full);
                     }
                 }
                 rename($from_file_full, $dest_file_full);
             }
             closedir($from_dh);
         }
     }
 }