In some situations, orphan article elements can remain in database after articles are purged (as explained in Photocaptions survive article deletion), and prevent purging of linked images.
You may want to get rid of such orphan elements, but it is better not to use SQL queries, as elements data is spread across many tables and incomplete deletions can leave "dirty" data.
This topic explains step-by-step how to build a XPath expression to clean such orphans, both article elements and referenced images.
Let's start with an article that has a photoCaption element and a linked image. Open the article in Ted4, open the photoCaption element and then display its properties. On the Info tab find the ID of the photoCaption article element. Let's assume the ID is 130031.
Open the browser and sign in to GN4. Duplicate the window, and then paste in the address bar the following: http://main.teradp.com/GN4/do.ashx?cmd=objsNav&ids=130031&options=referencing&max=6 The display will be something similar to this: If you look at the <nav:refObject idref="obj129847"> node you'll find the id of the parent article. Therefore, the XPath that connects a photocaption with its article is: gn4:photoCaption/nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject How we got it? Let's cut out of the above XML all parts that are not important for this task, and then let's examine what remained, starting from nav:referencing - you see the sequence of nodes specified above in the XPath: <photoCaption nav:objectType="photoCaption"> <nav:objectTypeAttrs ...></nav:objectTypeAttrs> <nav:referencing> <nav:parentBy attrName="article.txts"> <nav:refs handle="1"> <nav:refObject idref="obj129847"> </nav:refObject> </nav:refs> </nav:parentBy> Now, this handles the photoCaption. What about other orphans? The XPath that connects any article element with its article is: gn4:txt/nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject However, we're looking for article elements that do not have a parent article, therefore, let's "negate" the condition with a not enclosing all: gn4:txt[not(nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject)] However, we have to think also on images, linked to orphan photocaptions. The XPath to find such items is more complicated: gn4:img[nav:referencing/nav:referencingBy[@attrName="photoCaption.ref"]/nav:refs/nav:refObject/gn4:photoCaption[not(nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject)]] Let's summarize: Xpath to locate all orphan photoCaption elements gn4:photoCaption[not(nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject)] Xpath to locate all orphan article elements of any type gn4:txt[not(nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject)] Xpath to locate all images linked to orphan photoCaption elements Note: The complete list of navigation options: http://tech.teradp.com/tech/html/gn4/docs/VSdoc/index.html#frlrfTeraDPGN4GNClientDataNavigatorOptionClassTopic.html |
Now, one can write a small VB.Net script to generate the list of ids of the orphan elements, and run it from the Script editor in Ted4 or Fred4:
|
If you want to save the content of orphan items before deleting them, use the following cmd4 command (all in one line): cmd4 get -out c:\temp\orphans.xml -conditions "gn4:txt[not(nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject)]" -srvurl http://myhost.com/GN4/Adminsrv.asmx -UserName xxxx -password yyyy Note about the -srvurl parameter In version 2.5 and newer, the URL is http://<myserver>/<myWebApp>/. In version prior to 2.5, the URL is the address of the Web service to connect to, e.g. http://<myserver>/<myWebApp>/Adminsrv.asmx. The result may be: C:\tera\GN4\main\bin>cmd4 get -conditions "gn4:txt[not(nav:referencing/nav:paren tBy[@attrName='article.txts']/nav:refs/nav:refObject)]" -username xxxx -passwor d yyyy -out c:\temp\exportedorphans.xml -srvurl http://main.teradp.com/gn4/admin srv.asmx Cmd4 version 2.1.2084.0 GN4 command-line client Copyright © 2006 - 2014 Tera DP srl Language en-US
Getting object(s)... Saving object(s) to file 'c:\temp\exportedorphans.xml'... The exported content looks like: |
When you want to spike orphan items, you need to do it in a correct order: first spike the images, linked to the orphan photocaptions and their geometries; then, spike the other orphan elements, if any. Therefore, first execute the command to spike images and geometries, linked to orphan photocaptions(all in one line!): srv4 spike -conditions "gn4:img[nav:referencing/nav:referencingBy[@attrName='photoCaption.ref'] /nav:refs/nav:refObject/gn4:photoCaption[not(nav:referencing/nav:parentBy[@attrName='article.txts'] /nav:refs/nav:refObject)]]" -extend photoCaption.ref,txtGeometry.txtRef –recurse Then, execute the command to spike other orphan elements (all in one line!): srv4 spike -conditions "gn4:txt[not(nav:referencing/nav:parentBy[@attrName='article.txts']/nav:refs/nav:refObject)]" -extend txtGeometry.txtRef |