X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flinkchecker%2Fsrc%2FCommands%2FLinkcheckerCommands.php;fp=web%2Fmodules%2Fcontrib%2Flinkchecker%2Fsrc%2FCommands%2FLinkcheckerCommands.php;h=30102d2ffba71b30a67dfd6f13e9aef573d0acbc;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/modules/contrib/linkchecker/src/Commands/LinkcheckerCommands.php b/web/modules/contrib/linkchecker/src/Commands/LinkcheckerCommands.php new file mode 100644 index 000000000..30102d2ff --- /dev/null +++ b/web/modules/contrib/linkchecker/src/Commands/LinkcheckerCommands.php @@ -0,0 +1,136 @@ +config = $config; + $this->logger = $logger; + } + + /** + * Reanalyzes content for links. Recommended after module has been upgraded. + * + * @command linkchecker:analyze + * + * @aliases lca + */ + public function analyze() { + // @fixme + global $base_url; + if ($base_url == 'http://default') { + $this->logger()->error('You MUST configure the site $base_url or provide --uri parameter.'); + } + + // @fixme + module_load_include('admin.inc', 'linkchecker'); + + // Fake $form_state to leverage _submit function. + $form_state = [ + 'values' => ['op' => $this->t('Analyze content for links')], + 'buttons' => [], + ]; + + $node_types = linkchecker_scan_node_types(); + if (!empty($node_types) || \Drupal::config('linkchecker.settings')->get('scan_blocks')) { + linkchecker_analyze_links_submit(NULL, $form_state); + drush_backend_batch_process(); + } + else { + $this->logger()->warning('No content configured for link analysis.'); + } + } + + /** + * Clears all link data and analyze content for links. + * + * WARNING: Custom link check settings are deleted. + * + * @command linkchecker:clear + * + * @aliases lccl + */ + public function clear() { + // @fixme + global $base_url; + if ($base_url == 'http://default') { + $this->logger()->error('You MUST configure the site $base_url or provide --uri parameter.'); + return; + } + + // @fixme + module_load_include('admin.inc', 'linkchecker'); + + // Fake $form_state to leverage _submit function. + $form_state = [ + 'values' => ['op' => $this->t('Clear link data and analyze content for links')], + 'buttons' => [], + ]; + + $node_types = linkchecker_scan_node_types(); + if (!empty($node_types) || \Drupal::config('linkchecker.settings') + ->get('scan_blocks')) { + linkchecker_clear_analyze_links_submit(NULL, $form_state); + drush_backend_batch_process(); + } + else { + $this->logger()->warning('No content configured for link analysis.'); + } + } + + /** + * Check link status. + * + * @command linkchecker:check + * + * @aliases lcch + */ + public function check() { + $this->logger()->info('Starting link checking...'); + $run = _linkchecker_check_links(); + if (!$run) { + $this->logger()->warning('Attempted to re-run link checks while they are already running.'); + } + else { + $this->logger()->info('Finished checking links.'); + } + } + +}