class LinkCheckerCommands in Link checker 8
Drush 9 commands for Linkchecker module.
Hierarchy
- class \Drupal\linkchecker\Commands\LinkCheckerCommands extends \Drush\Commands\DrushCommands uses StringTranslationTrait
Expanded class hierarchy of LinkCheckerCommands
1 string reference to 'LinkCheckerCommands'
1 service uses LinkCheckerCommands
File
- src/
Commands/ LinkCheckerCommands.php, line 16
Namespace
Drupal\linkchecker\CommandsView source
class LinkCheckerCommands extends DrushCommands {
use StringTranslationTrait;
/**
* The linkchecker settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $linkcheckerSetting;
/**
* The logger.channel.linkchecker service.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The extractor batch helper.
*
* @var \Drupal\linkchecker\LinkExtractorBatch
*/
protected $extractorBatch;
/**
* The checker batch helper.
*
* @var \Drupal\linkchecker\LinkCheckerBatch
*/
protected $checkerBatch;
/**
* The link clean up.
*
* @var \Drupal\linkchecker\LinkCleanUp
*/
protected $linkCleanUp;
/**
* LinkCheckerCommands constructor.
*/
public function __construct(ConfigFactoryInterface $configFactory, LoggerInterface $logger, LinkExtractorBatch $extractorBatch, LinkCheckerBatch $checkerBatch, LinkCleanUp $linkCleanUp) {
parent::__construct();
$this->linkcheckerSetting = $configFactory
->get('linkchecker.settings');
$this->logger = $logger;
$this->extractorBatch = $extractorBatch;
$this->checkerBatch = $checkerBatch;
$this->linkCleanUp = $linkCleanUp;
}
/**
* Reanalyzes content for links. Recommended after module has been upgraded.
*
* @command linkchecker:analyze
*
* @aliases lca
*/
public function analyze() {
$this
->analyzeCheckParams();
$total = $this->extractorBatch
->getTotalEntitiesToProcess();
if (!empty($total)) {
$this->extractorBatch
->batch();
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() {
$this
->analyzeCheckParams();
$total = $this->extractorBatch
->getTotalEntitiesToProcess();
if (!empty($total)) {
$this->linkCleanUp
->removeAllBatch();
$this->extractorBatch
->batch();
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...');
// Always rebuild queue on Drush command run to check all links.
if (empty($this->checkerBatch
->getTotalLinksToProcess())) {
$this->logger
->notice($this
->t('There are no links to check.'));
return;
}
$this->checkerBatch
->batch();
drush_backend_batch_process();
}
/**
* Throws an exception if base url is not set.
*
* @throws \Exception
*/
protected function analyzeCheckParams() {
$alias = $this
->getConfig()
->getContext('alias');
$options = $alias
->get('options');
if (!isset($options['uri'])) {
$httpProtocol = $this->linkcheckerSetting
->get('default_url_scheme');
$baseUrl = $httpProtocol . $this->linkcheckerSetting
->get('base_path');
}
else {
$baseUrl = $options['uri'];
}
if (empty($baseUrl)) {
throw new \Exception($this
->t('You MUST configure the site base_url or provide --uri parameter.'));
}
if (mb_strpos($baseUrl, 'http') !== 0) {
throw new \Exception($this
->t('Base url should start with http scheme (http:// or https://)'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LinkCheckerCommands:: |
protected | property | The checker batch helper. | |
LinkCheckerCommands:: |
protected | property | The extractor batch helper. | |
LinkCheckerCommands:: |
protected | property | The linkchecker settings. | |
LinkCheckerCommands:: |
protected | property | The link clean up. | |
LinkCheckerCommands:: |
protected | property | The logger.channel.linkchecker service. | |
LinkCheckerCommands:: |
public | function | Reanalyzes content for links. Recommended after module has been upgraded. | |
LinkCheckerCommands:: |
protected | function | Throws an exception if base url is not set. | |
LinkCheckerCommands:: |
public | function | Check link status. | |
LinkCheckerCommands:: |
public | function | Clears all link data and analyze content for links. | |
LinkCheckerCommands:: |
public | function | LinkCheckerCommands constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |