-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityToTextTikaRequirementsHook.php
More file actions
49 lines (39 loc) · 2.33 KB
/
Copy pathEntityToTextTikaRequirementsHook.php
File metadata and controls
49 lines (39 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Drupal\entity_to_text_tika\Hook;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* RuntimeRequirements for entity to text tika.
*/
final class EntityToTextTikaRequirementsHook {
use StringTranslationTrait;
public function __construct(protected readonly StreamWrapperManagerInterface $streamWrapperManager, protected readonly FileSystemInterface $fileSystem) {
}
/**
* Implements hook_runtime_requirements().
*/
#[Hook('runtime_requirements')]
public function runtime(): array {
$requirements = [];
$requirements['entity_to_text_tika_private'] = [
'title' => $this->t('Entity to Text (Tika): Local File Storage (OCR cache)'),
'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.'),
'value' => $this->t('Private file system is set and writtable.'),
];
// Check if the private file stream wrapper is ready to use.
if (!$this->streamWrapperManager->isValidScheme('private')) {
$requirements['entity_to_text_tika_private']['value'] = 'Private file system is not set.';
$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.');
$requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_INFO;
}
$private_path = $this->fileSystem->realpath('private://');
// Check if the private file stream wrapper is ready to use.
if (!is_dir($private_path) || !is_writable($private_path)) {
$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]);
$requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_ERROR;
}
return $requirements;
}
}