|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigFactoryInterface;
|
|
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
|
use Drupal\Core\Link; |
|
|
|
|
use Drupal\Core\Mail\MailManagerInterface; |
|
|
|
|
use Drupal\Core\StringTranslation\StringTranslationTrait; |
|
|
|
|
use Drupal\Core\StringTranslation\TranslationInterface; |
|
|
|
|
use Drupal\dgi_fixity\Entity\FixityCheck; |
|
|
|
@ -47,10 +48,17 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
*/ |
|
|
|
|
protected $time; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The mail manager service. |
|
|
|
|
* |
|
|
|
|
* @var \Drupal\Core\Mail\MailManagerInterface |
|
|
|
|
*/ |
|
|
|
|
protected $mailManager; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The logger for this service. |
|
|
|
|
* |
|
|
|
|
* @var \Psr\Log\LoggerInterface |
|
|
|
|
* @var Psr\Log\LoggerInterface |
|
|
|
|
*/ |
|
|
|
|
protected $logger; |
|
|
|
|
|
|
|
|
@ -64,18 +72,12 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
/** |
|
|
|
|
* Constructor. |
|
|
|
|
*/ |
|
|
|
|
public function __construct( |
|
|
|
|
TranslationInterface $string_translation, |
|
|
|
|
ConfigFactoryInterface $config, |
|
|
|
|
EntityTypeManagerInterface $entity_type_manager, |
|
|
|
|
TimeInterface $time, |
|
|
|
|
LoggerInterface $logger, |
|
|
|
|
FileHash $filehash, |
|
|
|
|
) { |
|
|
|
|
public function __construct(TranslationInterface $string_translation, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, TimeInterface $time, MailManagerInterface $mail_manager, LoggerInterface $logger, FileHash $filehash) { |
|
|
|
|
$this->stringTranslation = $string_translation; |
|
|
|
|
$this->config = $config; |
|
|
|
|
$this->entityTypeManager = $entity_type_manager; |
|
|
|
|
$this->time = $time; |
|
|
|
|
$this->mailManager = $mail_manager; |
|
|
|
|
$this->logger = $logger; |
|
|
|
|
$this->filehash = $filehash; |
|
|
|
|
} |
|
|
|
@ -84,7 +86,10 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
* {@inheritdoc} |
|
|
|
|
*/ |
|
|
|
|
public function fromEntityTypes(): array { |
|
|
|
|
return static::ENTITY_TYPES; |
|
|
|
|
return [ |
|
|
|
|
'media', |
|
|
|
|
'file', |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -218,7 +223,7 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
// Assume success until proven untrue. |
|
|
|
|
$state = FixityCheck::STATE_MATCHES; |
|
|
|
|
// If column is set, only generate that hash. |
|
|
|
|
foreach ($this->filehash->getEnabledAlgorithms() as $column => $algo) { |
|
|
|
|
foreach ($this->filehash->algos() as $column => $algo) { |
|
|
|
|
// Nothing to do if the previous checksum value is not known. |
|
|
|
|
if (!isset($file->{$column})) { |
|
|
|
|
$state = FixityCheck::STATE_NO_CHECKSUM; |
|
|
|
@ -288,7 +293,6 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
->condition('performed', 0, '!=') |
|
|
|
|
->groupBy('state') |
|
|
|
|
->aggregate('id', 'COUNT') |
|
|
|
|
->accessCheck(FALSE) |
|
|
|
|
->execute(); |
|
|
|
|
|
|
|
|
|
$failed = 0; |
|
|
|
@ -308,14 +312,12 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
$periodic = (int) $storage->getQuery('AND') |
|
|
|
|
->count('id') |
|
|
|
|
->condition('periodic', TRUE) |
|
|
|
|
->accessCheck(FALSE) |
|
|
|
|
->execute(); |
|
|
|
|
|
|
|
|
|
// All checks performed ever. |
|
|
|
|
$revisions = (int) $storage->getQuery('AND') |
|
|
|
|
->allRevisions() |
|
|
|
|
->count('id') |
|
|
|
|
->accessCheck(FALSE) |
|
|
|
|
->execute(); |
|
|
|
|
|
|
|
|
|
// Checks which have exceeded the threshold and should be performed again. |
|
|
|
@ -324,7 +326,6 @@ class FixityCheckService implements FixityCheckServiceInterface {
|
|
|
|
|
->condition('periodic', TRUE) |
|
|
|
|
->condition('performed', $threshold, '>=') |
|
|
|
|
->count('id') |
|
|
|
|
->accessCheck(FALSE) |
|
|
|
|
->execute(); |
|
|
|
|
|
|
|
|
|
// Up to date checks. |
|
|
|
|