You are here

function invoice_update_7000 in Invoice 7

Implements hook_update_N()

File

./invoice.install, line 240

Code

function invoice_update_7000() {
  _invoice_set_content_type_settings();
  $times = array();

  // Convert datetime data type of "created" column to integer
  $result = db_query("SELECT iid, created FROM {invoice_items}")
    ->fetchAll();
  foreach ($result as $row) {
    $time = strtotime($row->created);
    $time = $time > 0 ? $time : 0;
    $times[$row->iid] = $time;
  }
  db_drop_field('invoice_items', 'created');
  db_add_field('invoice_items', 'created', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  foreach ($times as $item_id => $time) {
    db_update('invoice_items')
      ->fields(array(
      'created' => $time,
    ))
      ->condition('iid', $item_id)
      ->execute();
  }
  return t('Successfully updated the invoice module.');
}