Friday, March 4, 2011

Camera Flash Eye Damage

Cancellare programmaticamente un documento

Ho passato il pomeriggio a bestemmiare in tutte le lingue che conosco e a giudicare dagli sguardi che mi circondano, penso di aver raggiunto livelli da "Esorcista" (mancava solo il getto di vomito verde).
Non รจ che dovevo fare tutto sto lavoro poi... Avendo caricato vari nodi dalla cache e individuato quello da cancellare, utilizzavo il metodo delete() sul documento e ... subito dopo il postback mi ritrovavo il nodo vivo (solo che ripubblicando il sito, spariva come doveva fare).
Il codice assomigliava un po' a questo:
int idNode = 1111;
doc docDaCancellare = new Document(idNode);

docDaCancellare.delete();
umbraco.library.RefreshContent();

but nothing to make that maldedetto node (though physically gone from the back-end) kept coming back into my application as if nothing had happened, despite charging a DataTable with all the children of the parent node reloaded.
Eventually, I found the answer to my problems in this post by Tim Saunders (?) Result
the right code is something like:
idNode int = 1111;
docDaCancellare doc = new Document (idNode)

if (docDaCancellare.Published)
{
docDaCancellare.Unpublish ();
umbraco.library.UnpublishSingleNode (docDaCancellare.Id);}

docDaCancellare.delete ();
umbraco.library.RefreshContent ();

where the important part for me, makes umbraco.library.UnpublishSingleNode (docDaCancellare.Id) since it removes the node removed from the cache (umbraco.config file in data folder) so that it disappears from my application.
Now it all seems obvious, but since the delete () method can be called safely in a paper published in getting its cancellation, I would never have thought of "depubblicare.
I hope my experience can help.

0 comments:

Post a Comment