You are here

function node_authlink_update_7100 in Node authorize link 7

Implements hook_update_N().

File

./node_authlink.install, line 60
Installation and update of the node_authlink module.

Code

function node_authlink_update_7100(&$sandbox) {

  // Migrate data.
  drupal_install_schema('node_authlink');
  $keys = db_query('SELECT f.field_node_authlink_authkey_value, f.entity_id, n.created
    FROM {field_data_field_node_authlink_authkey} AS f INNER JOIN {node} AS n ON f.entity_id = n.nid
    WHERE f.language = \'und\'');
  foreach ($keys as $key) {
    db_insert('node_authlink_nodes')
      ->fields(array(
      'nid' => $key->entity_id,
      'authkey' => $key->field_node_authlink_authkey_value,
      'created' => $key->created,
    ))
      ->execute();
  }
  unset($keys);

  // Migrate settings.
  $field = field_info_field('field_node_authlink_authkey');
  $instances = field_read_instances(array(
    'field_id' => $field['id'],
    'entity_type' => 'node',
  ));
  $node_types = array();
  foreach ($instances as $instance) {
    $node_types[$instance['bundle']] = $instance['bundle'];
    variable_set('node_authlink_enable_' . $instance['bundle'], TRUE);
    variable_set('node_authlink_grants_' . $instance['bundle'], $instance['node_authlink_grants']);
  }
  variable_set('node_authlink_types', $node_types);

  // Cleanup.
  field_delete_field('field_node_authlink_authkey');
}