Fix Assets Inconsistencies - Some fixes to accomplish a successful dotCMS upgrade
During a dotCMS upgrade for a specific Client, two different and non-related issues arose when executing Fix Assets Inconsistencies functionality from System->Maintenance tab. These problems were fixed via hotfix mechanism but they may be fixed at dotCMS core level:
- Existing SELECT queries on fix-task "FixTask00004CheckFileAssetsInconsistencies" hung because of usage of "NOT IN" clause. Using "NOT EXISTS" instead of "NOT IN" proved to fix the problem and allowed the system not to hang while achieving an equivalent behavior. It was also noticed/discussed that this fix-task might be removed from the system because:
1.1. UPDATE query subsequently executed over "fileassetversioninfo" table is not really targeting any records since the "SELECT" query implicitly returns "identifier" rows that are not associated to any "fileassetversioninfo" records. For the fix-task to achieve its goal, it looks that query should be INSERT instead of UPDATE. However, look at following section (1.2) 1.2. Another existing fix-task "FixTask00070FixVersionInfo" seems to be already addressing the same goal of the fix-task in question with a more generic approach and a better performance. That is, it does INSERT or UPDATE over "fileassetversioninfo" table depending on whether the record exists or not. It seems there is duplicate functionality between both fix-tasks
- Existing records in "identifier" table "corrupted" with a empty/null PARENT-PATH caused the fix-task "FixTask00090RecreateMissingFoldersInParentPath" to break because of the check/validation/enforcement performed against PARENT-PATH at this line. The check/validation/enforcement for a not empty/null PARENT-PATH is right. That is, every valid "identifier" records should have a non empty/null PARENT-PATH. However, in our case, the fact of apparently corrupted/invalid data is needed to be taken into account: on a Client's database, there were found 3 invalid "identifier" records (with an empty PARENT-PATH). Thus:
2.1. This problem may be fixed by a new fix-task that either removes or fixes invalid "identifier" records. This new fix-task (ie. "FixTask00085FixEmptyParentPathInIdentifiers") should execute prior to the fix-task in question 2.1. The purpose of the new fix-task is to either remove (DELETE) invalid "identifier" records or to fix (UPDATE) empty/null PARENT-PATH to a valid value (ie. "/"). Further discussion might take place to decide what is more convenient: DELETE vs. UPDATE (ie. Potential Loss of Data vs. Preserving Corrupted Data). In our case and due to time constraints, problem was fixed with UPDATE approach.
The fix for this issue may be borrowed from hot-fix at https://github.com/dotCMS/support/tree/master/hotfixes/hotfix-GIT-10861_v3.7.1. Also, the original Support ticket may be accessed at https://my.dotcms.com/tickets/detail.dot?id=196f6f8a-e468-4f2d-83ae-d283ee4fb6e6