You are here

function drush_wordpress_migrate_rollback in WordPress Migrate 7

File

./wordpress_migrate.drush.inc, line 78
Drush support for the wordpress_migrate module

Code

function drush_wordpress_migrate_rollback($filename) {
  try {
    $blog = wordpress_migrate_blog($filename);
    $migrations = array_reverse($blog
      ->migrations());
    $incomplete = FALSE;
    foreach ($migrations as $migration) {
      $result = $migration
        ->processRollback();
      if ($result != MigrationBase::RESULT_COMPLETED) {
        $incomplete = TRUE;
        drush_log(dt('!title rollback failed to complete', array(
          '!title' => $blog
            ->getTitle(),
        )));
        break;
      }

      // Remove map/message tables, and migrate_status table entry
      Migration::deregisterMigration($migration
        ->getMachineName());
    }
    if (!$incomplete) {

      // Clear wordpress_migrate table entry
      db_delete('wordpress_migrate')
        ->condition('filename', $filename)
        ->execute();

      // Delete WXR file
      file_unmanaged_delete($filename);

      // Delete photo gallery
      if (module_exists('media_gallery')) {
        $account = user_load($blog
          ->getUid());
        $blog_title = t("@name's blog", array(
          '@name' => format_username($account),
        ));
        $gallery_nid = db_select('node', 'n')
          ->fields('n', array(
          'nid',
        ))
          ->condition('type', 'media_gallery')
          ->condition('title', $blog
          ->getTitle())
          ->execute()
          ->fetchField();
        if ($gallery_nid) {
          node_delete($gallery_nid);
        }
      }
    }
  } catch (Exception $e) {
    drush_log($e, 'error');
  }
}