forked from alxp/islandora
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reindexing parents of extracted text when updated (#767)
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
modules/islandora_text_extraction/islandora_text_extraction.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
logger.channel.islandora_text_extraction: | ||
parent: logger.channel_base | ||
arguments: ['islandora_text_extraction'] | ||
islandora_text_extraction.search_reindexer: | ||
class: Drupal\islandora_text_extraction\SearchReindexer | ||
arguments: ['@islandora.utils', '@logger.channel.islandora_text_extraction'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Drupal\islandora_text_extraction; | ||
|
||
use Drupal\islandora\IslandoraUtils; | ||
use Drupal\media\MediaInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Creates a GeminiClient as a Drupal service. | ||
* | ||
* @package Drupal\islandora | ||
*/ | ||
class SearchReindexer { | ||
|
||
/** | ||
* Islandora Utils. | ||
* | ||
* @var \Drupal\islandora\IslandoraUtils | ||
*/ | ||
protected $utils; | ||
|
||
/** | ||
* Logger. | ||
* | ||
* @var \Psr\Log\LoggerInterface | ||
*/ | ||
protected $logger; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Drupal\islandora\IslandoraUtils $utils | ||
* Islandora utils. | ||
* @param \Psr\Log\LoggerInterface $logger | ||
* The logger channel. | ||
*/ | ||
public function __construct(IslandoraUtils $utils, LoggerInterface $logger) { | ||
$this->utils = $utils; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* Reindexes parent node for a media. No-op if parent does not exist. | ||
* | ||
* @param Drupal\media\MediaInterface $media | ||
* Media whose parent you want to reindex. | ||
*/ | ||
public function reindexParent(MediaInterface $media) { | ||
$parent = $this->utils->getParentNode($media); | ||
|
||
if ($parent === NULL) { | ||
return; | ||
} | ||
|
||
$this->logger->debug( | ||
"Re-indexing parent node @nid for extracted text @mid using the search_api", | ||
['@nid' => $parent->id(), '@mid' => $media->id()] | ||
); | ||
|
||
$parent->original = $parent; | ||
search_api_entity_update($parent); | ||
} | ||
|
||
} |