You are here

function node_import_update_6000 in Node import 6

Implementation of hook_update_N().

For an update from 5.x to 6.x we need to delete the existing table (node_import_mappings) which is not used any more and does not contain any critical data and create the new database tables. We also need to check the directory path.

File

./node_import.install, line 85
Installs, upgrades or uninstalls the node_import module.

Code

function node_import_update_6000() {
  $result = array();

  // Drop old unneeded table.
  if (db_table_exists('node_import_mappings')) {
    db_drop_table($result, 'node_import_mappings');
  }

  // The recommendation is not to use drupal_install_schema() in
  // hook_update_N() (see: http://drupal.org/node/150220) so we
  // define the schema of 6.x-1.0-rc1 here.
  $schema = array();
  $schema['node_import_tasks'] = array(
    'description' => t('Stores the details of each import task.'),
    'fields' => array(
      'taskid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => '64',
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'has_headers' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'file_options' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'headers' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'map' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'defaults' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'options' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'offset' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'row_done' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'row_error' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'taskid',
    ),
  );
  $schema['node_import_status'] = array(
    'description' => t('Stores status of an imported (or not) row.'),
    'fields' => array(
      'taskid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'offset' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'errors' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'objid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'taskid',
      'offset',
    ),
  );

  // With the schema defined, install all tables.
  foreach ($schema as $name => $table) {
    if (!db_table_exists($name)) {
      db_create_table($result, $name, $table);
    }
  }
  return $result;
}