Code Duplication    Length = 56-56 lines in 2 locations

Core/Executor/ContentTypeGroupManager.php 1 location

@@ 156-211 (lines=56) @@
153
     * @throws \Exception
154
     * @return array
155
     */
156
    public function generateMigration(array $matchCondition, $mode, array $context = array())
157
    {
158
        $previousUserId = $this->loginUser($this->getAdminUserIdentifierFromContext($context));
159
        $contentTypeGroupCollection = $this->contentTypeGroupMatcher->match($matchCondition);
160
        $data = array();
161
162
        /** @var \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $contentTypeGroup */
163
        foreach ($contentTypeGroupCollection as $contentTypeGroup) {
164
165
            $contentTypeGroupData = array(
166
                'type' => reset($this->supportedStepTypes),
167
                'mode' => $mode,
168
            );
169
170
            switch ($mode) {
171
                case 'create':
172
                    $contentTypeGroupData = array_merge(
173
                        $contentTypeGroupData,
174
                        array(
175
                            'identifier' => $contentTypeGroup->identifier,
176
                            'creation_date' => $contentTypeGroup->creationDate->getTimestamp()
177
                        )
178
                    );
179
                    break;
180
                case 'update':
181
                    $contentTypeGroupData = array_merge(
182
                        $contentTypeGroupData,
183
                        array(
184
                            'match' => array(
185
                                ContentTypeGroupMatcher::MATCH_CONTENTTYPEGROUP_IDENTIFIER => $contentTypeGroup->identifier
186
                            ),
187
                            'identifier' => $contentTypeGroup->identifier,
188
                            'modification_date' => $contentTypeGroup->modificationDate->getTimestamp()
189
                        )
190
                    );
191
                    break;
192
                case 'delete':
193
                    $contentTypeGroupData = array_merge(
194
                        $contentTypeGroupData,
195
                            array(
196
                                'match' => array(
197
                                    ContentTypeGroupMatcher::MATCH_CONTENTTYPEGROUP_IDENTIFIER => $contentTypeGroup->identifier
198
                                )
199
                            )
200
                        );
201
                    break;
202
                default:
203
                    throw new \Exception("Executor 'content_type_group' doesn't support mode '$mode'");
204
            }
205
206
            $data[] = $contentTypeGroupData;
207
        }
208
209
        $this->loginUser($previousUserId);
210
        return $data;
211
    }
212
213
    /**
214
     * @param int|string $date if integer, we assume a timestamp

Core/Executor/SectionManager.php 1 location

@@ 172-227 (lines=56) @@
169
     * @throws \Exception
170
     * @return array
171
     */
172
    public function generateMigration(array $matchCondition, $mode, array $context = array())
173
    {
174
        $previousUserId = $this->loginUser($this->getAdminUserIdentifierFromContext($context));
175
        $sectionCollection = $this->sectionMatcher->match($matchCondition);
176
        $data = array();
177
178
        /** @var \eZ\Publish\API\Repository\Values\Content\Section $section */
179
        foreach ($sectionCollection as $section) {
180
181
            $sectionData = array(
182
                'type' => reset($this->supportedStepTypes),
183
                'mode' => $mode,
184
            );
185
186
            switch ($mode) {
187
                case 'create':
188
                    $sectionData = array_merge(
189
                        $sectionData,
190
                        array(
191
                            'identifier' => $section->identifier,
192
                            'name' => $section->name,
193
                        )
194
                    );
195
                    break;
196
                case 'update':
197
                    $sectionData = array_merge(
198
                        $sectionData,
199
                        array(
200
                            'match' => array(
201
                                SectionMatcher::MATCH_SECTION_ID => $section->id
202
                            ),
203
                            'identifier' => $section->identifier,
204
                            'name' => $section->name,
205
                        )
206
                    );
207
                    break;
208
                case 'delete':
209
                    $sectionData = array_merge(
210
                        $sectionData,
211
                        array(
212
                            'match' => array(
213
                                SectionMatcher::MATCH_SECTION_ID => $section->id
214
                            )
215
                        )
216
                    );
217
                    break;
218
                default:
219
                    throw new \Exception("Executor 'section' doesn't support mode '$mode'");
220
            }
221
222
            $data[] = $sectionData;
223
        }
224
225
        $this->loginUser($previousUserId);
226
        return $data;
227
    }
228
}
229