[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/migrate/ -> migrate.install (source)

   1  <?php
   2  // $Id: migrate.install,v 1.1.2.13 2009/09/18 19:13:05 mikeryan Exp $
   3  
   4  /**
   5   * @file
   6   * Implementation of profile destination handling
   7   */
   8  
   9  /**
  10   * Implementation of hook_schema().
  11   */
  12  function migrate_schema() {
  13    $schema['migrate_content_sets'] = array(
  14      'description' => t('Sets of content mappings'),
  15      'fields' => array(
  16        'mcsid' => array(
  17          'type' => 'serial',
  18          'unsigned' => TRUE,
  19          'not null' => TRUE,
  20        ),
  21        'view_name' => array(
  22          'type' => 'varchar',
  23          'length' => 255,
  24          'not null' => TRUE,
  25        ),
  26        'sourcekey' => array(
  27          'type' => 'varchar',
  28          'length' => 255,
  29          'not null' => FALSE,
  30        ),
  31        'contenttype' => array(
  32          'type' => 'varchar',
  33          'length' => 255,
  34          'not null' => TRUE,
  35          'default' => 'node',
  36        ),
  37        'desttype' => array(
  38          'type' => 'varchar',
  39          'length' => 255,
  40          'not null' => TRUE,
  41        ),
  42        'description' => array(
  43          'type' => 'varchar',
  44          'length' => 255,
  45          'not null' => TRUE,
  46        ),
  47        'clearing' => array(
  48          'type' => 'int',
  49          'size' => 'tiny',
  50          'not null' => TRUE,
  51          'default' => (int)FALSE,
  52        ),
  53        'importing' => array(
  54          'type' => 'int',
  55          'size' => 'tiny',
  56          'not null' => TRUE,
  57          'default' => (int)FALSE,
  58        ),
  59        'scanning' => array(
  60          'type' => 'int',
  61          'size' => 'tiny',
  62          'not null' => TRUE,
  63          'default' => (int)FALSE,
  64        ),
  65        'lastimported' => array(
  66          'type' => 'datetime',
  67          'not null' => FALSE,
  68        ),
  69        'weight' => array(
  70          'type' => 'int',
  71          'unsigned' => FALSE,
  72          'not null' => TRUE,
  73        ),
  74        'rowcount' => array(
  75          'type' => 'int',
  76          'unsigned' => TRUE,
  77          'not null' => TRUE,
  78          'default' => 0,
  79        ),
  80        'semaphore' => array(
  81          'type' => 'int',
  82          'size' => 'tiny',
  83          'not null' => TRUE,
  84          'default' => (int)FALSE,
  85        ),
  86      ),
  87      'primary key' => array('mcsid'),
  88      'unique keys' => array(
  89        'view_name' => array('view_name'),
  90      ),
  91    );
  92    $schema['migrate_content_mappings'] = array(
  93      'description' => t('Content field mappings'),
  94      'fields' => array(
  95        'mcmid' => array(
  96          'type' => 'serial',
  97          'unsigned' => TRUE,
  98          'not null' => TRUE,
  99        ),
 100        'mcsid' => array(
 101          'type' => 'int',
 102          'unsigned' => TRUE,
 103          'not null' => TRUE,
 104        ),
 105        'srcfield' => array(
 106          'type' => 'varchar',
 107          'length' => 255,
 108          'not null' => TRUE,
 109        ),
 110        'destfield' => array(
 111          'type' => 'varchar',
 112          'length' => 255,
 113          'not null' => TRUE,
 114        ),
 115        'default_value' => array(
 116          'type' => 'varchar',
 117          'length' => 255,
 118          'not null' => FALSE,
 119        ),
 120      ),
 121      'primary key' => array('mcmid'),
 122      'unique keys' => array(
 123        'colkey' => array('mcsid', 'destfield'),
 124      ),
 125    );
 126  
 127    return $schema;
 128  }
 129  
 130  /**
 131   * Implementation of hook_install().
 132   */
 133  function migrate_install() {
 134    // Create tables
 135    drupal_install_schema('migrate');
 136  }
 137  
 138  /**
 139   * Implementation of hook_uninstall().
 140   */
 141  function migrate_uninstall() {
 142    // Remove dynamically-created mapping and message tables
 143    $tw_active = module_exists('tw');
 144    $sql = "SELECT mcsid FROM {migrate_content_sets}";
 145    $result = db_query($sql);
 146    while ($row = db_fetch_object($result)) {
 147      $maptablename = 'migrate_map_' . $row->mcsid;
 148      if ($tw_active) {
 149        tw_remove_tables($maptablename);
 150      }
 151      if (db_table_exists($maptablename)) {
 152        $sql = "DROP TABLE $maptablename";
 153        db_query($sql);
 154      }
 155      $msgtablename = 'migrate_msgs_' . $row->mcsid;
 156      if ($tw_active) {
 157        tw_remove_tables($msgtablename);
 158      }
 159      if (db_table_exists($msgtablename)) {
 160        $sql = "DROP TABLE $msgtablename";
 161        db_query($sql);
 162      }
 163    }
 164    drupal_uninstall_schema('migrate');
 165  }
 166  
 167  // Refactoring of map and message tables
 168  function migrate_update_6000() {
 169    $ret = array();
 170  
 171    // Need to make sure schema inspect support is included
 172    schema_init();
 173    // Make view_name unique
 174    db_drop_index($ret, 'migrate_content_sets', 'view_name');
 175    db_add_unique_key($ret, 'migrate_content_sets', 'view_name', array('view_name'));
 176  
 177    $sql = "SELECT * FROM {migrate_content_sets}";
 178    $result = db_query($sql);
 179    while ($row = db_fetch_object($result)) {
 180      // Rename map and message tables
 181      $oldmaptable = $row->view_name . '_' . $row->contenttype . '_map';
 182      if (db_table_exists($oldmaptable)) {
 183        $newmaptable = migrate_map_table_name($row->view_name);
 184        db_rename_table($ret, $oldmaptable, $newmaptable);
 185        $maptableexists = TRUE;
 186      }
 187      else {
 188        $maptableexists = FALSE;
 189      }
 190      $oldmsgtable = $row->view_name . '_' . $row->contenttype . '_msgs';
 191      if (db_table_exists($oldmsgtable)) {
 192        $newmsgtable = migrate_message_table_name($row->view_name);
 193        db_rename_table($ret, $oldmsgtable, $newmsgtable);
 194        $msgtableexists = TRUE;
 195      }
 196      else {
 197        $msgtableexists = FALSE;
 198      }
 199  
 200      if ($maptableexists) {
 201        // Remove mcsid from map table
 202        db_drop_field($ret, $newmaptable, 'mcsid');
 203  
 204        // Rename remaining map table columns
 205        db_drop_primary_key($ret, $newmaptable);
 206        db_drop_unique_key($ret, $newmaptable, 'idkey');
 207        db_change_field($ret, $newmaptable, $row->sourcekey, 'sourceid',
 208          array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
 209          array('primary key' => array('sourceid')));
 210        db_change_field($ret, $newmaptable, $row->contenttype . 'id', 'destid',
 211          array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
 212          array('unique keys' => array('destid' => array('destid'))));
 213  
 214        // Update Table Wizard to reflect the changes
 215        tw_remove_tables($oldmaptable);
 216        tw_add_tables($newmaptable);
 217      }
 218  
 219      if ($msgtableexists) {
 220        tw_remove_tables($oldmsgtable);
 221        tw_add_tables($newmsgtable);
 222      }
 223  
 224      // Save the content set, to make sure the message table is created
 225      migrate_save_content_set($row);
 226    }
 227    return $ret;
 228  }
 229  
 230  /**
 231   * Refactoring of content/destination types
 232   *
 233   */
 234  function migrate_update_6001() {
 235    // Clear desttype, except for nodes
 236    $sql = "UPDATE {migrate_content_sets} SET desttype='' WHERE contenttype <> 'node'";
 237    db_query($sql);
 238    return array();
 239  }
 240  
 241  /**
 242   * The {node} field for the updated timestamp is actually called 'changed'
 243   */
 244  function migrate_update_6002() {
 245    $ret = array();
 246    $sql = "UPDATE {migrate_content_mappings}
 247            SET destfield='changed'
 248            WHERE destfield='updated' AND mcsid IN
 249              (SELECT mcsid FROM {migrate_content_sets} WHERE contenttype='node')";
 250    $ret[] = update_sql($sql);
 251    return $ret;
 252  }
 253  
 254  /**
 255   * Hook names have changed - notify the admin
 256   */
 257  function migrate_update_6003() {
 258    drupal_set_message(t('The Migrate module API has changed - all functions and hooks
 259      containing the word destination have been renamed to remove that word. Any hooks
 260      listed below will need to be renamed - please review your code carefully
 261      to make sure there are no other changes to make.'));
 262    // Tell modules to include their migrate hooks
 263    module_invoke_all('migrate_init');
 264  
 265    foreach (module_implements('migrate_destination_types') as $module) {
 266      drupal_set_message($module . '_migrate_destination_types');
 267    }
 268  
 269    $desttypes = migrate_invoke_all('destination_types');
 270    foreach ($desttypes as $type => $info) {
 271      foreach (module_implements("migrate_destination_fields_$type") as $module) {
 272        drupal_set_message($module . "_migrate_destination_fields_$type");
 273      }
 274      foreach (module_implements("migrate_destination_delete_$type") as $module) {
 275        drupal_set_message($module . "_migrate_destination_delete_$type");
 276      }
 277      foreach (module_implements("migrate_destination_import_$type") as $module) {
 278        drupal_set_message($module . "_migrate_destination_import_$type");
 279      }
 280    }
 281  
 282    foreach (module_implements('migrate_destination_prepare_node') as $module) {
 283      drupal_set_message($module . '_migrate_destination_prepare_node');
 284    }
 285    foreach (module_implements('migrate_destination_prepare_user') as $module) {
 286      drupal_set_message($module . '_migrate_destination_prepare_user');
 287    }
 288    foreach (module_implements('migrate_destination_prepare_role') as $module) {
 289      drupal_set_message($module . '_migrate_destination_prepare_role');
 290    }
 291    foreach (module_implements('migrate_destination_prepare_comment') as $module) {
 292      drupal_set_message($module . '_migrate_destination_prepare_comment');
 293    }
 294    foreach (module_implements('migrate_destination_prepare_term') as $module) {
 295      drupal_set_message($module . '_migrate_destination_prepare_term');
 296    }
 297    foreach (module_implements('migrate_destination_complete_node') as $module) {
 298      drupal_set_message($module . '_migrate_destination_complete_node');
 299    }
 300    foreach (module_implements('migrate_destination_complete_user') as $module) {
 301      drupal_set_message($module . '_migrate_destination_complete_user');
 302    }
 303    foreach (module_implements('migrate_destination_complete_role') as $module) {
 304      drupal_set_message($module . '_migrate_destination_complete_role');
 305    }
 306    foreach (module_implements('migrate_destination_complete_comment') as $module) {
 307      drupal_set_message($module . '_migrate_destination_complete_comment');
 308    }
 309    foreach (module_implements('migrate_destination_complete_term') as $module) {
 310      drupal_set_message($module . '_migrate_destination_complete_term');
 311    }
 312    foreach (module_implements('migrate_destination_xlat_node') as $module) {
 313      drupal_set_message($module . '_migrate_destination_xlat_node');
 314    }
 315    foreach (module_implements('migrate_destination_xlat_user') as $module) {
 316      drupal_set_message($module . '_migrate_destination_xlat_user');
 317    }
 318    foreach (module_implements('migrate_destination_xlat_term') as $module) {
 319      drupal_set_message($module . '_migrate_destination_xlat_term');
 320    }
 321    return array();
 322  }
 323  
 324  // Refactoring of map and message table names
 325  function migrate_update_6004() {
 326    $ret = array();
 327  
 328    // Need to make sure schema inspect support is included
 329    schema_init();
 330    // Make view_name unique
 331  
 332    $sql = "SELECT * FROM {migrate_content_sets}";
 333    $result = db_query($sql);
 334    while ($row = db_fetch_object($result)) {
 335      // Rename map and message tables
 336      $oldmaptable = $row->view_name . '_map';
 337      if (db_table_exists($oldmaptable)) {
 338        $newmaptable = migrate_map_table_name($row->mcsid);
 339        db_rename_table($ret, $oldmaptable, $newmaptable);
 340        // Update Table Wizard to reflect the changes
 341        tw_remove_tables($oldmaptable);
 342        tw_add_tables($newmaptable);
 343      }
 344  
 345      $oldmsgtable = $row->view_name . '_msgs';
 346      if (db_table_exists($oldmsgtable)) {
 347        $newmsgtable = migrate_message_table_name($row->mcsid);
 348        db_rename_table($ret, $oldmsgtable, $newmsgtable);
 349        // Update Table Wizard to reflect the changes
 350        tw_remove_tables($oldmsgtable);
 351        tw_add_tables($newmsgtable);
 352      }
 353    }
 354    return $ret;
 355  }
 356  
 357  // Add semaphore field
 358  function migrate_update_6005() {
 359    $ret = array();
 360    db_add_field($ret, 'migrate_content_sets', 'semaphore',
 361      array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE,
 362            'default' => (int)FALSE));
 363    variable_del('migrate_semaphore');
 364    return $ret;
 365  }
 366  
 367  // Cron processing - set to TRUE on update, so existing installations will not
 368  // be surprised by cron processing stopping. The default value for new installations
 369  // will be FALSE - drush is the preferred mechanism for long migration processes.
 370  function migrate_update_6006() {
 371    variable_set('migrate_enable_cron', TRUE);
 372    return array();
 373  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7