Webdav API, set creation date for files and comments

I’m trying to create a Python script to migrate files from Alfresco to Nextcloud. My goal would be to transfer the files from Alfresco to Nextcloud and preserve the file date. I also would like to transfer all file comments including their creation date.

I’ve managed so far to export all Files and comments from Alfresco using their api. Now I’m looking for ways to import this into Nextcloud. I already found a way to create comments like this:

data = {}
data[“actorType”] = “users”
data[“verb”] = “comment”
data[“message”] = “Test”
json_data = json.dumps(data)
res = requests.post(url, auth=HTTPBasicAuth(user, password), headers={“Content-Type”: “application/json”}, data=json_data)

Regarding the files Nextcloud only seams to know the date when the file was last modified. Is there also a create date that could be imported?

And is it also possible to create such a comment using a specific date in the past?

Update: I just found a way to do this:

For the files there is a built in way to set the file date by sending a unix timestamp over webdav. In Python this can be done like this:

data = “”"<?xml version="1.0"?>
<d:propertyupdate xmlns:d=“DAV:”>

url = baseUrl + “/remote.php/dav/files/admin/Test.txt”

res = requests.request(“PROPPATCH”, url, auth=HTTPBasicAuth(user, password), data=data.encode(encoding=‘utf-8’))

It is also possible to set a specific date for comments, but first I had to add one line of code to the following file inside the nextcloud server to be able to do this:

/nextcloud/apps/dav/lib/Comments/CommentsPlugin.php Line 245:

$comment->setCreationDateTime(new \DateTime($data[‘creationDateTime’]), new \DateTimeZone(‘UTC’));

After that the date can be set by sending a unix timestamp with UTC timezone as a “creationDateTime” json variable. I don’t know yet if this additional line of will cause any side effects. Saving comments in the webpage still seems to work. But the line can simply be removed after importing.

Did this still work for you in the latest version? I think I’ve implemented this but it’s not changing the date/time of a file on the latest nextcloud for me.

Python 3.7.4, for the res var it gives me <Response [207]>