You are here

function linkchecker_update_5200 in Link checker 5.2

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

Upgrade module to new schema.

File

./linkchecker.install, line 176
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.
  $ret[] = update_sql("DROP TABLE {linkchecker_tasks}");
  $ret[] = update_sql("DROP TABLE {linkchecker_results}");

  // Create new tables.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {linkchecker_boxes} (\n        bid INT NOT NULL,\n        lid INT NOT NULL,\n        PRIMARY KEY (bid, lid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $ret[] = update_sql("CREATE TABLE {linkchecker_nodes} (\n        nid INT NOT NULL,\n        lid INT NOT NULL,\n        PRIMARY KEY (nid, lid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $ret[] = update_sql("CREATE TABLE {linkchecker_links} (\n        lid INT NOT NULL auto_increment,\n        token VARCHAR(32) NOT NULL,\n        url TEXT NOT NULL,\n        method varchar(4) NOT NULL default 'HEAD',\n        code INT NOT NULL default '0',\n        error TEXT,\n        fail_count INT NOT NULL default '0',\n        last_checked INT NOT NULL default '0',\n        PRIMARY KEY (lid),\n        UNIQUE KEY token (token)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;

    // Install PgSQL tables with update_5204 level! PgSQL was broken in
    // all older versions so we can expect nobody have used it. This allows not
    // to reinvent the complete upgrade process with all steps. Fully untested!
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {linkchecker_boxes} (\n        bid int_unsigned NOT NULL,\n        lid int_unsigned NOT NULL,\n        PRIMARY KEY (bid, lid)\n      );");
      $ret[] = update_sql("CREATE TABLE {linkchecker_nodes} (\n        nid int_unsigned NOT NULL,\n        lid int_unsigned NOT NULL,\n        PRIMARY KEY (nid, lid)\n      );");
      $ret[] = update_sql("CREATE TABLE {linkchecker_comments} (\n        cid int_unsigned NOT NULL,\n        lid int_unsigned NOT NULL,\n        PRIMARY KEY (cid, lid)\n      );");
      $ret[] = update_sql("CREATE TABLE {linkchecker_links} (\n        lid int_unsigned NOT NULL,\n        token VARCHAR(32) NOT NULL,\n        url TEXT NOT NULL,\n        method VARCHAR(4) NOT NULL default 'HEAD',\n        code INTEGER NOT NULL default '-1',\n        error TEXT,\n        fail_count INTEGER NOT NULL default '0',\n        last_checked INTEGER NOT NULL default '0',\n        PRIMARY KEY (lid),\n        UNIQUE (token)\n      );");
      break;
  }

  // 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');

  // D5 required job_queue.module. We need to make sure both is active.
  if (!module_exists('job_queue')) {
    module_disable(array(
      'linkchecker',
    ));
    drupal_set_message('The required job_queue module is missing. The linkchecker module has been disabled. Install job_queue module and re-enable linkchecker, please.', 'error');
  }
  return $ret;
}