You are here

function migrate_example_update_7001 in Migrate 7.2

Convert modificationdate datetime field to modificationdatetime int field.

File

migrate_example/migrate_example.install, line 56

Code

function migrate_example_update_7001() {
  $ret = array();
  db_add_field('migrate_example_beer_legacy_urls', 'modificationdatetime', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));
  $result = db_select('migrate_example_beer_legacy_urls', 'ms')
    ->fields('ms', array(
    'machine_name',
    'modificationdate',
  ))
    ->execute();
  foreach ($result as $row) {
    $modificationdatetime = strtotime($row->modificationdate);
    db_update('migrate_example_beer_legacy_urls')
      ->fields(array(
      'modificationdatetime' => $modificationdatetime,
    ))
      ->condition('machine_name', $row->machineName)
      ->execute();
  }
  db_drop_field('migrate_example_beer_legacy_urls', 'modificationdate');
  $ret[] = t('Converted modificationdate datetime field to modificationdatetime int field');
  return $ret;
}