Skip to content

Commit

Permalink
Update reindexation detection code using isDirty()
Browse files Browse the repository at this point in the history
for CakePHP 3.

Note that the existing array_intersect_key() hack was
always returning true, which means every modified
field of a sentence was triggering a reindexation of
all its direct and indirect translations, instead of
only the 'user_id' and 'lang' fields.
  • Loading branch information
jiru committed Mar 6, 2019
1 parent d2e2aad commit d58949a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Model/Table/SentencesTable.php
Expand Up @@ -230,14 +230,10 @@ public function afterSave($event, $entity, $options = array())
$this->getEventManager()->dispatch($event);

$this->updateTags($entity);
if (isset($entity->modified)) {
if ($entity->isDirty('modified')) {
$this->needsReindex($entity->id);
}
$transIndexedAttr = array('lang', 'user_id');
$transNeedsReindex = array_intersect_key(
$entity->old_format['Sentence'],
array_flip($transIndexedAttr)
);
$transNeedsReindex = $entity->isDirty('lang') || $entity->isDirty('user_id');
if ($transNeedsReindex) {
$this->flagTranslationsToReindex($entity->id);
}
Expand Down

0 comments on commit d58949a

Please sign in to comment.