Opened 11 years ago
Last modified 6 years ago
#11340 closed enhancement
Confusion with timestamp - lack of documentation — at Version 1
Reported by: | Owned by: | osimons | |
---|---|---|---|
Priority: | normal | Component: | XmlRpcPlugin |
Severity: | normal | Keywords: | documentation |
Cc: | Trac Release: | 1.0 |
Description (last modified by )
I would like to start using Trac tickets, but first I need to synchronize thousands of ticket with trac via XmlRpcPlugin.
I cannot find any documentation with properties and their types to provide to ticket_create and ticket_update. Documentation http://www.jspwiki.org/Wiki.jsp?page=WikiRPCInterface2 linked from http://trac-hacks.org/wiki/XmlRpcPlugin doesn't work.
Can you please provide more complex example how to use timestamps when calling ticket_update? I cannot get it work. I would expect that I should provide timestamp of type int32 in _ts field? But when I call _trac.ticket_get(id) I obtain very long number ["_ts"] = "1380897120346000"
which seem not be be int32 unix timestamp.
I probably use wrong type beause of "Server returned a fault exception: [1] 'unsupported type for timedelta microseconds component: unicode' while executing 'ticket.update()'". My code C# code is:
public XmlRpcStruct GetProperties() { XmlRpcStruct dict = new XmlRpcStruct(); dict.Add("type", Type.ToString()); dict.Add("time", Time.ToString("yyyyMMddTHHmmsszzz")); dict.Add("changetime", Changetime.ToString("yyyyMMddTHHmmsszzz")); dict.Add("_ts", DateTimeToUnixTimeStamp(DateTime.Now)); dict.Add("component", Component ?? string.Empty); dict.Add("severity", Severity.ToString()); dict.Add("priority", Priority.ToString()); dict.Add("owner", Owner ?? string.Empty); dict.Add("reporter", Reporter ?? string.Empty); dict.Add("cc", Cc ?? string.Empty); dict.Add("version", Version ?? string.Empty); dict.Add("milestone", Milestone ?? string.Empty); dict.Add("status", Status.ToString()); dict.Add("resolution", Resolution.ToString()); dict.Add("summary", Summary ?? string.Empty); dict.Add("description", Description?? string.Empty); dict.Add("keywords", Keywords ?? string.Empty); return dict; } public static int DateTimeToUnixTimeStamp(DateTime dateTime) { System.DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); return (int)((dateTime - epoch.ToLocalTime()).TotalSeconds); }
When updating a ticket, all you have to do is pass whatever
_ts
value you get from the server. The timestamp is a marker for the server to make sure that updates are performed based on latest values, and not on stale values. So, in order to doticket.update
you first have to doticket.get
.What this value is exactly has changed with Trac. In earlier Trac versions (pre-0.12) timestamped based on seconds since epoch. However, with 0.12 this changed so that Trac now timestamps based on microseconds. So dividing by 1.000.000 will get you the seconds since epoch. The plugin works with both versions.
However, all this is implementation details you should not be concerned with.
_ts
is really just a token used to ensure valid updates.As for available fields, that also depends on your server. If you have defined custom fields they will also appear as available fields for creation and updating. All fields are returned by the
ticket.getTicketFields
call. However, as you noticed, the plugin does not know anything about types, expected inputs, validation rules or similar. You may even have validation/manipulator plugins installed the plugin cannot know about. The plugin takes the data as if entered through web, and makes Trac perform validation of input - applying changes if all is correct, or returning all the warnings if problems are found. With fields as if entered through web, all ticket attributes should be passed as plain strings.If you have specific suggestions for more correct documentation, then by all means add patch or suggestions to this ticket.