|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\entity_to_text_tika\Hook; |
| 4 | + |
| 5 | +use Drupal\Core\File\FileSystemInterface; |
| 6 | +use Drupal\Core\Hook\Attribute\Hook; |
| 7 | +use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; |
| 8 | +use Drupal\Core\StringTranslation\StringTranslationTrait; |
| 9 | + |
| 10 | +/** |
| 11 | + * RuntimeRequirements for entity to text tika. |
| 12 | + */ |
| 13 | +final class EntityToTextTikaRequirementsHook { |
| 14 | + use StringTranslationTrait; |
| 15 | + |
| 16 | + public function __construct(protected readonly StreamWrapperManagerInterface $streamWrapperManager, protected readonly FileSystemInterface $fileSystem) { |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * Implements hook_runtime_requirements(). |
| 21 | + */ |
| 22 | + #[Hook('runtime_requirements')] |
| 23 | + public function runtime(): array { |
| 24 | + $requirements = []; |
| 25 | + |
| 26 | + $requirements['entity_to_text_tika_private'] = [ |
| 27 | + 'title' => $this->t('Entity to Text (Tika): Local File Storage (OCR cache)'), |
| 28 | + 'description' => $this->t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration can leverage it.'), |
| 29 | + 'value' => $this->t('Private file system is set and writtable.'), |
| 30 | + ]; |
| 31 | + |
| 32 | + // Check if the private file stream wrapper is ready to use. |
| 33 | + if (!$this->streamWrapperManager->isValidScheme('private')) { |
| 34 | + $requirements['entity_to_text_tika_private']['value'] = 'Private file system is not set.'; |
| 35 | + $requirements['entity_to_text_tika_private']['description'] = $this->t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration cannot leverage it.'); |
| 36 | + $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_INFO; |
| 37 | + } |
| 38 | + |
| 39 | + $private_path = $this->fileSystem->realpath('private://'); |
| 40 | + // Check if the private file stream wrapper is ready to use. |
| 41 | + if (!is_dir($private_path) || !is_writable($private_path)) { |
| 42 | + $requirements['entity_to_text_tika_private']['value'] = $this->t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration cannot leverage it. The resolved private directory %directory% seems not writable.', ['%directory%' => $private_path]); |
| 43 | + $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_ERROR; |
| 44 | + } |
| 45 | + |
| 46 | + return $requirements; |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments