TYPO3: No content edit permission

On a TYPO3 v12 system one of our customers got this error when editing a mask content element:

No content edit permission for user 23 on page 42 1437679657

Exception code 1437679657 has the following comment in the source code:

A non page record is edited. If there is a parent page row, check content edit right of user

In my case it was a sys_file_reference entry that had a different pid than the tt_content element it was linked to. I have no idea how that happened; most likely a bug when copying or moving content elements in early stages of the project when things were in flux.

The backend user had access to the page with the content element, but not to the pid of the sys_file_reference record.

Solution

Find all affected content elements:

SELECT sfr.uid, sfr.pid AS sfr_pid, tt_content.pid AS t_pid, tt_content.CType
  FROM sys_file_reference AS sfr
  JOIN tt_content ON tt_content.uid = sfr.uid_foreign
WHERE
  sfr.tablenames = "tt_content"
  AND sfr.pid != tt_content.pid
LIMIT 100

Now fix the file references:

UPDATE sys_file_reference
  INNER JOIN tt_content ON sys_file_reference.uid_foreign = tt_content.uid
SET
 sys_file_reference.pid = tt_content.pid,
 sys_file_reference.tstamp = UNIX_TIMESTAMP()
WHERE
 sys_file_reference.pid != tt_content.pid
 AND sys_file_reference.tablenames = "tt_content"

And in the end check if the records have the correct page IDs now:

SELECT
  sys_file_reference.uid AS sfr_uid,
  sys_file_reference.pid AS sfr_pid,
  tt_content.uid AS tt_uid,
  tt_content.pid AS tt_pid
FROM sys_file_reference, tt_content
WHERE
  tt_content.uid = sys_file_reference.uid_foreign
  AND sys_file_reference.tablenames = "tt_content"
  AND sys_file_reference.uid IN (94,95,96,97)

Written by Christian Weiske.

Comments? Please send an e-mail.