Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. Quick and dirty script to programatically compare and merge data from two versions of a Drupal 7 site.
  5.  
  6. $databases = array (
  7. 'default' =>
  8. array (
  9. 'default' =>
  10. array (
  11. 'database' => 'database_live',
  12. 'username' => 'root',
  13. 'password' => '',
  14. 'host' => 'localhost',
  15. 'port' => '',
  16. 'driver' => 'mysql',
  17. 'prefix' => '',
  18. ),
  19. ),
  20. 'staging' =>
  21. array (
  22. 'default' =>
  23. array (
  24. 'database' => 'database_staging',
  25. 'username' => 'root',
  26. 'password' => '',
  27. 'host' => 'localhost',
  28. 'port' => '',
  29. 'driver' => 'mysql',
  30. 'prefix' => '',
  31. ),
  32. ),
  33. );
  34.  
  35. */
  36.  
  37.  
  38. define('DRUPAL_ROOT', getcwd());
  39. require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  40. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  41.  
  42. /**
  43. * As we're working on a small site,
  44. * load all nodes from staging into memory for faster comparison
  45. */
  46.  
  47. $staging_nodes = array();
  48. db_set_active('staging');
  49. $query = new EntityFieldQuery();
  50. $result = $query->entityCondition('entity_type', 'node')->execute();
  51. if (!empty($result['node'])) {
  52. $nids = array_keys($result['node']);
  53. $nodes = node_load_multiple($nids, array(), TRUE);
  54. foreach($nodes as $node) {
  55. $staging_nodes[(string) $node->nid] = $node;
  56. }
  57. }
  58.  
  59.  
  60. /**
  61. * Iterate across the nodes on the production site
  62. */
  63. db_set_active();
  64.  
  65. $query = new EntityFieldQuery();
  66. $result = $query->entityCondition('entity_type', 'node')->execute();
  67. if (!empty($result['node'])) {
  68. $nids = array_keys($result['node']);
  69. $nodes = node_load_multiple($nids, array(), TRUE);
  70. foreach($nodes as $node) {
  71. $staging_node = isset($staging_nodes[(string) $node->nid]) ? $staging_nodes[(string) $node->nid] : FALSE;
  72. if ($staging_node) {
  73.  
  74. // Do things if they no longer match
  75. if ($node->changed != $staging_node->changed) {
  76.  
  77.  
  78. }
  79.  
  80. }
  81. }
  82. }
  83.  
  84. echo 'All done';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement