Code Duplication    Length = 37-37 lines in 2 locations

Core/Executor/ObjectStateGroupManager.php 1 location

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

Core/Executor/ObjectStateManager.php 1 location

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