Modification dates of Archetypes objects are set automatically to the current
date and time when an object is reindexed. Usually this is useful behaviour but if
,for example, you’re importing content from elsewhere into a Plone site and you’d
like to set the modification date to be some time in the past then it’s a problem.
Heres a method that sets the standard dates of an Archetypes content type ‘obj’
to DateTime ‘dt’.
def setObjDate(obj, dt): """Prevent update of modification date during reindexing""" obj.setCreationDate(dt) obj.setEffectiveDate(dt) obj.setModificationDate(dt) od = obj.__dict__ od['notifyModified'] = lambda *args: None obj.reindexObject() del od['notifyModified']
The trick, based on migration code found in the plone.app.blob package, is
to mask the ‘notifyModified’ class method with a no-op lambda on our
instance, call the reindex, then drop the mask so that the class method is visible
I’ve used this successfully for importing data into a Plone 4 instance but it should work at least as far back as Plone 2.5.