Issue Bug Closed

#82784DataHandler: copyRecords doesn't set sorting correctly for negative $destPid

Sebastian Michaelsen 10/17/17, 15:52 updated 08/24/26, 17:26

Description

In DataHandler->copyRecord() accepts a $destPid which (according to the phpDoc) can either contain a page id or (indicated by a negative number) a content uid after which the source record is copied to. This “convention” is also used in DataHandler->moveRecord().

However DataHandler->copyRecord() does not implement the functionality. Only DataHandler->moveRecord() does.

How to reproduce:

            $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
            $data = [
                'tt_content' => [
                    $sourceContentUid=> [
                        'copy' => ($targetContentUid * -1),
                    ],
                ],
            ];
            $dataHandler->start([], $data);
            $dataHandler->process_cmdmap();

The copied element will just receive the sorting value of the source element instead of being sorted after the target content element.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 4

  1. Coders.Care Extension Team commented <span data-processor="relativetime" data-value="2017-10-17T20:25:20+00:00" > 10/17/17, 20:25 </span>

    AFAICS sorting is done in process_datamap, which is called by process_cmdmap in case of ‘copy’ but not in case of ‘move’, since usually there is no data to be processed, when moving a record.

    So sorting should be handled at lines 1058 to 1082 of \TYPO3\CMS\Core\DataHandling\DataHandler

    // The $pid_value is now the numerical pid at this point
    if ($OK) {
        $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
        // Points to a page on which to insert the element, possibly in the top of the page
        if ($pid_value >= 0) {
            // If this table is sorted we better find the top sorting number
            if ($sortRow) {
                $fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value);
            }
            // The numerical pid is inserted in the data array
            $fieldArray['pid'] = $pid_value;
        } else {
            // points to another record before ifself
            // If this table is sorted we better find the top sorting number
            if ($sortRow) {
                // Because $pid_value is < 0, getSortNumber returns an array
                $tempArray = $this->getSortNumber($table, 0, $pid_value);
                $fieldArray['pid'] = $tempArray['pid'];
                $fieldArray[$sortRow] = $tempArray['sortNumber'];
            } else {
                // Here we fetch the PID of the record that we point to...
                $tempdata = $this->recordInfo($table, abs($pid_value), 'pid');
                $fieldArray['pid'] = $tempdata['pid'];
            }
        }
    }
  2. Oliver Hader commented and changed status New Accepted <span data-processor="relativetime" data-value="2018-01-23T20:41:12+00:00" > 01/23/18, 20:41 </span>

    Should be verified with an additional DataHandler functional test using negative PID values

  3. Benjamin Kott commented and changed status Accepted Closed <span data-processor="relativetime" data-value="2026-08-24T17:26:56+00:00" > 08/24/26, 17:26 </span>

    DataHandler: copyRecords doesn’t set sorting correctly for negative $destPid
    Resolved by: no single commit identified. Not reproducible on main (15.0.0-dev); verified by functional test — copying tt_content 298 with copy => -299 yields pid 89, sorting 896, correctly placed after 299.