Skip to content

Commit

Permalink
move the storage preparation responsibility
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK committed Apr 25, 2024
1 parent 491ee94 commit d4c9e91
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ $body = \Drupal::service('entity_to_text_tika.extractor.file_to_text')->fromFile
or for an advanced usage avoiding multiple calls to Tika:

```php
// Anywhere at least once in the code (Eg. module.install) in order to prepare the storage.
\Drupal::service('entity_to_text_tika.storage.local_file')->prepareStorage();

// Load the already OCR'ed file if possible to avoid unecessary calls to Tika.
$body = \Drupal::service('entity_to_text_tika.storage.local_file')->load($file, 'eng+fra');

Expand Down
4 changes: 2 additions & 2 deletions modules/entity_to_text_tika/src/Storage/LocalFileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ private function getFullPath(File $file, string $langcode = 'eng'): string {
}

/**
* Ensure the destination directory is ready to use.
* {@inheritdoc}
*/
private function prepareDestination(): void {
public function prepareStorage(): void {
$dest = self::DESTINATION;
$this->fileSystem->prepareDirectory($dest, FileSystemInterface::CREATE_DIRECTORY);
}
Expand Down
6 changes: 6 additions & 0 deletions modules/entity_to_text_tika/src/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public function load(File $file, string $langcode = 'eng'): ?string;
*/
public function save(File $file, string $content, string $langcode = 'eng'): string;

/**
* Ensure the storage is ready to store OCR text values.
*
* @return void

Check failure on line 46 in modules/entity_to_text_tika/src/Storage/StorageInterface.php

View workflow job for this annotation

GitHub Actions / phpcs

Description for the @return value is missing
*/
public function prepareStorage(): void;

Check failure on line 48 in modules/entity_to_text_tika/src/Storage/StorageInterface.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 blank line after function; 0 found
}

Check failure on line 49 in modules/entity_to_text_tika/src/Storage/StorageInterface.php

View workflow job for this annotation

GitHub Actions / phpcs

The closing brace for the interface must have an empty line before it

0 comments on commit d4c9e91

Please sign in to comment.