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 8346dbf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 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
6 changes: 2 additions & 4 deletions modules/entity_to_text_tika/src/Storage/LocalFileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function load(File $file, string $langcode = 'eng'): ?string {
* {@inheritdoc}
*/
public function save(File $file, string $content, string $langcode = 'eng'): string {
$this->prepareDestination();

$fullpath = $this->getFullPath($file, $langcode);
file_put_contents($fullpath, $content);
return $fullpath;
Expand Down Expand Up @@ -98,9 +96,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
7 changes: 7 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,11 @@ 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;

}

0 comments on commit 8346dbf

Please sign in to comment.