Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Quick and dirty script to programatically compare and merge data from two versions of a Drupal 7 site.
- $databases = array (
- 'default' =>
- array (
- 'default' =>
- array (
- 'database' => 'database_live',
- 'username' => 'root',
- 'password' => '',
- 'host' => 'localhost',
- 'port' => '',
- 'driver' => 'mysql',
- 'prefix' => '',
- ),
- ),
- 'staging' =>
- array (
- 'default' =>
- array (
- 'database' => 'database_staging',
- 'username' => 'root',
- 'password' => '',
- 'host' => 'localhost',
- 'port' => '',
- 'driver' => 'mysql',
- 'prefix' => '',
- ),
- ),
- );
- */
- define('DRUPAL_ROOT', getcwd());
- require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
- drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
- /**
- * As we're working on a small site,
- * load all nodes from staging into memory for faster comparison
- */
- $staging_nodes = array();
- db_set_active('staging');
- $query = new EntityFieldQuery();
- $result = $query->entityCondition('entity_type', 'node')->execute();
- if (!empty($result['node'])) {
- $nids = array_keys($result['node']);
- $nodes = node_load_multiple($nids, array(), TRUE);
- foreach($nodes as $node) {
- $staging_nodes[(string) $node->nid] = $node;
- }
- }
- /**
- * Iterate across the nodes on the production site
- */
- db_set_active();
- $query = new EntityFieldQuery();
- $result = $query->entityCondition('entity_type', 'node')->execute();
- if (!empty($result['node'])) {
- $nids = array_keys($result['node']);
- $nodes = node_load_multiple($nids, array(), TRUE);
- foreach($nodes as $node) {
- $staging_node = isset($staging_nodes[(string) $node->nid]) ? $staging_nodes[(string) $node->nid] : FALSE;
- if ($staging_node) {
- // Do things if they no longer match
- if ($node->changed != $staging_node->changed) {
- }
- }
- }
- }
- echo 'All done';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement