Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #!/usr/bin/env php
  2. <?php
  3.  
  4. $config = "migration/config.xml";
  5.  
  6. $configXml = simplexml_load_file(__DIR__."/../{$config}");
  7.  
  8. $sourceDatabase = (string) $configXml->source->database->attributes()->name;
  9. $sourceHost = (string) $configXml->source->database->attributes()->host;
  10. $sourceDSN = "mysql:host={$sourceHost};dbname={$sourceDatabase}";
  11. $sourceUser = (string) $configXml->source->database->attributes()->user;
  12. $sourcePassword = (string) $configXml->source->database->attributes()->password;
  13. $sourcePDO = new \PDO($sourceDSN, $sourceUser, $sourcePassword);
  14.  
  15.  
  16.  
  17. $destDatabase = (string) $configXml->destination->database->attributes()->name;
  18. $destHost = (string) $configXml->destination->database->attributes()->host;
  19. $destUser = (string) $configXml->destination->database->attributes()->user;
  20. $destPassword = (string) $configXml->destination->database->attributes()->password;
  21. $destDSN = "mysql:host={$configXml->destination->database->attributes()->host};dbname={$configXml->destination->database->attributes()->name}";
  22. $destPDO = new \PDO($sourceDSN, $destUser, $destPassword);
  23.  
  24.  
  25. //Source database adjustments. Only executes after rebuild
  26. $sourceSql = <<<EOF
  27. truncate dataflow_batch_export;
  28. truncate dataflow_batch_import;
  29. truncate log_customer;
  30. truncate log_quote;
  31. truncate log_summary;
  32. truncate log_summary_type;
  33. truncate log_url;
  34. truncate log_url_info;
  35. truncate log_visitor;
  36. truncate log_visitor_info;
  37. truncate log_visitor_online;
  38. truncate report_viewed_product_index;
  39. truncate report_compared_product_index;
  40. truncate report_event;
  41. TRUNCATE index_event;
  42.  
  43. DELETE FROM sales_flat_quote WHERE updated_at < DATE_SUB(Now(),INTERVAL 30 DAY);
  44. DELETE FROM sales_flat_quote_address WHERE quote_id NOT IN (SELECT entity_id FROM `sales_flat_quote`);
  45. DELETE FROM sales_flat_quote_item WHERE quote_id NOT IN (SELECT entity_id FROM `sales_flat_quote`);
  46. DELETE FROM sales_flat_quote_payment WHERE quote_id NOT IN (SELECT entity_id FROM `sales_flat_quote`);
  47.  
  48. EOF;
  49.  
  50.  
  51.  
  52. echo "Rebuilding destination database: ";
  53. $destPDO->exec(<<<EOF
  54. DROP DATABASE {$destDatabase};
  55. CREATE DATABASE {$destDatabase};
  56. EOF
  57. );
  58. passthru(sprintf("mysql -u %s %s {$destDatabase} < babyhome2_2016-08-26.sql", $destUser, $destPassword ? "-p{$destPassword}": ""));
  59.  
  60.  
  61. if(false) {
  62. echo "Rebuilding source database: ";
  63. $sourcePDO->exec(<<<EOF
  64. DROP DATABASE {$sourceDatabase};
  65. CREATE DATABASE {$sourceDatabase};
  66. EOF
  67. );
  68.  
  69. passthru(sprintf("mysql -u %s %s {$sourceDatabase} < babyhome.sql", $sourceUser, $sourcePassword ? "-p{$sourcePassword}" : ""));
  70. $sourcePDO->exec($sourceSql);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement