Skip to content

Commit

Permalink
get the ready the ticket update: comments and workflow actions.
Browse files Browse the repository at this point in the history
the _ts field is very import for avoiding editing collisions.
  • Loading branch information
seanchen committed Jan 25, 2013
1 parent 4377c61 commit cf79801
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
67 changes: 67 additions & 0 deletions wp-trac-client/actions.php
@@ -0,0 +1,67 @@
<?php
/**
* a convenient function to handle form post.
*/
function wptc_form_submit() {

// get the submit action from $_POST
if (!isset($_POST['submit'])) {
// nothing to do.
return;
}

$comment = $_POST['comment'];
$id = $_POST['id'];
$workflow_actions = wptc_analyze_workflow_action();

// get ready the attributes.
$attributes = array();
// timestamp is must!
$attributes['_ts'] = $_POST['ts'];
$attributes = array_merge($attributes, $workflow_actions);
// ticket attributes.

$ticket = wptc_update_ticket($id, $comment, $attributes);
}

/**
* analyze workflow actions from the action section.
* all field is defined in function
* wptc_widget_action_fieldset.
*/
function wptc_analyze_workflow_action() {

// analyze action:
// based on the default workflow.
// we should always have 'action' field.
$action = $_POST['action'];
$attributes = array();
$attributes['action'] = $action;
switch($action) {
case 'leave':
// leave as it is.
break;
case 'reopen':
// status update to reopened
$attributes['status'] = 'reopened';
break;
case 'accept':
$attributes['status'] = 'accepted';
break;
case 'resolve':
// resove to a resolution.
$attributes['status'] = 'closed';
$attributes['resolution'] =
$_POST['action_resolve_resolve_resolution'];
break;
case 'reassign':
// reassign to another person.
$attributes['status'] = 'assigned';
$attributes['owner'] =
$_POST['action_reassign_reassign_owner'];
break;
}

return apply_filters('wptc_analyze_workflow_action',
$attributes);
}
23 changes: 20 additions & 3 deletions wp-trac-client/tags.php
Expand Up @@ -255,8 +255,25 @@ function wptc_get_ticket_default_version() {
/**
* update the ticket .
*/
function wptc_update_ticket($id, $comment='', $attributes,
$author) {
function wptc_update_ticket($id, $comment='', $attributes) {


// using current user's login as the author.
global $current_user;
get_currentuserinfo();

$proxy = get_wptc_client()->getProxy('ticket');
// here is the signature
// update(id, comment, attributes, notify, author, when)
$ticket = $proxy->update($id, $comment, $attributes,
False,
$current_user->user_login);
// TODO:
// 1. update memcached entry for ticket.
// 2. load the ticket change log
// 3. update memcached entry for ticket change log.
// 4. load the ticket actions
// 5. update memcached entry for ticket actions.
// 6. update solr doc based on the new data.

return $ticket;
}
7 changes: 6 additions & 1 deletion wp-trac-client/widgets.php
Expand Up @@ -12,6 +12,7 @@ function wptc_widget_parse_content($wiki) {
//$ret = Markdown($wiki);
$wkr = new WikiRenderer('trac_to_xhtml');
$ret = $wkr->render($wiki);
//$ret = $wiki;

// apply filters to allow user to tweak.
return apply_filters('wptc_widget_parse_content', $ret);
Expand Down Expand Up @@ -730,9 +731,13 @@ function wptc_widget_ticket_details($ticket_id) {
echo wptc_widget_comment_fieldset();
echo wptc_widget_action_fieldset($actions, $ticket['status']);

// preparing the timestamp, should be the following format
// value="2012-11-26 20:01:26.925065+00:00"
//$now = new DateTime("now", new DateTimeZone('UTC'));
//$ts = $now->format('Y-m-d H:i:sP');
echo <<<EOT
<div class="buttons">
<input type="hidden" name="ts" value="">
<input type="hidden" name="ts" value="{$ticket['_ts']}">
<input type="hidden" name="id" value="{$ticket_id}">
<!-- input type="submit" name="preview" value="Preview" -->&nbsp;
<input type="submit" name="submit" value="Submit changes">
Expand Down

0 comments on commit cf79801

Please sign in to comment.