View source
<?php
define('LINKCHECKER_MINIMUM_MYSQL', '5.0');
function linkchecker_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {linkchecker_boxes} (\n bid INT unsigned NOT NULL,\n lid INT unsigned NOT NULL,\n PRIMARY KEY (bid, lid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {linkchecker_nodes} (\n nid INT unsigned NOT NULL,\n lid INT unsigned NOT NULL,\n PRIMARY KEY (nid, lid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {linkchecker_comments} (\n cid INT unsigned NOT NULL,\n lid INT unsigned NOT NULL,\n PRIMARY KEY (cid ,lid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("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 INT NOT NULL default '-1',\n error TEXT,\n fail_count INT NOT NULL default '0',\n last_checked INT NOT NULL default '0',\n status INT NOT NULL default '1',\n PRIMARY KEY (lid),\n UNIQUE KEY token (token)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {linkchecker_boxes} (\n bid int_unsigned NOT NULL,\n lid int_unsigned NOT NULL,\n PRIMARY KEY (bid, lid)\n );");
db_query("CREATE TABLE {linkchecker_nodes} (\n nid int_unsigned NOT NULL,\n lid int_unsigned NOT NULL,\n PRIMARY KEY (nid, lid)\n );");
db_query("CREATE TABLE {linkchecker_comments} (\n cid int_unsigned NOT NULL,\n lid int_unsigned NOT NULL,\n PRIMARY KEY (cid, lid)\n );");
db_query("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 status INT NOT NULL default '1',\n PRIMARY KEY (lid),\n UNIQUE (token)\n );");
break;
}
}
function linkchecker_uninstall() {
db_query("DROP TABLE {linkchecker_boxes}");
db_query("DROP TABLE {linkchecker_nodes}");
db_query("DROP TABLE {linkchecker_comments}");
db_query("DROP TABLE {linkchecker_links}");
variable_del('linkchecker_action_status_code_301');
variable_del('linkchecker_action_status_code_404');
variable_del('linkchecker_check_links_interval');
variable_del('linkchecker_check_links_max');
variable_del('linkchecker_check_useragent');
variable_del('linkchecker_cleanup_links_last');
variable_del('linkchecker_disable_link_check_for_urls');
variable_del('linkchecker_extract_from_a');
variable_del('linkchecker_extract_from_audio');
variable_del('linkchecker_extract_from_embed');
variable_del('linkchecker_extract_from_iframe');
variable_del('linkchecker_extract_from_img');
variable_del('linkchecker_extract_from_object');
variable_del('linkchecker_extract_from_source');
variable_del('linkchecker_extract_from_video');
variable_del('linkchecker_filter_blacklist');
variable_del('linkchecker_fqdn_only');
variable_del('linkchecker_ignore_response_codes');
variable_del('linkchecker_scan_blocks');
variable_del('linkchecker_scan_comments');
variable_del('linkchecker_scan_nodetypes');
}
function linkchecker_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'install':
$version = db_version();
if (in_array($GLOBALS['db_type'], array(
'mysql',
'mysqli',
)) && version_compare($version, LINKCHECKER_MINIMUM_MYSQL) < 0) {
$requirements['linkchecker_minimum_mysql'] = array(
'title' => $t('MySQL database'),
'value' => $version,
'severity' => REQUIREMENT_ERROR,
'description' => $t('Your MySQL Server is too old. Link Checker requires at least MySQL %version.', array(
'%version' => LINKCHECKER_MINIMUM_MYSQL,
)),
);
}
break;
}
return $requirements;
}
function linkchecker_check_http_request() {
$result = drupal_http_request(url('', array(
'absolute' => TRUE,
)));
$works = isset($result->code) && $result->code >= 100 && $result->code < 600;
variable_set('drupal_http_request_fails', !$works);
return $works;
}
function linkchecker_update_5200() {
$ret = array();
drupal_load('module', 'linkchecker');
$ret[] = update_sql("DROP TABLE {linkchecker_tasks}");
$ret[] = update_sql("DROP TABLE {linkchecker_results}");
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;
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;
}
$ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_ignore_responses', "200\n304\n401\n403"));
$ignore_response_codes = array_filter($ignore_response_codes, '_linkchecker_isvalid_response_code');
$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),
);
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');
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;
}
function linkchecker_update_5201() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE {linkchecker_comments} (\n cid INT NOT NULL,\n lid INT NOT NULL,\n PRIMARY KEY (cid ,lid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
}
return $ret;
}
function linkchecker_update_5202() {
$ret = array();
variable_del('linkchecker_analyze');
variable_del('linkchecker_clear_analyze');
return $ret;
}
function linkchecker_update_5203() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {linkchecker_links} MODIFY COLUMN `code` INT NOT NULL DEFAULT -1");
break;
}
return $ret;
}
function linkchecker_update_5204() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {linkchecker_links} CHANGE lid `lid` INT unsigned NOT NULL auto_increment");
$ret[] = update_sql("ALTER TABLE {linkchecker_boxes} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {linkchecker_boxes} CHANGE bid `bid` INT unsigned NOT NULL");
$ret[] = update_sql("ALTER TABLE {linkchecker_boxes} CHANGE lid `lid` INT unsigned NOT NULL");
$ret[] = update_sql("ALTER TABLE {linkchecker_boxes} ADD PRIMARY KEY (bid, lid)");
$ret[] = update_sql("ALTER TABLE {linkchecker_comments} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {linkchecker_comments} CHANGE cid `cid` INT unsigned NOT NULL");
$ret[] = update_sql("ALTER TABLE {linkchecker_comments} CHANGE lid `lid` INT unsigned NOT NULL");
$ret[] = update_sql("ALTER TABLE {linkchecker_comments} ADD PRIMARY KEY (cid, lid)");
$ret[] = update_sql("ALTER TABLE {linkchecker_nodes} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {linkchecker_nodes} CHANGE nid `nid` INT unsigned NOT NULL");
$ret[] = update_sql("ALTER TABLE {linkchecker_nodes} CHANGE lid `lid` INT unsigned NOT NULL");
$ret[] = update_sql("ALTER TABLE {linkchecker_nodes} ADD PRIMARY KEY (nid, lid)");
break;
}
return $ret;
}
function linkchecker_update_5205() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {linkchecker_links} MODIFY COLUMN `lid` INTEGER UNSIGNED NOT NULL");
break;
}
return $ret;
}
function linkchecker_update_5206() {
$ret = array();
$ret[] = update_sql("DELETE FROM {linkchecker_nodes} WHERE nid IN (SELECT nid FROM {node} WHERE status = 0)");
$ret[] = update_sql("DELETE FROM {linkchecker_comments} WHERE cid IN (SELECT c.cid FROM {node} n INNER JOIN {comments} c ON c.nid = n.nid WHERE n.status = 0)");
return $ret;
}
function linkchecker_update_5207() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {linkchecker_links} ADD COLUMN `status` INTEGER NOT NULL DEFAULT 1");
return $ret;
}
function linkchecker_update_5208() {
$ret = array();
variable_del('linkchecker_cleanup_links_interval');
return $ret;
}
function linkchecker_update_5209() {
$ret = array();
$res = db_query('SELECT rid, perm FROM {permission}');
$perms = array();
while ($p = db_fetch_object($res)) {
$perm = $p->perm;
$perm = preg_replace('/access linkchecker/', 'access broken links report', $perm);
$perms[$p->rid] = $perm;
}
foreach ($perms as $rid => $renamed_permission) {
db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $renamed_permission, $rid);
$ret[] = array(
'success' => TRUE,
'query' => 'UPDATE {permission} SET perm = ' . check_plain($renamed_permission) . ' WHERE rid = ' . $rid,
);
}
return $ret;
}
function linkchecker_update_5210() {
$ret = array();
$ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_ignore_response_codes', "200\n302\n304\n401\n403"));
if (!in_array('302', $ignore_response_codes)) {
$ignore_response_codes[] = '302';
sort($ignore_response_codes);
variable_set('linkchecker_ignore_response_codes', implode("\n", $ignore_response_codes));
$ret[] = array(
'success' => TRUE,
'query' => 'Added the status code 302 to the list of ignored response codes.',
);
}
else {
$ret[] = array(
'success' => TRUE,
'query' => 'No action taken. The status code 302 was already on the list of ignored response codes.',
);
}
return $ret;
}
function linkchecker_update_5211() {
$ret = array();
variable_del('linkchecker_pathfilter_support');
return $ret;
}
function linkchecker_update_5212() {
$ret = array();
$linkchecker_disable_link_check_for_urls = array_filter(preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_disable_link_check_for_urls', LINKCHECKER_RESERVED_DOCUMENTATION_DOMAINS)));
variable_set('linkchecker_disable_link_check_for_urls', implode("\n", array_unique(array_merge(explode("\n", LINKCHECKER_RESERVED_DOCUMENTATION_DOMAINS), $linkchecker_disable_link_check_for_urls))));
$ret[] = array(
'success' => TRUE,
'query' => 'Added RFC documenation domains back if they have been removed.',
);
return $ret;
}