You are here

function node_expire_update_6001 in Node expire 6

Update the database table in order to support more DBMS.

File

./node_expire.install, line 89
Install, uninstall and update the module.

Code

function node_expire_update_6001() {
  $update = array();
  $expire_timefrom = array(
    'none' => 0,
    'onupdate' => 1,
    'date' => 2,
  );
  $nodes = db_query('SELECT expire, expiresec, nid FROM {node_expire}');
  while ($node = db_fetch_array($nodes)) {

    // Convert 'expire' dates to timestamps format, since date features
    // is not standard thru DBMS
    $node['expire'] = $node['expire'];

    // Convert the data from 'expiresec' to a small numbers
    $node['expire_timefrom'] = $expire_timefrom($node['expiresec']);
    $nodes_data[] = $node;
  }

  // Remove the old columns and rename the new ones
  db_drop_field($update, 'node_expire', 'expire');
  db_drop_field($update, 'node_expire', 'expiresec');
  db_add_column($update, 'node_expire', 'expire', 'int', array(
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
  ));
  db_add_column($update, 'node_expire', 'expire_timefrom', 'int', array(
    'size' => 'small',
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
  ));
  db_add_index($update, 'node_expire', 'expire', array(
    'expire',
  ));
  foreach ($nodes_data as $node) {
    $update[] = update_sql('UPDATE {node_expire} SET
      expire = ' . $node['expire'] . ',
      expire_timefrom = ' . $node['expire_timefrom'] . '
      WHERE nid = ' . $node['nid']);
  }

  // Convert all 'expiration_type' variables to 'expiremode'
  if ($defaults = variable_get('node-expire-node-visibility', array())) {
    foreach (array_keys($defaults) as $node) {
      $defaults[$node]['expiremode'] = $defaults[$node]['expiration_type'];
      unset($defaults[$node]['expiration_type']);
    }
    variable_set('node-expire-node-visibility', $defaults);
  }
  return $update;
}