Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env php
- <?php
- $config = "migration/config.xml";
- $configXml = simplexml_load_file(__DIR__."/../{$config}");
- $sourceDatabase = (string) $configXml->source->database->attributes()->name;
- $sourceHost = (string) $configXml->source->database->attributes()->host;
- $sourceDSN = "mysql:host={$sourceHost};dbname={$sourceDatabase}";
- $sourceUser = (string) $configXml->source->database->attributes()->user;
- $sourcePassword = (string) $configXml->source->database->attributes()->password;
- $sourcePDO = new \PDO($sourceDSN, $sourceUser, $sourcePassword);
- $destDatabase = (string) $configXml->destination->database->attributes()->name;
- $destHost = (string) $configXml->destination->database->attributes()->host;
- $destUser = (string) $configXml->destination->database->attributes()->user;
- $destPassword = (string) $configXml->destination->database->attributes()->password;
- $destDSN = "mysql:host={$configXml->destination->database->attributes()->host};dbname={$configXml->destination->database->attributes()->name}";
- $destPDO = new \PDO($sourceDSN, $destUser, $destPassword);
- //Source database adjustments. Only executes after rebuild
- $sourceSql = <<<EOF
- truncate dataflow_batch_export;
- truncate dataflow_batch_import;
- truncate log_customer;
- truncate log_quote;
- truncate log_summary;
- truncate log_summary_type;
- truncate log_url;
- truncate log_url_info;
- truncate log_visitor;
- truncate log_visitor_info;
- truncate log_visitor_online;
- truncate report_viewed_product_index;
- truncate report_compared_product_index;
- truncate report_event;
- TRUNCATE index_event;
- DELETE FROM sales_flat_quote WHERE updated_at < DATE_SUB(Now(),INTERVAL 30 DAY);
- DELETE FROM sales_flat_quote_address WHERE quote_id NOT IN (SELECT entity_id FROM `sales_flat_quote`);
- DELETE FROM sales_flat_quote_item WHERE quote_id NOT IN (SELECT entity_id FROM `sales_flat_quote`);
- DELETE FROM sales_flat_quote_payment WHERE quote_id NOT IN (SELECT entity_id FROM `sales_flat_quote`);
- EOF;
- echo "Rebuilding destination database: ";
- $destPDO->exec(<<<EOF
- DROP DATABASE {$destDatabase};
- CREATE DATABASE {$destDatabase};
- EOF
- );
- passthru(sprintf("mysql -u %s %s {$destDatabase} < babyhome2_2016-08-26.sql", $destUser, $destPassword ? "-p{$destPassword}": ""));
- if(false) {
- echo "Rebuilding source database: ";
- $sourcePDO->exec(<<<EOF
- DROP DATABASE {$sourceDatabase};
- CREATE DATABASE {$sourceDatabase};
- EOF
- );
- passthru(sprintf("mysql -u %s %s {$sourceDatabase} < babyhome.sql", $sourceUser, $sourcePassword ? "-p{$sourcePassword}" : ""));
- $sourcePDO->exec($sourceSql);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement