Orchard CMS ContentPart Update - orchardcms

I am trying to send a message every time a specific Content Part is updated, created or deleted.
When is created or deleted I use the Content Handler: OnCreated and OnRemoving to send the message.
But during the update I need the previous state of the ContentPart and the new Data also.
Thanks.
[Answer]
The answer and comments of Piotr Szmyd lead me to the solve the problem. Read them.

Use OnVersioning / OnVersioned. Those events gets fired whenever a new version of an item is created. You can access old and new versions of a given part then.

Related

Update Kentico document field regardless of versioning

I have a field on one of my base page types which I need to update programmatically from an external data feed, so that it can be included in my Smart Search index.
The documents are versioned, but I want to update the published value of this field regardless of checkout state, and obviously avoid any sort of overwrite when documents are checked in.
The field will not appear on the editor form -- or ideally, would conditionally display for Global Admins.
It appears that using the API to update the document without doing a CheckOut fails silently. However if I do a Checkout/Update/CheckIn on a checkout-out page, the author will lose their work I assume?
Any way to handle this "versionless" field via the Kentico data model and API?
I don't think there is a way around updating checked out pages. You can update the page type table directly, but as you mentioned, it will be overwritten when they check in. You could update the version history I believe to make changes to the current data that is checked out, but again, I think that will be lost if the user cancels.
The only way I can think of to solve your issue is to create another table that maps the values you want to the page. Then you don't have to worry about the pages being checked out, you just need to grab the documentID or something. Since the value isn't displayed to the editor, you just have a field that does a lookup on this table.
The preferred and right way is using the API but as you stated, it causes problems if a user has something already checked out and working on it or it's in workflow and not published yet.
If the field you're updating is page type specific, there is one thing specifically I can think of and that's going directly to the database to the page type's database field and perform an update to that field.
Note: this is not recommended unless you know specifically what you're doing and have done full testing on it
The down side of going direct to the database is this will not update the current version since you're using check in/out and workflow. You will also need to update the checked out and current version which means you need to:
Go to the Document itself in the cms_documents table and get the document you are working with.
Then using the fields DocumentCheckedOutVersionHistoryID and DocumentPublishedVersionHistoryID' you can get the version history IDs of the document from theCMS_VersionHistory` table.
Then you can perform an update to the CMS_VersionHistory and your custom page type fields.
You will then need to look in the CMS_WorkflowHistory table and find out if that document is in workflow and in what step.
After you have that workflow history step, use the VersionHistoryID field to go back to the CMS_VersionHistory table and update that record with your data.
Again, not an elegant solution since you are using check in/out and workflow but after some trial and error and testing you should be able to figure it out.
UPDATE
You may also be able to add a custom table or some other linked database table which will allow you to create a global handler. The linked table would be where you perform your updates via API and other calls without versioning or workflow. Then when a user updates a specific page type you could do a check to see when the last time that linked table was updated and update the field(s) you need on update of that particular page (of course by node and document IDs).
Unfortunately you'll have to check it in and out with API. See examples here.
Also you might need to publish it in order to reflect changes on the live site.

How do Lotus Notes documents arise with document versioning enabled?

In several mail-in and regular databases we have documents that appear to be "uneditable" - i.e. edit them and the edits appear not to save. In fact what is happening is that both the original and the edited doc are being saved because something has switched on "versioning". Needless to say this confuses users quite a lot.
It appears you can only tell versioning is enabled by looking inside the document properties for a field called $VersionOpt.
The form designs have versioning set to None, so something must be setting $VersionOpt.. but what might do that? Is there anything in a regular 8.5.3 mail client that sets document versioning? Any other ideas how this can happen?
(This link explains the background to Notes versioning - http://gg-lnotes.blogspot.co.uk/2010/04/ways-to-do-version-controllingtracking.html)
Based on the comments, my best guess is that you have one or more users drafting their messages in a Notes application built with a template that supports versioning (possibly the Document Library, but it could be something custom) and using a programmed action that calls #MailSend to submit them to the mail-in database. That's going to take the note intact, add the required fields (e.g., SendTo, etc.) for mailing, and drop it into mail.box, complete with all items that the application template's code had created.
(The only other possibility I can conceive of is that you have some add-on software on one of your servers that is hooking the router and adding the $VersionOpt item based on something it sees in certain messages, but that seems very far-fetched. I've never heard of a mail add-in that would do that.)
In any case, the solution to the problem would be to add an agent to the mail-in databases, triggered by the "Before new mail arrives" event, to remove the item. I.e., FIELD $VersionOpt = #DeleteField;
If a user creates a Notes 'memo' message using 'stationery', the new note can be created with a version control field. If this Notes 'memo' is then mailed in to the mail-in db, it will recieve the message with the version control field '$VersionOpt'. See this answer in an old forum post:
http://www-10.lotus.com/ldd/nd6forum.nsf/ShowMyTopicsAllFlatweb/92a576fbe203b781852573af00630b78?OpenDocument
There are also old technotes referring to this issue.
The solution is to delete the field using a background agent or otherwsie arrange to delete the field.

How to update an existing activity stream entry in IBM Connections

I am trying to update an existing activity stream entry e.g. the title of the entry.
Here I found the code for the creation of the new entry:
Link
But I could not find any reference how do I update an existing entry?
Additional information:
I use IBM Connections 4.5 and the IBM SBT
I create the entries with a system user to other users with the flag
'actionable'
Here my questions:
Which URL?
Which Method (PUT?)?
Which Json?
And another question about the actionable flag:
How can I change the actionable flag for an entry of another user? The description for my own entries is described on slide 37 here: Link
Thank you so much !
Markus
Ok, I think I fully understand the issue now. As suggested this is not supported, but there is a way you can achieve the same result.
First of all why isn't it supported . . .
Events are a point in time (and they were accurate at that point in time)
A new event on the same object supersedes it (as it's now the most interesting) but
doesn't invalidate it (it can still be seen in history)
The Actionable view does not show a rolled up view, instead it shows all events that are marked actionable (and there may be multiple actions related to any given Object)
What you can do . . .
If you want to replace an entry in the Actionable view, you can remove the event from the actionable view (it is just removed from that view and could still be seen in event history)
You can then add another event to the actionable view (which as the latest event will also supersede events in other rolled up views)
Removing the actionable flag is here ->http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Support_for_Saved_and_Actionable_events&content=pdcontent
an activity stream object is treated an an immutable object in IBM Connections.
you can Create Delete and Read.
You can use a rollup-id in IBM Connections.
In order to address the scenario where a user posts a file and 200 people 'like' it, filling up their Activity Stream, rollup needs to be performed. This means:
Only the latest event on any given object is shown
The 2 most recent comments are returned.
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpAPIViewer.xsp?lookupName=IBM+Connections+4.0+API+Documentation#action=openDocument&res_title=Support_for_Rollup&content=apicontent
Just to extend the last answer, delete is not directly supported in the Activity Stream in IBM Connections, though a means of propagating delete based on deletion of an Object was introduced in IBM Connections 4.5.
However it does seem like submitting a new event with an appropriate rollup id is what you're looking for. That way users will see the latest, but the history remains and can be seen if desired.

How to get both the old and new value of an Orchard.Rules Event Published

I can create a new rule with an event of "Published", and I can fetch the value of a given part, say the AutoroutePart. But how do I get the old value?
I want to compare the two values, and if it has changed, I want to create a new Rewrite Rule based on that.
My aim is to make a simple URL Tracker module, which allows you to change any content item's route with no worries about SEO.
It will be depending on the Orchard.Module.Contrib.RewriteRules by Sébastien Ros
You can't Published has nothing to do with old values. What you want is the Versionned event for when a new content version is created. Because a user could create a new version and publish it in two different steps. If you still wanted to access old versions during a Published event then you might need a custom event with custom tokens.
Or maybe you could file a feature request so that we provide a new token to access previous versions of a content item. Something like {Content.Versions:0} for latest and {Content.Versions:1} for the one just before the latest. Just an idea. This would also solve you initial question.
Or even better, you could implement it and do a pull request.

Deleting a record in javascript

I need to delete some records related to the current record when it is deactivated. I can get the the event when the record is deactivated but I have looked around for some time on Google and this site for the code to delete records in javascript but I can't find any, though I know there must be some out there.
Can anyone help?
Thanks
I would be alright with doing this with a plugin, all I would need to know is how to pick up that the record has been deactivated
You can register a plugin on the SetState and SetStateDynamic messages (recommend the Pre event in your scenario). Each of these messages will pass an EntityMoniker in the InputParameters property bag which refers to the record that is being deactivated.
In your code you will need to:
Check that the new state in the SetState request is deactivated (since of course a record can usually be reactivated and you don't want to try deleting things then too, presumably)
Pick up the EntityMoniker from IPluginExecutionContext.InputParameters
Run your query to identify and delete related records
Exit the plugin to allow the SetState transaction to complete
If you really want to delete a record with JavaScript there is a sample on the MSDN.
Its a little long winded (its a CRUD example - create, retrieve, update & delete). But it should contain the information you need.
Note there is also an example on that page which doesnt use jQuery (if using jQuery is a problem).
That said I think for this operation would will find it easier to implement, test and maintain with a plugin (so I would go for Greg's answer).
Additionally a plugin will apply in all contexts, e.g. if you deactivate the record in a workflow your JavaScript will not run, but a plugin will.

Resources