/**
  * Private helper to update a synonym group, throw exception on merge conflict
  *
  * @param SynonymGroup $oldSynonymGroup
  * @param SynonymGroupInterface $newSynonymGroup
  * @param bool $errorOnMergeConflict
  * @return SynonymGroupInterface
  * @throws Synonym\MergeConflictException
  */
 private function update(SynonymGroup $oldSynonymGroup, SynonymGroupInterface $newSynonymGroup, $errorOnMergeConflict)
 {
     $matchingSynonymGroups = $this->getMatchingSynonymGroups($newSynonymGroup);
     // ignore existing synonym group as it's value will be discarded
     $matchingSynonymGroups = array_diff_key($matchingSynonymGroups, [$oldSynonymGroup->getGroupId() => $oldSynonymGroup->getSynonymGroup()]);
     if ($matchingSynonymGroups) {
         if ($errorOnMergeConflict) {
             throw new Synonym\MergeConflictException($this->parseToArray($matchingSynonymGroups), $this->getExceptionMessage($matchingSynonymGroups));
         }
         // merge matching synonyms before updating a row
         $mergedSynonyms = $this->merge($newSynonymGroup, array_keys($matchingSynonymGroups));
         $oldSynonymGroup->setSynonymGroup(implode(',', $mergedSynonyms));
         $oldSynonymGroup->setWebsiteId($newSynonymGroup->getWebsiteId());
         $oldSynonymGroup->setStoreId($newSynonymGroup->getStoreId());
         $this->resourceModel->save($oldSynonymGroup);
     } else {
         // no merge conflict, perform simple update
         $this->populateSynonymGroupModel($oldSynonymGroup, $newSynonymGroup);
         $this->resourceModel->save($oldSynonymGroup);
     }
     return $oldSynonymGroup;
 }
Exemplo n.º 2
0
 public function testSetGetSynonymGroup()
 {
     $this->assertEquals($this->model, $this->model->setSynonymGroup('a,b,c'));
     $this->assertEquals('a,b,c', $this->model->getSynonymGroup());
 }