Code Duplication    Length = 37-39 lines in 2 locations

Core/Executor/ObjectStateGroupManager.php 1 location

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

Core/Executor/ObjectStateManager.php 1 location

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