Skip to content
Snippets Groups Projects
Commit 4196af8b authored by Tom Blanchard's avatar Tom Blanchard Committed by Carsten Logemann
Browse files

Issue #3104574 by Tomefa: Remove unused code that comes from the drupal7 version in module

parent 79623730
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\linkchecker\LinkCheckerLinkInterface;
/**
......@@ -107,146 +106,6 @@ function linkchecker_watchdog_log($type, $message, $variables = [], $severity =
}
}
/**
* Run perodically via cron and delete all links without a references.
*
* For speed reasons and check results we keep the links for some time
* as they may be reused by other new content.
*/
function _linkchecker_cleanup_links() {
// Remove disabled node types no longer in use.
$node_types = linkchecker_scan_node_types();
if (!empty($node_types)) {
$subquery1 = \Drupal::database()->select('node', 'n')
->fields('n', ['nid'])
->condition('n.type', $node_types, 'NOT IN');
\Drupal::database()->delete('linkchecker_node')
->condition('nid', $subquery1, 'IN')
->execute();
// @todo Remove comments link references from table.
// db_query('DELETE FROM {linkchecker_comment} WHERE cid IN (SELECT nid FROM {node} n WHERE n.type NOT IN (' . db_placeholders($node_types, 'varchar') . '))', $node_types);
}
else {
// No active node_type. Remove all items from table.
\Drupal::database()->truncate('linkchecker_node')->execute();
// @todo Remove comments link references from table.
}
// Remove comment link references if comment scanning is disabled.
// @todo Remove comments of unpublished nodes.
$comment_types = linkchecker_scan_comment_types();
if (empty($comment_types)) {
\Drupal::database()->truncate('linkchecker_comment')->execute();
}
// Remove block link references if block scanning is disabled.
if (\Drupal::config('linkchecker.settings')->get('scan_blocks') == FALSE) {
\Drupal::database()->truncate('linkchecker_block_custom')->execute();
}
// Remove dead links without references.
$linkchecker_node = \Drupal::database()->select('linkchecker_node', 'ln')
->distinct()
->fields('ln', ['lid']);
$linkchecker_comment = \Drupal::database()->select('linkchecker_comment', 'lc')
->distinct()
->fields('lc', ['lid']);
$linkchecker_block_custom = \Drupal::database()->select('linkchecker_block_custom', 'lb')
->distinct()
->fields('lb', ['lid']);
// UNION all linkchecker type tables.
$subquery2 = \Drupal::database()->select($linkchecker_block_custom->union($linkchecker_comment)->union($linkchecker_node), 'q1')
->distinct()
->fields('q1', ['lid']);
\Drupal::database()->delete('linkchecker_link')
->condition('lid', $subquery2, 'NOT IN')
->execute();
}
/**
* Customized clone of core check_markup() with additional filter blacklist.
*
* See https://api.drupal.org/api/function/check_markup/7 for API documentation.
*/
function _linkchecker_check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE) {
if (!isset($text)) {
return '';
}
if (!isset($format_id)) {
$format_id = filter_fallback_format();
}
// If the requested text format does not exist, the text cannot be filtered.
/** @var \Drupal\filter\Entity\FilterFormat $format **/
$format = FilterFormat::load($format_id);
if (!$format) {
linkchecker_watchdog_log('filter', 'Missing text format: %format.', ['%format' => $format_id], RfcLogLevel::ALERT);
return '';
}
// Check for a cached version of this piece of text.
$cache = $cache && !empty($format->cache);
$cache_id = '';
if ($cache) {
$cache_id = 'linkchecker:' . $format->id() . ':' . $langcode . ':' . hash('sha256', $text);
if ($cached = \Drupal::cache()->get($cache_id)) {
return $cached->data;
}
}
// Convert all Windows and Mac newlines to a single newline, so filters only
// need to deal with one possibility.
$text = str_replace(["\r\n", "\r"], "\n", $text);
// Get a complete list of filters, ordered properly.
/** @var \Drupal\filter\Plugin\FilterInterface[] $filters **/
$filters = $format->filters();
$filter_info = filter_formats();
// Do not run placeholder or special tag filters used as references to nodes
// like 'weblink' or 'weblinks' node types. If the original link node is
// updated, all links are automatically up-to-date and there is no need to
// notify about the broken link on all nodes having a link reference in
// content. This would only confuse the authors as they may also not be able
// to fix the source node of the reference.
$filters_blacklist = array_keys(array_filter(\Drupal::config('linkchecker.settings')->get('extract.filter_blacklist')));
// Give filters the chance to escape HTML-like data such as code or formulas.
foreach ($filters->getAll() as $filter) {
$name = $filter->getType();
$status = $filter->status;
if (!in_array($name, $filters_blacklist)) {
if ($status && isset($filter_info[$name]['prepare callback']) && function_exists($filter_info[$name]['prepare callback'])) {
$function = $filter_info[$name]['prepare callback'];
$text = $function($text, $filters, $format, $langcode, $cache, $cache_id);
}
}
}
// Perform filtering.
foreach ($filters->getAll() as $name => $filter) {
if (!in_array($name, $filters_blacklist)) {
if ($filter->status && isset($filter_info[$name]['process callback']) && function_exists($filter_info[$name]['process callback'])) {
$function = $filter_info[$name]['process callback'];
$text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
}
}
}
// Store in cache with a minimum expiration time of 1 day.
if ($cache) {
\Drupal::cache()->set($cache_id, $text, REQUEST_TIME + (60 * 60 * 24));
}
return $text;
}
/**
* Defines the list of allowed response codes for form input validation.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment