You are here

nodewords.install in Nodewords: D6 Meta Tags 6.3

Same filename and directory in other branches
  1. 5 nodewords.install
  2. 6 nodewords.install
  3. 6.2 nodewords.install

Install, update and uninstall functions for the Nodewords module.

File

nodewords.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Nodewords module.
 */

/**
 * Implements hook_requirements().
 */
function nodewords_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    drupal_load('module', 'nodewords');
    if (!count(nodewords_get_possible_tags())) {
      if (!count(module_implements('metatags_info'))) {
        $requirements['nodewords'] = array(
          'title' => t('Nodewords'),
          'description' => t('There are no modules that implement meta tags.'),
          'severity' => REQUIREMENT_ERROR,
          'value' => t('Enable at least a module listed under the category <em>Meta tags</em> in <a href="@modules-page">modules page</a>.', array(
            '@modules-page' => url('admin/build/modules'),
          )),
        );
      }
      else {
        $requirements['nodewords'] = array(
          'title' => t('Nodewords'),
          'description' => t('There are no modules that support the current version version.'),
          'severity' => REQUIREMENT_ERROR,
          'value' => t('There should be at least one module that supports the current version version. Verify you correctly copied the files in the server.'),
        );
      }
    }
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function nodewords_schema() {
  $schema = array();
  $schema['nodewords'] = array(
    'description' => 'The table containing the meta tag values for all the pages.',
    'fields' => array(
      'mtid' => array(
        'description' => 'The primary key.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The type of object to which the meta tag refers (node, user, page, etc...).',
        'type' => 'int',
        'size' => 'small',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'id' => array(
        'description' => 'The object ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'sid' => array(
        'description' => 'The secondary ID (i.e., the node revision ID).',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'name' => array(
        'description' => 'The meta tag name.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'content' => array(
        'description' => 'The content of the meta tag.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'language' => array(
        'description' => 'The language of this meta tag.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'indexes' => array(
      'nodewords_lang' => array(
        array(
          'language',
          6,
        ),
      ),
      'nodewords_name' => array(
        array(
          'name',
          6,
        ),
      ),
      'nodewords_type_id' => array(
        'type',
        'id',
      ),
      'nodewords_sid' => array(
        'sid',
      ),
    ),
    'unique keys' => array(
      'nodewords_type_ids_name_lang' => array(
        'type',
        'id',
        'sid',
        'name',
        'language',
      ),
    ),
    'primary key' => array(
      'mtid',
    ),
  );
  $schema['nodewords_custom'] = array(
    'description' => 'The table containing data for custom pages.',
    'fields' => array(
      'pid' => array(
        'description' => 'The primary key.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The page name as shown in the list of custom pages.',
        'type' => 'varchar',
        'length' => 60,
        'not null' => TRUE,
        'default' => '',
      ),
      'path' => array(
        'description' => 'The page path.',
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE,
        'default' => '',
      ),
      'weight' => array(
        'description' => 'The weight of the page.',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
      'enabled' => array(
        'description' => 'A flag set when the page is enabled.',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function nodewords_install() {
  drupal_install_schema('nodewords');
  db_query("UPDATE {system} SET weight = 10 WHERE name = 'nodewords' AND type = 'module'");
  drupal_set_message(t('The module nodewords.module has been installed. Now you can <a href="@settings-page">configure it</a>, after you enabled at least one module implementing meta tags.', array(
    '@settings-page' => url('admin/content/nodewords'),
  )));
}

/**
 * Implements hook_update_N().
 */
function nodewords_update_6300() {
  drupal_load('module', 'nodewords');
  $ret = array();
  $types = array(
    'default' => NODEWORDS_TYPE_DEFAULT,
    'errorpage' => NODEWORDS_TYPE_ERRORPAGE,
    'frontpage' => NODEWORDS_TYPE_FRONTPAGE,
    'pager' => NODEWORDS_TYPE_PAGER,
    'node' => NODEWORDS_TYPE_NODE,
    'term' => NODEWORDS_TYPE_TERM,
    'tracker' => NODEWORDS_TYPE_TRACKER,
    'user' => NODEWORDS_TYPE_USER,
    'vocabulary' => NODEWORDS_TYPE_VOCABULARY,
  );
  if (variable_get('nodewords_update', 0) >= 6176) {
    db_add_field($ret, 'nodewords', 'sid', array(
      'description' => 'The secondary ID (i.e., the node revision ID).',
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ));
  }
  else {
    $ret['#abort'] = array(
      'success' => FALSE,
      'query' => 'Updating to version 6.x-3 is possible only from version 6.x-1.12-beta6 or later',
    );
  }
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function nodewords_update_6301() {
  $ret = array();
  if (!db_column_exists('nodewords', 'language')) {
    db_add_field($ret, 'nodewords', 'language', array(
      'type' => 'varchar',
      'length' => 12,
      'not null' => TRUE,
      'default' => '',
    ));
    db_add_index($ret, 'nodewords', 'nodewords_lang', array(
      array(
        'language',
        6,
      ),
    ));
  }
  db_drop_unique_key($ret, 'nodewords', 'nodewords_type_id_name');
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function nodewords_update_6302() {
  $ret = array();
  db_add_unique_key($ret, 'nodewords', 'nodewords_type_ids_name_lang', array(
    'type',
    'id',
    'sid',
    'name',
    'language',
  ));
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function nodewords_update_6303() {
  $ret = array();
  drupal_load('module', 'nodewords');
  $ret[] = update_sql("UPDATE {nodewords} nw SET nw.sid = (SELECT n.vid FROM {node} n WHERE n.nid = nw.id) WHERE type = " . NODEWORDS_TYPE_NODE);
  return $ret;
}

/**
 * Implements hook_update_N().
 */
function nodewords_update_6304() {
  $ret = array();
  menu_rebuild();
  $ret[] = array(
    'success' => TRUE,
    'query' => 'Rebuilt the module menu',
  );
  return $ret;
}

/**
 * Implements hook_uninstall().
 */
function nodewords_uninstall() {
  drupal_uninstall_schema('nodewords');
  variable_del('nodewords_base_url');
  variable_del('nodewords_global');
  variable_del('nodewords_head');
  variable_del('nodewords_icra_validation_content');
  variable_del('nodewords_list_repeat');
  variable_del('nodewords_max_size');
  variable_del('nodewords_update');
}