Code Duplication    Length = 39-39 lines in 2 locations

Classes/Controller/ContentController.php 2 locations

@@ 395-433 (lines=39) @@
392
     * @param array $matches
393
     * @return string
394
     */
395
    public function deleteAction(array $matches = array())
396
    {
397
398
        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
399
400
        // Fetch objects via the Content Service.
401
        $contentService = $this->getContentService()->findBy($matcher);
402
403
        // Compute the label field name of the table.
404
        $tableTitleField = Tca::table()->getLabelField();
405
406
        // Get result object for storing data along the processing.
407
        $result = $this->getJsonResult();
408
        $result->setNumberOfObjects($contentService->getNumberOfObjects());
409
410
        foreach ($contentService->getObjects() as $object) {
411
412
            // Store the first object, so that the delete message can be more explicit when deleting only one record.
413
            if ($contentService->getNumberOfObjects() === 1) {
414
                $tableTitleValue = $object[$tableTitleField];
415
                $processedObjectData = array(
416
                    'uid' => $object->getUid(),
417
                    'name' => $tableTitleValue,
418
                );
419
                $result->setProcessedObject($processedObjectData);
420
            }
421
422
            // Properly delete object.
423
            ContentRepositoryFactory::getInstance()->remove($object);
424
425
            // Get the possible error messages and store them.
426
            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
427
            $result->addErrorMessages($errorMessages);
428
        }
429
430
        // Set the result and render the JSON view.
431
        $this->getJsonView()->setResult($result);
432
        return $this->getJsonView()->render();
433
    }
434
435
    /**
436
     * Retrieve Content objects first according to matching criteria and then "copy" them.
@@ 513-551 (lines=39) @@
510
     * @param array $matches
511
     * @return string
512
     */
513
    public function moveAction($target, array $matches = array())
514
    {
515
516
        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches);
517
518
        // Fetch objects via the Content Service.
519
        $contentService = $this->getContentService()->findBy($matcher);
520
521
        // Compute the label field name of the table.
522
        $tableTitleField = Tca::table()->getLabelField();
523
524
        // Get result object for storing data along the processing.
525
        $result = $this->getJsonResult();
526
        $result->setNumberOfObjects($contentService->getNumberOfObjects());
527
528
        foreach ($contentService->getObjects() as $object) {
529
530
            // Store the first object, so that the "action" message can be more explicit when deleting only one record.
531
            if ($contentService->getNumberOfObjects() === 1) {
532
                $tableTitleValue = $object[$tableTitleField];
533
                $processedObjectData = array(
534
                    'uid' => $object->getUid(),
535
                    'name' => $tableTitleValue,
536
                );
537
                $result->setProcessedObject($processedObjectData);
538
            }
539
540
            // Work out the object.
541
            ContentRepositoryFactory::getInstance()->move($object, $target);
542
543
            // Get the possible error messages and store them.
544
            $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
545
            $result->addErrorMessages($errorMessages);
546
        }
547
548
        // Set the result and render the JSON view.
549
        $this->getJsonView()->setResult($result);
550
        return $this->getJsonView()->render();
551
    }
552
553
    /**
554
     * Retrieve Content objects from the Clipboard then "move" them according to the target.