Issue Bug Rejected

#106211'tstamp' is hardcoded

Claus Harup 02/19/25, 13:57 updated 02/20/25, 13:08

Description

In LinkAnalyzer.php function recheckLinks ‘tstamp’ is hardcoded.

        $row = $queryBuilder->select('uid', 'pid', $GLOBALS['TCA'][$table]['ctrl']['label'], $field, 'tstamp')
        ->from($table)
        ->where(
         $queryBuilder->expr()->eq(
                    'uid',
                    $queryBuilder->createNamedParameter($recordUid, Connection::PARAM_INT)
                )
            )
            ->executeQuery()
            ->fetchAssociative();

        if (!$row) {
            // missing record: remove existing links
            $this->brokenLinkRepository->removeBrokenLinksForRecord($table, $recordUid);
            return;
        }
        if (($row['tstamp'] ?? 0) && $timestamp && ((int)($row['tstamp']) < $timestamp)) {
            // timestamp has not changed: no need to recheck
            return;
        }

‘tstamp’ should be derived from TCA[‘ctrl’][‘tstamp’]….

Reviews 0

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

History 10

  1. Georg Ringer commented and changed assigned to Georg Ringer 02/19/25, 14:19

    fixed in 13.4 at least, will check if we backport that to 12

  2. Claus Harup commented 02/19/25, 14:22

    Georg Ringer wrote in #note-1:
    > fixed in 13.4 at least, will check if we backport that to 12

    Brillant!!

  3. Georg Ringer commented and changed status New Rejected 02/19/25, 14:51

    just checked with benni. There are a lot of places where this is hardcoded and this is fixed in 13 using the schema API.
    therefore we won’t fix it in 12.

    hope that is still ok for you

  4. Claus Harup commented 02/19/25, 14:54

    Georg Ringer wrote in #note-3:
    > just checked with benni. There are a lot of places where this is hardcoded and this is fixed in 13 using the schema API.
    > therefore we won’t fix it in 12.
    >
    > hope that is still ok for you

    Unfortunately I cannot add the link validator functionality to my clients…. :-(

  5. Claus Harup commented 02/19/25, 14:57

    This would fix it :-)

            $tstamp = $GLOBALS['TCA'][$table]['ctrl']['tstamp'];
            $row = $queryBuilder->select('uid', 'pid', $GLOBALS['TCA'][$table]['ctrl']['label'], $field, $tstamp)
            ->from($table)
            ->where(
             $queryBuilder->expr()->eq(
                        'uid',
                        $queryBuilder->createNamedParameter($recordUid, Connection::PARAM_INT)
                    )
                )
                ->executeQuery()
                ->fetchAssociative();
    
            if (!$row) {
                // missing record: remove existing links
                $this->brokenLinkRepository->removeBrokenLinksForRecord($table, $recordUid);
                return;
            }
            if (($row[$tstamp] ?? 0) && $timestamp && ((int)($row[$tstamp]) < $timestamp)) {
                // timestamp has not changed: no need to recheck
                return;
            }
  6. Garvin Hicking commented 02/20/25, 01:12

    clausharup claush (that would only work when ‘tstamp’ is really available, it would still fail on tables having no timestamp at all)

  7. Claus Harup commented 02/20/25, 07:26

    There you go :-)

            ...
    
            $selects = ['uid', 'pid', $GLOBALS['TCA'][$table]['ctrl']['label'], $field];
            $tstamp = $GLOBALS['TCA'][$table]['ctrl']['tstamp'] ?? false;
    
            if ($tstamp) {
                $selects[] = $tstamp;
            }
    
            $row = $queryBuilder->select(...$selects)
                ->from($table)
                ->where(
                    $queryBuilder->expr()->eq(
                        'uid',
                        $queryBuilder->createNamedParameter($recordUid, Connection::PARAM_INT)
                    )
                )
                ->executeQuery()
                ->fetchAssociative();
    
            if (!$row) {
                // missing record: remove existing links
                $this->brokenLinkRepository->removeBrokenLinksForRecord($table, $recordUid);
                return;
            }
    
            if ($tstamp) {
                if (($row[$tstamp] ?? 0) && $timestamp && ((int)($row[$tstamp]) < $timestamp)) {
                    // timestamp has not changed: no need to recheck
                    return;
                }
            }
            ...
  8. Garvin Hicking commented 02/20/25, 07:41

    Great, thank you for sharing this so that users affected by this in v12 could patch it like this!

  9. Georg Ringer commented 02/20/25, 08:09

    just a final comment: use XCLASS or composer patches to provide that change to your site. or update to v13 in the long run.

  10. Claus Harup commented 02/20/25, 13:08

    Everything works like a charm using composer patch!!!