Skip to content

Commit

Permalink
Merge pull request #41 from Prashant-bd/DDST-382
Browse files Browse the repository at this point in the history
DDST-382: Handle errors while deleting orphaned embargo
  • Loading branch information
nchiasson-dgi authored Aug 5, 2024
2 parents a075aa4 + ad31c3c commit a481d32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Entity/Embargo.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ public function getCacheMaxAge() {
* {@inheritdoc}
*/
public function getCacheTags() {
$tags = Cache::mergeTags(parent::getCacheTags(), $this->getEmbargoedNode()->getCacheTags());
$tags = parent::getCacheTags();
if ($node = $this->getEmbargoedNode()) {
$tags = Cache::mergeTags($tags, $node->getCacheTags());
}

if ($this->getExemptIps()) {
$tags = Cache::mergeTags($tags, $this->getExemptIps()->getCacheTags());
Expand All @@ -411,9 +414,11 @@ public function getCacheTags() {
public function getCacheContexts() {
$contexts = Cache::mergeContexts(
parent::getCacheContexts(),
$this->getEmbargoedNode()->getCacheContexts(),
['user.embargo__has_exemption'],
);
if ($node = $this->getEmbargoedNode()) {
$contexts = Cache::mergeContexts($contexts, $node->getCacheContexts());
}

if ($this->getExemptIps()) {
$contexts = Cache::mergeContexts($contexts, $this->getExemptIps()->getCacheContexts());
Expand Down
6 changes: 6 additions & 0 deletions src/Plugin/search_api/processor/EmbargoJoinProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ protected function doAddNodeField(ItemInterface $item, EntityInterface $entity)
*/
protected function doAddEmbargoField(ItemInterface $item, EntityInterface $entity) : void {
assert($entity instanceof EmbargoInterface);

// Early return if there is no embargoed node.
if ($entity->getEmbargoedNode() === NULL) {
return;
}

$paths = match ($entity->getEmbargoType()) {
EmbargoInterface::EMBARGO_TYPE_FILE => [static::EMBARGO_FIELD_FILE],
EmbargoInterface::EMBARGO_TYPE_NODE => [static::EMBARGO_FIELD_NODE, static::EMBARGO_FIELD_FILE],
Expand Down

0 comments on commit a481d32

Please sign in to comment.