Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ContentManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class ContentManager extends RepositoryExecutor implements MigrationGeneratorInterface |
||
| 27 | 20 | { |
|
| 28 | protected $supportedStepTypes = array('content'); |
||
| 29 | 20 | ||
| 30 | 20 | protected $contentMatcher; |
|
| 31 | 20 | protected $sectionMatcher; |
|
| 32 | protected $userMatcher; |
||
| 33 | protected $objectStateMatcher; |
||
| 34 | protected $complexFieldManager; |
||
| 35 | protected $locationManager; |
||
| 36 | 4 | protected $sortConverter; |
|
| 37 | |||
| 38 | 4 | public function __construct( |
|
| 39 | 4 | ContentMatcher $contentMatcher, |
|
| 40 | 4 | SectionMatcher $sectionMatcher, |
|
| 41 | UserMatcher $userMatcher, |
||
| 42 | 4 | ObjectStateMatcher $objectStateMatcher, |
|
| 43 | 4 | ComplexFieldManager $complexFieldManager, |
|
| 44 | 3 | LocationManager $locationManager, |
|
| 45 | 3 | SortConverter $sortConverter |
|
| 46 | 4 | ) { |
|
| 47 | $this->contentMatcher = $contentMatcher; |
||
| 48 | 4 | $this->sectionMatcher = $sectionMatcher; |
|
| 49 | 4 | $this->userMatcher = $userMatcher; |
|
| 50 | $this->objectStateMatcher = $objectStateMatcher; |
||
| 51 | 4 | $this->complexFieldManager = $complexFieldManager; |
|
| 52 | 1 | $this->locationManager = $locationManager; |
|
| 53 | 1 | $this->sortConverter = $sortConverter; |
|
| 54 | } |
||
| 55 | |||
| 56 | 4 | /** |
|
| 57 | 4 | * Handle the content create migration action type |
|
| 58 | 1 | */ |
|
| 59 | 1 | protected function create() |
|
| 60 | 4 | { |
|
| 61 | 4 | $contentService = $this->repository->getContentService(); |
|
| 62 | 1 | $locationService = $this->repository->getLocationService(); |
|
| 63 | 1 | $contentTypeService = $this->repository->getContentTypeService(); |
|
| 64 | |||
| 65 | 4 | $contentTypeIdentifier = $this->dsl['content_type']; |
|
| 66 | 1 | $contentTypeIdentifier = $this->referenceResolver->resolveReference($contentTypeIdentifier); |
|
| 67 | 1 | /// @todo use a contenttypematcher |
|
| 68 | $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
||
| 69 | 4 | ||
| 70 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $this->getLanguageCode()); |
||
| 71 | 4 | ||
| 72 | $this->setFields($contentCreateStruct, $this->dsl['attributes'], $contentType); |
||
| 73 | |||
| 74 | if (isset($this->dsl['always_available'])) { |
||
| 75 | $contentCreateStruct->alwaysAvailable = $this->dsl['always_available']; |
||
| 76 | } else { |
||
| 77 | // Could be removed when https://github.com/ezsystems/ezpublish-kernel/pull/1874 is merged, |
||
| 78 | // but we strive to support old eZ kernel versions as well... |
||
| 79 | $contentCreateStruct->alwaysAvailable = $contentType->defaultAlwaysAvailable; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (isset($this->dsl['remote_id'])) { |
||
| 83 | 4 | $contentCreateStruct->remoteId = $this->dsl['remote_id']; |
|
| 84 | 3 | } |
|
| 85 | |||
| 86 | 3 | View Code Duplication | if (isset($this->dsl['section'])) { |
|
|
|||
| 87 | 3 | $sectionKey = $this->referenceResolver->resolveReference($this->dsl['section']); |
|
| 88 | $section = $this->sectionMatcher->matchOneByKey($sectionKey); |
||
| 89 | $contentCreateStruct->sectionId = $section->id; |
||
| 90 | } |
||
| 91 | |||
| 92 | View Code Duplication | if (isset($this->dsl['owner'])) { |
|
| 93 | $owner = $this->getUser($this->dsl['owner']); |
||
| 94 | 1 | $contentCreateStruct->ownerId = $owner->id; |
|
| 95 | } |
||
| 96 | 1 | ||
| 97 | 1 | // This is a bit tricky, as the eZPublish API does not support having a different creator and owner with only 1 version. |
|
| 98 | // We allow it, hoping that nothing gets broken because of it |
||
| 99 | if (isset($this->dsl['version_creator'])) { |
||
| 100 | $realContentOwnerId = $contentCreateStruct->ownerId; |
||
| 101 | if ($realContentOwnerId == null) { |
||
| 102 | $realContentOwnerId = $this->repository->getCurrentUser()->id; |
||
| 103 | } |
||
| 104 | $versionCreator = $this->getUser($this->dsl['version_creator']); |
||
| 105 | $contentCreateStruct->ownerId = $versionCreator->id; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (isset($this->dsl['modification_date'])) { |
||
| 109 | $contentCreateStruct->modificationDate = $this->toDateTime($this->dsl['modification_date']); |
||
| 110 | } |
||
| 111 | |||
| 112 | // instantiate a location create struct from the parent location: |
||
| 113 | // BC |
||
| 114 | $locationId = isset($this->dsl['parent_location']) ? $this->dsl['parent_location'] : ( |
||
| 115 | isset($this->dsl['main_location']) ? $this->dsl['main_location'] : null |
||
| 116 | ); |
||
| 117 | // 1st resolve references |
||
| 118 | $locationId = $this->referenceResolver->resolveReference($locationId); |
||
| 119 | // 2nd allow to specify the location via remote_id |
||
| 120 | $locationId = $this->locationManager->matchLocationByKey($locationId)->id; |
||
| 121 | 1 | $locationCreateStruct = $locationService->newLocationCreateStruct($locationId); |
|
| 122 | |||
| 123 | 1 | if (isset($this->dsl['location_remote_id'])) { |
|
| 124 | $locationCreateStruct->remoteId = $this->dsl['location_remote_id']; |
||
| 125 | } |
||
| 126 | |||
| 127 | 1 | if (isset($this->dsl['priority'])) { |
|
| 128 | $locationCreateStruct->priority = $this->dsl['priority']; |
||
| 129 | 1 | } |
|
| 130 | 1 | ||
| 131 | if (isset($this->dsl['is_hidden'])) { |
||
| 132 | 1 | $locationCreateStruct->hidden = $this->dsl['is_hidden']; |
|
| 133 | 1 | } |
|
| 134 | 1 | ||
| 135 | if (isset($this->dsl['sort_field'])) { |
||
| 136 | 1 | $locationCreateStruct->sortField = $this->sortConverter->hash2SortField($this->dsl['sort_field']); |
|
| 137 | } else { |
||
| 138 | 1 | $locationCreateStruct->sortField = $contentType->defaultSortField; |
|
| 139 | 1 | } |
|
| 140 | 1 | ||
| 141 | if (isset($this->dsl['sort_order'])) { |
||
| 142 | 1 | $locationCreateStruct->sortOrder = $this->sortConverter->hash2SortOrder($this->dsl['sort_order']); |
|
| 143 | 1 | } else { |
|
| 144 | 1 | $locationCreateStruct->sortOrder = $contentType->defaultSortOrder; |
|
| 145 | } |
||
| 146 | 1 | ||
| 147 | $locations = array($locationCreateStruct); |
||
| 148 | |||
| 149 | // BC |
||
| 150 | $other_locations = isset($this->dsl['other_parent_locations']) ? $this->dsl['other_parent_locations'] : ( |
||
| 151 | isset($this->dsl['other_locations']) ? $this->dsl['other_locations'] : null |
||
| 152 | ); |
||
| 153 | if (isset($other_locations)) { |
||
| 154 | foreach ($other_locations as $locationId) { |
||
| 155 | $locationId = $this->referenceResolver->resolveReference($locationId); |
||
| 156 | $locationId = $this->locationManager->matchLocationByKey($locationId)->id; |
||
| 157 | $secondaryLocationCreateStruct = $locationService->newLocationCreateStruct($locationId); |
||
| 158 | array_push($locations, $secondaryLocationCreateStruct); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | 1 | ||
| 162 | 1 | // create a draft using the content and location create struct and publish it |
|
| 163 | 1 | $draft = $contentService->createContent($contentCreateStruct, $locations); |
|
| 164 | $content = $contentService->publishVersion($draft->versionInfo); |
||
| 165 | |||
| 166 | if (isset($this->dsl['object_states'])) { |
||
| 167 | $this->setObjectStates($content, $this->dsl['object_states']); |
||
| 168 | 3 | } |
|
| 169 | |||
| 170 | 3 | // 2nd part of the hack: re-set the content owner to its intended value |
|
| 171 | if (isset($this->dsl['version_creator']) || isset($this->dsl['publication_date'])) { |
||
| 172 | 3 | $contentMetaDataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
|
| 173 | |||
| 174 | 3 | if (isset($this->dsl['version_creator'])) { |
|
| 175 | $contentMetaDataUpdateStruct->ownerId = $realContentOwnerId; |
||
| 176 | 3 | } |
|
| 177 | 3 | if (isset($this->dsl['publication_date'])) { |
|
| 178 | $contentMetaDataUpdateStruct->publishedDate = $this->toDateTime($this->dsl['publication_date']); |
||
| 179 | } |
||
| 180 | |||
| 181 | 3 | $contentService->updateContentMetadata($content->contentInfo, $contentMetaDataUpdateStruct); |
|
| 182 | 3 | } |
|
| 183 | |||
| 184 | $this->setReferences($content); |
||
| 185 | |||
| 186 | return $content; |
||
| 187 | } |
||
| 188 | |||
| 189 | 3 | /** |
|
| 190 | * Handle the content update migration action type |
||
| 191 | 3 | * |
|
| 192 | * @todo handle updating of more metadata fields |
||
| 193 | */ |
||
| 194 | protected function update() |
||
| 195 | { |
||
| 196 | 3 | $contentService = $this->repository->getContentService(); |
|
| 197 | 1 | $contentTypeService = $this->repository->getContentTypeService(); |
|
| 198 | 1 | ||
| 199 | 1 | $contentCollection = $this->matchContents('update'); |
|
| 200 | |||
| 201 | if (count($contentCollection) > 1 && isset($this->dsl['references'])) { |
||
| 202 | 1 | throw new \Exception("Can not execute Content update because multiple contents match, and a references section is specified in the dsl. References can be set when only 1 content matches"); |
|
| 203 | } |
||
| 204 | 3 | ||
| 205 | $contentType = null; |
||
| 206 | |||
| 207 | 3 | foreach ($contentCollection as $key => $content) { |
|
| 208 | 3 | $contentInfo = $content->contentInfo; |
|
| 209 | 1 | ||
| 210 | 1 | if ($contentType == null) { |
|
| 211 | 1 | $contentType = $contentTypeService->loadContentType($contentInfo->contentTypeId); |
|
| 212 | 1 | } |
|
| 213 | 1 | ||
| 214 | 1 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
|
| 215 | 3 | ||
| 216 | 3 | if (isset($this->dsl['attributes'])) { |
|
| 217 | 3 | $this->setFields($contentUpdateStruct, $this->dsl['attributes'], $contentType); |
|
| 218 | } |
||
| 219 | 3 | ||
| 220 | $versionCreator = null; |
||
| 221 | 3 | if (isset($this->dsl['version_creator'])) { |
|
| 222 | $versionCreator = $this->getUser($this->dsl['version_creator']); |
||
| 223 | } |
||
| 224 | |||
| 225 | $draft = $contentService->createContentDraft($contentInfo, null, $versionCreator); |
||
| 226 | $contentService->updateContent($draft->versionInfo, $contentUpdateStruct); |
||
| 227 | $content = $contentService->publishVersion($draft->versionInfo); |
||
| 228 | |||
| 229 | if (isset($this->dsl['always_available']) || |
||
| 230 | isset($this->dsl['new_remote_id']) || |
||
| 231 | 4 | isset($this->dsl['owner']) || |
|
| 232 | isset($this->dsl['modification_date']) || |
||
| 233 | 4 | isset($this->dsl['publication_date'])) { |
|
| 234 | |||
| 235 | $contentMetaDataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
||
| 236 | 4 | ||
| 237 | if (isset($this->dsl['always_available'])) { |
||
| 238 | 4 | $contentMetaDataUpdateStruct->alwaysAvailable = $this->dsl['always_available']; |
|
| 239 | } |
||
| 240 | 4 | ||
| 241 | if (isset($this->dsl['new_remote_id'])) { |
||
| 242 | 1 | $contentMetaDataUpdateStruct->remoteId = $this->dsl['new_remote_id']; |
|
| 243 | 1 | } |
|
| 244 | |||
| 245 | 4 | View Code Duplication | if (isset($this->dsl['owner'])) { |
| 246 | 3 | $owner = $this->getUser($this->dsl['owner']); |
|
| 247 | $contentMetaDataUpdateStruct->ownerId = $owner->id; |
||
| 248 | 4 | } |
|
| 249 | 4 | ||
| 250 | 4 | if (isset($this->dsl['modification_date'])) { |
|
| 251 | $contentMetaDataUpdateStruct->modificationDate = $this->toDateTime($this->dsl['modification_date']); |
||
| 252 | } |
||
| 253 | |||
| 254 | if (isset($this->dsl['publication_date'])) { |
||
| 255 | $contentMetaDataUpdateStruct->publishedDate = $this->toDateTime($this->dsl['publication_date']); |
||
| 256 | } |
||
| 257 | |||
| 258 | $content = $contentService->updateContentMetadata($content->contentInfo, $contentMetaDataUpdateStruct); |
||
| 259 | } |
||
| 260 | |||
| 261 | if (isset($this->dsl['section'])) { |
||
| 262 | 4 | $this->setSection($content, $this->dsl['section']); |
|
| 263 | } |
||
| 264 | 4 | ||
| 265 | 4 | if (isset($this->dsl['object_states'])) { |
|
| 266 | $this->setObjectStates($content, $this->dsl['object_states']); |
||
| 267 | } |
||
| 268 | 4 | ||
| 269 | 4 | $contentCollection[$key] = $content; |
|
| 270 | 4 | } |
|
| 271 | |||
| 272 | 4 | $this->setReferences($contentCollection); |
|
| 273 | 1 | ||
| 274 | 1 | return $contentCollection; |
|
| 275 | } |
||
| 276 | 4 | ||
| 277 | /** |
||
| 278 | * Handle the content delete migration action type |
||
| 279 | */ |
||
| 280 | protected function delete() |
||
| 281 | { |
||
| 282 | $contentService = $this->repository->getContentService(); |
||
| 283 | |||
| 284 | $contentCollection = $this->matchContents('delete'); |
||
| 285 | |||
| 286 | foreach ($contentCollection as $content) { |
||
| 287 | 1 | try { |
|
| 288 | $contentService->deleteContent($content->contentInfo); |
||
| 289 | 1 | } catch (NotFoundException $e) { |
|
| 290 | 1 | // Someone else (or even us, by virtue of location tree?) removed the content which we found just a |
|
| 291 | // second ago. We can safely ignore this |
||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | return $contentCollection; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param string $action |
||
| 300 | * @return ContentCollection |
||
| 301 | * @throws \Exception |
||
| 302 | 3 | */ |
|
| 303 | View Code Duplication | protected function matchContents($action) |
|
| 304 | 3 | { |
|
| 305 | 2 | if (!isset($this->dsl['object_id']) && !isset($this->dsl['remote_id']) && !isset($this->dsl['match'])) { |
|
| 306 | throw new \Exception("The ID or remote ID of an object or a Match Condition is required to $action a new location."); |
||
| 307 | } |
||
| 308 | 3 | ||
| 309 | // Backwards compat |
||
| 310 | if (!isset($this->dsl['match'])) { |
||
| 311 | if (isset($this->dsl['object_id'])) { |
||
| 312 | $this->dsl['match'] = array('content_id' => $this->dsl['object_id']); |
||
| 313 | } elseif (isset($this->dsl['remote_id'])) { |
||
| 314 | $this->dsl['match'] = array('content_remote_id' => $this->dsl['remote_id']); |
||
| 315 | 3 | } |
|
| 316 | } |
||
| 317 | 3 | ||
| 318 | 3 | $match = $this->dsl['match']; |
|
| 319 | 3 | ||
| 320 | 3 | // convert the references passed in the match |
|
| 321 | 3 | foreach ($match as $condition => $values) { |
|
| 322 | 3 | if (is_array($values)) { |
|
| 323 | 2 | foreach ($values as $position => $value) { |
|
| 324 | 2 | $match[$condition][$position] = $this->referenceResolver->resolveReference($value); |
|
| 325 | 2 | } |
|
| 326 | 1 | } else { |
|
| 327 | 1 | $match[$condition] = $this->referenceResolver->resolveReference($values); |
|
| 328 | 1 | } |
|
| 329 | 1 | } |
|
| 330 | |||
| 331 | return $this->contentMatcher->match($match); |
||
| 332 | } |
||
| 333 | 3 | ||
| 334 | /** |
||
| 335 | 3 | * Helper function to set the fields of a ContentCreateStruct based on the DSL attribute settings. |
|
| 336 | 3 | * |
|
| 337 | * @param ContentCreateStruct|ContentUpdateStruct $createOrUpdateStruct |
||
| 338 | 3 | * @param ContentType $contentType |
|
| 339 | * @param array $fields see description of expected format in code below |
||
| 340 | * @throws \Exception |
||
| 341 | */ |
||
| 342 | protected function setFields($createOrUpdateStruct, array $fields, ContentType $contentType) |
||
| 343 | { |
||
| 344 | $i = 0; |
||
| 345 | // the 'easy' yml: key = field name, value = value |
||
| 346 | // deprecated: the 'legacy' yml: key = numerical index, value = array ( field name => value ) |
||
| 347 | foreach ($fields as $key => $field) { |
||
| 348 | |||
| 349 | if ($key === $i && is_array($field) && count($field) == 1) { |
||
| 350 | // each $field is one key value pair |
||
| 351 | // eg.: $field = array($fieldIdentifier => $fieldValue) |
||
| 352 | reset($field); |
||
| 353 | $fieldIdentifier = key($field); |
||
| 354 | $fieldValue = $field[$fieldIdentifier]; |
||
| 355 | } else { |
||
| 356 | $fieldIdentifier = $key; |
||
| 357 | $fieldValue = $field; |
||
| 358 | } |
||
| 359 | |||
| 360 | if (!isset($contentType->fieldDefinitionsByIdentifier[$fieldIdentifier])) { |
||
| 361 | throw new \Exception("Field '$fieldIdentifier' is not present in field type '{$contentType->identifier}'"); |
||
| 362 | } |
||
| 363 | |||
| 364 | $fieldDefinition = $contentType->fieldDefinitionsByIdentifier[$fieldIdentifier]; |
||
| 365 | $fieldValue = $this->getFieldValue($fieldValue, $fieldDefinition, $contentType->identifier, $this->context); |
||
| 366 | |||
| 367 | $createOrUpdateStruct->setField($fieldIdentifier, $fieldValue, $this->getLanguageCode()); |
||
| 368 | |||
| 369 | $i++; |
||
| 370 | } |
||
| 371 | } |
||
| 372 | |||
| 373 | View Code Duplication | protected function setSection(Content $content, $sectionKey) |
|
| 374 | { |
||
| 375 | $sectionKey = $this->referenceResolver->resolveReference($sectionKey); |
||
| 376 | $section = $this->sectionMatcher->matchOneByKey($sectionKey); |
||
| 377 | |||
| 378 | $sectionService = $this->repository->getSectionService(); |
||
| 379 | $sectionService->assignSection($content->contentInfo, $section); |
||
| 380 | } |
||
| 381 | |||
| 382 | protected function setObjectStates(Content $content, array $stateKeys) |
||
| 383 | { |
||
| 384 | foreach ($stateKeys as $stateKey) { |
||
| 385 | $stateKey = $this->referenceResolver->resolveReference($stateKey); |
||
| 386 | /** @var \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $state */ |
||
| 387 | $state = $this->objectStateMatcher->matchOneByKey($stateKey); |
||
| 388 | |||
| 389 | $stateService = $this->repository->getObjectStateService(); |
||
| 390 | $stateService->setContentState($content->contentInfo, $state->getObjectStateGroup(), $state); |
||
| 391 | } |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Create the field value from the migration definition hash |
||
| 396 | * |
||
| 397 | * @param mixed $value |
||
| 398 | * @param FieldDefinition $fieldDefinition |
||
| 399 | * @param string $contentTypeIdentifier |
||
| 400 | * @param array $context |
||
| 401 | * @throws \InvalidArgumentException |
||
| 402 | * @return mixed |
||
| 403 | */ |
||
| 404 | protected function getFieldValue($value, FieldDefinition $fieldDefinition, $contentTypeIdentifier, array $context = array()) |
||
| 405 | { |
||
| 406 | $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier; |
||
| 407 | if (is_array($value) || $this->complexFieldManager->managesField($fieldTypeIdentifier, $contentTypeIdentifier)) { |
||
| 408 | // inject info about the current content type and field into the context |
||
| 409 | $context['contentTypeIdentifier'] = $contentTypeIdentifier; |
||
| 410 | $context['fieldIdentifier'] = $fieldDefinition->identifier; |
||
| 411 | return $this->complexFieldManager->hashToFieldValue($fieldTypeIdentifier, $contentTypeIdentifier, $value, $context); |
||
| 412 | } |
||
| 413 | |||
| 414 | return $this->getSingleFieldValue($value, $fieldDefinition, $contentTypeIdentifier, $context); |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Create the field value for a primitive field from the migration definition hash |
||
| 419 | * |
||
| 420 | * @param mixed $value |
||
| 421 | * @param FieldDefinition $fieldDefinition |
||
| 422 | * @param string $contentTypeIdentifier |
||
| 423 | * @param array $context |
||
| 424 | * @throws \InvalidArgumentException |
||
| 425 | * @return mixed |
||
| 426 | */ |
||
| 427 | protected function getSingleFieldValue($value, FieldDefinition $fieldDefinition, $contentTypeIdentifier, array $context = array()) |
||
| 428 | { |
||
| 429 | // booleans were handled here. They are now handled as complextypes |
||
| 430 | |||
| 431 | // q: do we really want this to happen by default on all scalar field values? |
||
| 432 | // Note: if you want this *not* to happen, register a complex field for your scalar field... |
||
| 433 | $value = $this->referenceResolver->resolveReference($value); |
||
| 434 | |||
| 435 | return $value; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Load user using either login, email, id - resolving eventual references |
||
| 440 | * @param int|string $userKey |
||
| 441 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
| 442 | */ |
||
| 443 | protected function getUser($userKey) |
||
| 444 | { |
||
| 445 | $userKey = $this->referenceResolver->resolveReference($userKey); |
||
| 446 | return $this->userMatcher->matchOneByKey($userKey); |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Sets references to certain content attributes. |
||
| 451 | * |
||
| 452 | * @param \eZ\Publish\API\Repository\Values\Content\Content|ContentCollection $content |
||
| 453 | * @throws \InvalidArgumentException When trying to set a reference to an unsupported attribute |
||
| 454 | * @return boolean |
||
| 455 | * |
||
| 456 | * @todo add support for other attributes: contentTypeId, contentTypeIdentifier, section, etc... ? |
||
| 457 | */ |
||
| 458 | protected function setReferences($content) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @param int|string $date if integer, we assume a timestamp |
||
| 502 | * @return \DateTime |
||
| 503 | */ |
||
| 504 | protected function toDateTime($date) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param array $matchCondition |
||
| 515 | * @param string $mode |
||
| 516 | * @throws \Exception |
||
| 517 | * @return array |
||
| 518 | * |
||
| 519 | * @todo add support for dumping all object languages |
||
| 520 | * @todo add 2ndary locations when in 'update' mode |
||
| 521 | * @todo add dumping of sort_field and sort_order for 2ndary locations |
||
| 522 | */ |
||
| 523 | public function generateMigration(array $matchCondition, $mode) |
||
| 624 | } |
||
| 625 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.