You are here

function nodeorder_install in Node Order 6

Same name and namespace in other branches
  1. 8 nodeorder.install \nodeorder_install()
  2. 5 nodeorder.install \nodeorder_install()
  3. 7 nodeorder.install \nodeorder_install()

Implementation of hook_install()

Adds field 'weight_in_tid' to core table 'term_node'.

File

./nodeorder.install, line 13
Nodeorder install file.

Code

function nodeorder_install() {
  $module_name = 'nodeorder';

  // Set field properties
  $spec = array(
    'type' => 'int',
    'signed' => TRUE,
    'not null' => TRUE,
    'default' => 0,
    'initial' => 0,
    'description' => t('A user-defined weight for each node in its respective category.'),
  );

  // Create an index for 'weight_in_tid'
  $keys['indexes'] = array(
    'weight_in_tid' => array(
      'weight_in_tid',
    ),
  );

  // Add the column to the table
  $ret = array();
  db_add_field($ret, 'term_node', 'weight_in_tid', $spec, $keys);

  // Check for query errors
  for ($i = 0; $i < count($ret); $i++) {
    if ($ret[$i]['success'] !== TRUE) {
      $installation_failed = TRUE;
      break;
    }
  }
  if ($installation_failed) {
    drupal_set_message(st('Table installation for the %name module was unsuccessful. The tables may need to be installed by hand.  See %name.install file for a list of the installation queries.', array(
      '%name' => $module_name,
    )), 'error');
  }
  else {

    // Set the weight of the nodeorder module in the system table
    // so that we come after most other modules in module_invoke_all()
    // calls.  This ensures that we can alter forms after, for instance,
    // the taxonomy module...
    db_query("UPDATE {system} SET weight = 5 WHERE name = 'nodeorder' AND type = 'module'");
    drupal_set_message(st('The %name module was installed successfully.', array(
      '%name' => $module_name,
    )));
  }
}