You are here

node_import.install in Node import 6

Same filename and directory in other branches
  1. 5 node_import.install

Installs, upgrades or uninstalls the node_import module.

File

node_import.install
View source
<?php

/**
 * @file
 * Installs, upgrades or uninstalls the node_import module.
 */

/**
 * Minimum Drupal version Node import will work with.
 *
 * We need Drupal 6.5 or later because we need the patch of
 * http://drupal.org/node/180063 : No way to flush form errors
 * during iterative programatic form submission.
 *
 * Without this patch, we can't do multiple drupal_execute()s
 * in one page request. This is a requirement for validating
 * reliable and for generating previews.
 *
 * This patch was included in Drupal 6.5, see:
 * http://drupal.org/node/318701.
 *
 * @ingroup node_import_constants
 */
define('NODE_IMPORT_MINIMUM_DRUPAL', '6.5');

/**
 * Minimum DateAPI version Node import will work with.
 *
 * To avoid problems with parsing dates, node import uses DateAPI
 * module. This constant defines the minimum version of DateAPI
 * that will work.
 *
 * @ingroup node_import_contants
 */
define('NODE_IMPORT_MINIMUM_DATEAPI', '5.2');

/**
 * Implementation of hook_install().
 */
function node_import_install() {
  drupal_install_schema('node_import');
}

/**
 * Implementation of hook_uninstall().
 */
function node_import_uninstall() {
  drupal_uninstall_schema('node_import');
  variable_del('node_import:ftp:directory');

  // Wrongly named, should be ':directory' only
  variable_del('node_import:directory');
  variable_del('node_import:ftp:enabled');
  variable_del('node_import:ftp:user');
  variable_del('node_import:ftp:extensions');
  variable_del('node_import:fgets:length');
  variable_del('node_import:number_of_samples');
  variable_del('node_import:length_of_samples');
  variable_del('node_import:preview_count');
  variable_del('node_import:set_time_limit');
  variable_del('node_import:cron:unit');
  variable_del('node_import:cron:count');
  variable_del('node_import:multiple_separator');
  variable_del('node_import:hierarchy_separator');
  variable_del('node_import:annoy');
  variable_del('node_import:debug:row_count');
  variable_del('node_import:detect:row_count');
}

/**
 * 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.
 */
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;
}

/**
 * Implementation of hook_update_N().
 *
 * 6.x-1.0-rc3 to 6.x-1.0-rc4:
 * - rebuild menu for admin/content/node_import/%node_import/view.
 */
function node_import_update_6100() {
  $result = array();
  menu_rebuild();
  return $result;
}

/**
 * Implementation of hook_update_N().
 *
 * 6.x-1.0-rc4 to 6.x-1.0-rc5:
 * - rename the offset column to file_offset for pgsql (#384944).
 */
function node_import_update_6101() {
  $result = array();
  db_change_field($result, 'node_import_tasks', 'offset', 'file_offset', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_drop_primary_key($result, 'node_import_status');
  db_change_field($result, 'node_import_status', 'offset', 'file_offset', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'taskid',
      'file_offset',
    ),
  ));
  return $result;
}

/**
 * Implementation of hook_update_N().
 *
 * 6.x-1.0-rc4 to 6.x-1.0-rc5:
 * - rebuild menu for admin/content/node_import/list/files.
 * - rebuild menu for admin/content/node_import/list/tasks.
 */
function node_import_update_6102() {
  $result = array();
  menu_rebuild();
  return $result;
}

/**
 * Implementation of hook_schema().
 */
function node_import_schema() {
  $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,
      ),
      'file_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,
      ),
      'file_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',
      'file_offset',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_requirements().
 */
function node_import_requirements($phase) {
  $requirements = array();
  $t = get_t();

  // Check minimum Drupal version.
  if (($phase == 'install' || $phase == 'runtime') && version_compare(VERSION, NODE_IMPORT_MINIMUM_DRUPAL) < 0) {
    $requirements['node_import:minimum_drupal'] = array(
      'title' => $t('Drupal version'),
      'description' => $t('Node import module requires Drupal %version or later (currently %drupal_version installed).', array(
        '%version' => NODE_IMPORT_MINIMUM_DRUPAL,
        '%drupal_version' => VERSION,
      )),
      'value' => VERSION,
      'severity' => REQUIREMENT_ERROR,
    );
  }

  // Check minimum DateAPI version.
  if ($phase == 'runtime' && variable_get('date_api_version', 0) < NODE_IMPORT_MINIMUM_DATEAPI) {
    $requirements['node_import:minimum_dateapi'] = array(
      'title' => $t('DateAPI version'),
      'description' => $t('Node import module requires DateAPI module %version or later (currently %date_version installed).', array(
        '%version' => NODE_IMPORT_MINIMUM_DATEAPI,
        '%date_version' => variable_get('date_api_version', 0),
      )),
      'value' => variable_get('date_api_version', 0),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  return $requirements;
}

Functions

Namesort descending Description
node_import_install Implementation of hook_install().
node_import_requirements Implementation of hook_requirements().
node_import_schema Implementation of hook_schema().
node_import_uninstall Implementation of hook_uninstall().
node_import_update_6000 Implementation of hook_update_N().
node_import_update_6100 Implementation of hook_update_N().
node_import_update_6101 Implementation of hook_update_N().
node_import_update_6102 Implementation of hook_update_N().

Constants

Namesort descending Description
NODE_IMPORT_MINIMUM_DATEAPI Minimum DateAPI version Node import will work with.
NODE_IMPORT_MINIMUM_DRUPAL Minimum Drupal version Node import will work with.