Code Duplication    Length = 37-37 lines in 2 locations

Core/Executor/ObjectStateGroupManager.php 1 location

@@ 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 = $this->referenceResolver->resolveReference($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

Core/Executor/ObjectStateManager.php 1 location

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