| @@ 71-107 (lines=37) @@ | ||
| 68 | * |
|
| 69 | * @todo add support for defaultLanguageCode |
|
| 70 | */ |
|
| 71 | protected function update($step) |
|
| 72 | { |
|
| 73 | $objectStateService = $this->repository->getObjectStateService(); |
|
| 74 | ||
| 75 | $groupsCollection = $this->matchObjectStateGroups('update', $step); |
|
| 76 | ||
| 77 | if (count($groupsCollection) > 1 && isset($step->dsl['references'])) { |
|
| 78 | throw new \Exception("Can not execute Object State Group update because multiple groups match, and a references section is specified in the dsl. References can be set when only 1 state group matches"); |
|
| 79 | } |
|
| 80 | ||
| 81 | if (count($groupsCollection) > 1 && isset($step->dsl['identifier'])) { |
|
| 82 | throw new \Exception("Can not execute Object State Group update because multiple groups match, and an identifier is specified in the dsl."); |
|
| 83 | } |
|
| 84 | ||
| 85 | foreach ($groupsCollection as $objectStateGroup) { |
|
| 86 | $objectStateGroupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); |
|
| 87 | ||
| 88 | if (isset($step->dsl['identifier'])) { |
|
| 89 | $objectStateGroupUpdateStruct->identifier = $step->dsl['identifier']; |
|
| 90 | } |
|
| 91 | if (isset($step->dsl['names'])) { |
|
| 92 | foreach ($step->dsl['names'] as $languageCode => $name) { |
|
| 93 | $objectStateGroupUpdateStruct->names[$languageCode] = $name; |
|
| 94 | } |
|
| 95 | } |
|
| 96 | if (isset($step->dsl['descriptions'])) { |
|
| 97 | foreach ($step->dsl['descriptions'] as $languageCode => $description) { |
|
| 98 | $objectStateGroupUpdateStruct->descriptions[$languageCode] = $description; |
|
| 99 | } |
|
| 100 | } |
|
| 101 | $objectStateGroup = $objectStateService->updateObjectStateGroup($objectStateGroup, $objectStateGroupUpdateStruct); |
|
| 102 | ||
| 103 | $this->setReferences($objectStateGroup, $step); |
|
| 104 | } |
|
| 105 | ||
| 106 | return $groupsCollection; |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Handles the delete step of object state group migrations |
|
| @@ 87-123 (lines=37) @@ | ||
| 84 | * |
|
| 85 | * @throws \Exception |
|
| 86 | */ |
|
| 87 | protected function update($step) |
|
| 88 | { |
|
| 89 | $stateCollection = $this->matchObjectStates('update', $step); |
|
| 90 | ||
| 91 | if (count($stateCollection) > 1 && array_key_exists('references', $step->dsl)) { |
|
| 92 | throw new \Exception("Can not execute Object State update because multiple states match, and a references section is specified in the dsl. References can be set when only 1 state matches"); |
|
| 93 | } |
|
| 94 | ||
| 95 | if (count($stateCollection) > 1 && isset($step->dsl['identifier'])) { |
|
| 96 | throw new \Exception("Can not execute Object State update because multiple states match, and an identifier is specified in the dsl."); |
|
| 97 | } |
|
| 98 | ||
| 99 | $objectStateService = $this->repository->getObjectStateService(); |
|
| 100 | ||
| 101 | foreach ($stateCollection as $state) { |
|
| 102 | $objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct(); |
|
| 103 | ||
| 104 | if (isset($step->dsl['identifier'])) { |
|
| 105 | $objectStateUpdateStruct->identifier = $step->dsl['identifier']; |
|
| 106 | } |
|
| 107 | if (isset($step->dsl['names'])) { |
|
| 108 | foreach ($step->dsl['names'] as $name) { |
|
| 109 | $objectStateUpdateStruct->names[$name['languageCode']] = $name['name']; |
|
| 110 | } |
|
| 111 | } |
|
| 112 | if (isset($step->dsl['descriptions'])) { |
|
| 113 | foreach ($step->dsl['descriptions'] as $languageCode => $description) { |
|
| 114 | $objectStateUpdateStruct->descriptions[$languageCode] = $description; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | $state = $objectStateService->updateObjectState($state, $objectStateUpdateStruct); |
|
| 118 | ||
| 119 | $this->setReferences($state, $step); |
|
| 120 | } |
|
| 121 | ||
| 122 | return $stateCollection; |
|
| 123 | } |
|
| 124 | ||
| 125 | /** |
|
| 126 | * Handles the deletion step of object state migrations. |
|