Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tasks to clean up DB inconsistencies: children with container which is no longer a gridelement (orphans) #58

Open
sypets opened this issue Nov 22, 2023 · 0 comments

Comments

@sypets
Copy link
Contributor

sypets commented Nov 22, 2023

The following inconsistency should not happen and will cause existing elements to disappear (in list and page view):

  • elements have tx_gridelements_container != 0 and colpos=-1, but the container is not a gridelement type

Reproduce

  1. Create a gridelement with children
  2. change the CType of the gridelement (e.g. to textmedia).

Result: The children will then "disappear" in list and page view

SQL select for showing these records

SELECT t1.uid,t1.pid,t1.sys_language_uid,t1.ctype,t1.header,t2.uid,t2.pid,t2.header,t2.ctype 
    FROM tt_content t1 
    INNER JOIN tt_content t2 
        ON t1.tx_gridelements_container=t2.uid
    WHERE t1.colpos=-1 
        AND t1.tx_gridelements_container != 0
       AND  t2.ctype NOT LIKE 'gridelements_pi1'
       AND NOT t1.deleted
       AND NOT t2.deleted;
UPDATE tt_content t1 
    INNER JOIN tt_content t2 
        ON t1.tx_gridelements_container=t2.uid
    SET t1.colpos=0,t1.tx_gridelements_container=0    
    WHERE t1.colpos=-1 
        AND t1.tx_gridelements_container != 0
       AND  t2.ctype NOT LIKE 'gridelements_pi1'
       AND NOT t1.deleted
       AND NOT t2.deleted;

Possible solutions

  1. Create a scheduler task to clean up existing records. For these records, set colpos to 0 (or the default) and tx_gridelements_container to 0. In general, if the records are cleaned up, I think it is a good idea to make the elements "hidden" by default, otherwise elements will suddenly "reappear" which were formerly hidden.

  2. or prevent this from happening: it should not be possible to change the ctype

  3. or if the ctype is changed, the elements should be released from the parent or deleted

Related

sypets added a commit to sypets/gridelements that referenced this issue Nov 22, 2023
If the CType of a gridelement is changed to a non-gridelement,
existing children will be orphaned. They still exist in the
database, but are not visible in the backend list or page view.

This can now be fixed via a scheduler task:
The connection between the (formerly) gridelements container
and child is severed by setting tx_gridelements_container to 0 and
setting the colpos to the value of the formerly gridelements
parent.

Related: CodersCare#58
@sypets sypets changed the title Add tasks to clean up DB inconsistencies Add tasks to clean up DB inconsistencies: children with container which is no longer a gridelement (orphans) Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant