You are here

function linkchecker_update_5200 in Link checker 6.2

Same name and namespace in other branches
  1. 5.2 linkchecker.install \linkchecker_update_5200()

Upgrade module to new D5 schema.

File

./linkchecker.install, line 215
Installation file for Link Checker module.

Code

function linkchecker_update_5200() {
  $ret = array();

  // Module functions are required. Make sure the module is loaded.
  drupal_load('module', 'linkchecker');

  // Remove obsolete tables no longer required.
  db_drop_table($ret, 'linkchecker_tasks');
  db_drop_table($ret, 'linkchecker_results');

  // Create new tables.
  $schema['linkchecker_links'] = array(
    'description' => 'Stores all links.',
    'fields' => array(
      'lid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique link ID.',
      ),
      'token' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => 'The indexable md5 hash of the {linkchecker_links}.url.',
      ),
      'url' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'The full qualified link URL.',
      ),
      'method' => array(
        'type' => 'varchar',
        'length' => 4,
        'default' => 'HEAD',
        'not null' => TRUE,
        'description' => 'The method for checking links (HEAD, GET, POST).',
      ),
      'code' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'HTTP status code from link checking.',
      ),
      'error' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'The error message received from the remote server while doing link checking.',
      ),
      'fail_count' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Fail count of unsuccessful link checks. No flapping detection. (Successful = 0, Unsuccessful = fail_count+1).',
      ),
      'last_checked' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Timestamp of the last link check.',
      ),
    ),
    'primary key' => array(
      'lid',
    ),
    'unique keys' => array(
      'token' => array(
        'token',
      ),
    ),
  );
  $schema['linkchecker_boxes'] = array(
    'description' => 'Stores all link references for boxes.',
    'fields' => array(
      'bid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique {boxes}.bid.',
      ),
      'lid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
      ),
    ),
    'primary key' => array(
      'bid',
      'lid',
    ),
  );
  $schema['linkchecker_nodes'] = array(
    'description' => 'Stores all link references for nodes.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique {node}.nid.',
      ),
      'lid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique {linkchecker_links}.lid.',
      ),
    ),
    'primary key' => array(
      'nid',
      'lid',
    ),
  );

  // Create schema.
  db_create_table($ret, 'linkchecker_links', $schema['linkchecker_links']);
  db_create_table($ret, 'linkchecker_boxes', $schema['linkchecker_boxes']);
  db_create_table($ret, 'linkchecker_nodes', $schema['linkchecker_nodes']);

  // Upgrade settings. Could be less code, but is easier to follow.
  $ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_ignore_responses', "200\n304\n401\n403"));

  // Filter all invalid responds codes and outdated error messages out.
  $ignore_response_codes = array_filter($ignore_response_codes, '_linkchecker_isvalid_response_code');

  // Make sure we have status code 200 and 304 in the ignore list.
  $ignore_response_codes = array_merge(array(
    '200',
    '304',
  ), $ignore_response_codes);
  $ignore_response_codes = array_unique($ignore_response_codes);
  variable_set('linkchecker_ignore_response_codes', implode("\n", $ignore_response_codes));
  $ret[] = array(
    'success' => TRUE,
    'query' => 'Ignored response codes have been upgraded to ' . implode(",", $ignore_response_codes),
  );

  // Remove obsolete settings.
  variable_del('linkchecker_ignore_responses');
  variable_del('linkchecker_rebuild');
  variable_del('linkchecker_maxtime');
  variable_del('linkchecker_socket_timeout');
  variable_del('linkchecker_max_links_per_node');
  variable_del('linkchecker_remove_after');
  variable_del('linkchecker_give_up');
  return $ret;
}