linkchecker.module | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/linkchecker.module b/linkchecker.module index 9a22ee9..71b32c1 100644 --- a/linkchecker.module +++ b/linkchecker.module @@ -2488,3 +2488,64 @@ function _linkchecker_array_values_recursive(array $array) { return $array_values; } + +/** + * Implements hook_requirements(). + */ +function linkchecker_requirements($phase) { + $requirements = array(); + if ($phase == 'runtime') { + $links_all = db_query('SELECT COUNT(1) FROM {linkchecker_link} WHERE status = :status', array(':status' => 1))->fetchField(); + $links_unchecked = db_query('SELECT COUNT(1) FROM {linkchecker_link} WHERE last_checked = :last_checked AND status = :status', array(':last_checked' => 0, ':status' => 1))->fetchField(); + $ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403")); + $query = db_select('linkchecker_link', 'll'); + $query->leftJoin('linkchecker_node', 'ln', 'ln.lid = ll.lid'); + $query->leftJoin('linkchecker_comment', 'lc', 'lc.lid = ll.lid'); + $query->condition('ll.last_checked', 0, '<>'); + $query->condition('ll.status', 1); + $query->condition('ll.code', $ignore_response_codes, 'NOT IN'); + $query->condition(db_or() + ->condition('ln.nid', 'NOT NULL') + ->condition('lc.cid', 'NOT NULL') + ); + $links_broken = $query->countQuery()->execute()->fetchField(); + + $description = ''; + if ($links_all > 0 && $links_broken == 0 && $links_unchecked == 0) { + $msg = format_plural($links_all, + '@count link in the database is checked OK.', + '@count links in the database are checked OK.' + ); + } + else { + $msg = ($links_all > 0) + ? format_plural($links_all, + '@links_broken broken and @links_unchecked unchecked of total @count link in the database.', + '@links_broken broken and @links_unchecked unchecked of total @count links in the database.', + array( + '@links_unchecked' => $links_unchecked, + '@links_broken' => $links_broken, + )) + : t('There are no links in the database.'); + if ($links_unchecked > 0) { + $description .= t('Please be patient until all links have been checked via cron.'); + $description .= ' ' . t('You can run cron manually.', array('@cron' => url('admin/reports/status/run-cron'))); + } + if ($links_broken > 0) { + if (!empty($description)) { + $description .= '
'; + } + $description .= t('See Broken links report.', array('@report' => url('admin/reports/linkchecker'))); + } + } + + $requirements['linkchecker'] = array( + 'value' => $msg, + 'severity' => ($links_broken > 0) ? REQUIREMENT_WARNING : REQUIREMENT_OK, + 'description' => $description, + 'title' => t('Link Checker'), + ); + } + return $requirements; +} +