civca
Returning Observer

Delete broken references

Jump to solution

Is there any why to delete all broken references from Page content area without opening page by page and delete them manually from input fields?

I tried something with script trough API, going trough Page content, page by page, section by section, getReferences(), check if it is broken then remove it from section, save section but without success, broken references are still there.

 

Set<ReferenceEntry> references = section.getReferences();
Iterator<ReferenceEntry> iterator = references.iterator();
while(iterator.hasNext()) {
ReferenceEntry referenceEntry = iterator.next();
if(referenceEntry.isBroken()) {
iterator.remove();
}
}
section.save();

 Also I tried to remove all references from section, then add new filtered references Set (without broken ones) and save section, but again without success.

0 Kudos
1 Solution

Accepted Solutions
hoebbel
Crownpeak employee

Dear civca,

a broken reference occurs when a node that no longer exists is selected within an input component.
If you now delete the broken reference, the inconsistent content of the input component remains, of course. When you save, the references of the current node are recalculated and the broken reference is created again.
So instead of deleting the broken reference, you have to delete the inconsistent value in the input component. When you save afterwards, the broken reference will be removed automatically.

Or to put it in other words - the broken reference is not the problem, but the incorrect content of the corresponding input component.

best regards,
Holger

 

View solution in original post

6 Replies
hoebbel
Crownpeak employee

Dear civca,

a broken reference occurs when a node that no longer exists is selected within an input component.
If you now delete the broken reference, the inconsistent content of the input component remains, of course. When you save, the references of the current node are recalculated and the broken reference is created again.
So instead of deleting the broken reference, you have to delete the inconsistent value in the input component. When you save afterwards, the broken reference will be removed automatically.

Or to put it in other words - the broken reference is not the problem, but the incorrect content of the corresponding input component.

best regards,
Holger

 

civca
Returning Observer

Thank you hoebbel on you quick answer.

I alreadysupposed that it needs to be done in the way that you described. Remove specific incorrect content instead of remove broken reference entry.

Then it is much more complicated because a lot of input fields can contain refereneces fs_reference, cms_input_link, cms_input_dom can, fs_catalog...

 

0 Kudos

I know it may not be helpful for the current mess you are facing, but I suggest that you focus on the root cause: Deleting referenced content. This is only allowed for project admins and only after acknowledging that the deletion will cause broken references. Maybe you've got too many editors with the permission to do this? In my opinion there is no way around that editors have to manually check existing references to the content they are deleting. Even if you come up with an automated clearing of "dead references", the state will still be semantically inconsistent.

Peter

You are right that attention should be paid to deleting referenced content. Thanks for the advice, but I think I'm close to a solution.

I go through all the pages, call save () over a particular page, if I catch the exception ElementValidationReportsException then from that exception I come to the section and the element that contains the broken references, with a little manipulation I found a way to get all that information. I think only FS_REFERENCE, CMS_INPUT_LINK, CMS_INPUT_DOM and FS_CATALOG (depending on the template) can contain broken references.

0 Kudos
hoebbel
Crownpeak employee

Dear civca,

you don't need to save the page, you can just use the validation agent to validate it:
https://docs.e-spirit.com/odfs/dev/de/espirit/firstspirit/agency/ValidationAgent.html

Hint: If you save the page, you create a new revision of it. If you do this far too often, this might result in a slight performance deterioration.

And another hint: FS_INDEX can also obtain a broken reference (depending on the DAP used, e.g. if the referred dataset has been deleted)

Best regards,
Holger

civca
Returning Observer

Thanks hoebbel, I will consider and apply what you suggest.

best regards

0 Kudos