Code Duplication    Length = 37-37 lines in 2 locations

Core/Executor/ObjectStateGroupManager.php 1 location

@@ 81-117 (lines=37) @@
78
     *
79
     * @todo add support for defaultLanguageCode
80
     */
81
    protected function update($step)
82
    {
83
        $objectStateService = $this->repository->getObjectStateService();
84
85
        $groupsCollection = $this->matchObjectStateGroups('update', $step);
86
87
        if (count($groupsCollection) > 1 && isset($step->dsl['references'])) {
88
            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");
89
        }
90
91
        if (count($groupsCollection) > 1 && isset($step->dsl['identifier'])) {
92
            throw new \Exception("Can not execute Object State Group update because multiple groups match, and an identifier is specified in the dsl.");
93
        }
94
95
        foreach ($groupsCollection as $objectStateGroup) {
96
            $objectStateGroupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct();
97
98
            if (isset($step->dsl['identifier'])) {
99
                $objectStateGroupUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
100
            }
101
            if (isset($step->dsl['names'])) {
102
                foreach ($step->dsl['names'] as $languageCode => $name) {
103
                    $objectStateGroupUpdateStruct->names[$languageCode] = $name;
104
                }
105
            }
106
            if (isset($step->dsl['descriptions'])) {
107
                foreach ($step->dsl['descriptions'] as $languageCode => $description) {
108
                    $objectStateGroupUpdateStruct->descriptions[$languageCode] = $description;
109
                }
110
            }
111
            $objectStateGroup = $objectStateService->updateObjectStateGroup($objectStateGroup, $objectStateGroupUpdateStruct);
112
113
            $this->setReferences($objectStateGroup, $step);
114
        }
115
116
        return $groupsCollection;
117
    }
118
119
    /**
120
     * Handles the delete step of object state group migrations

Core/Executor/ObjectStateManager.php 1 location

@@ 99-135 (lines=37) @@
96
     *
97
     * @throws \Exception
98
     */
99
    protected function update($step)
100
    {
101
        $stateCollection = $this->matchObjectStates('update', $step);
102
103
        if (count($stateCollection) > 1 && array_key_exists('references', $step->dsl)) {
104
            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");
105
        }
106
107
        if (count($stateCollection) > 1 && isset($step->dsl['identifier'])) {
108
            throw new \Exception("Can not execute Object State update because multiple states match, and an identifier is specified in the dsl.");
109
        }
110
111
        $objectStateService = $this->repository->getObjectStateService();
112
113
        foreach ($stateCollection as $state) {
114
            $objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct();
115
116
            if (isset($step->dsl['identifier'])) {
117
                $objectStateUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
118
            }
119
            if (isset($step->dsl['names'])) {
120
                foreach ($step->dsl['names'] as $name) {
121
                    $objectStateUpdateStruct->names[$name['languageCode']] = $name['name'];
122
                }
123
            }
124
            if (isset($step->dsl['descriptions'])) {
125
                foreach ($step->dsl['descriptions'] as $languageCode => $description) {
126
                    $objectStateUpdateStruct->descriptions[$languageCode] = $description;
127
                }
128
            }
129
            $state = $objectStateService->updateObjectState($state, $objectStateUpdateStruct);
130
131
            $this->setReferences($state, $step);
132
        }
133
134
        return $stateCollection;
135
    }
136
137
    /**
138
     * Handles the deletion step of object state migrations.