~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/workflow/ArcanistStopWorkflow.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Stop time tracking on an object
 
5
 */
 
6
final class ArcanistStopWorkflow extends ArcanistPhrequentWorkflow {
 
7
 
 
8
  public function getWorkflowName() {
 
9
    return 'stop';
 
10
  }
 
11
 
 
12
  public function getCommandSynopses() {
 
13
    return phutil_console_format(<<<EOTEXT
 
14
      **stop** [--note __note__] [__objects__]
 
15
EOTEXT
 
16
      );
 
17
  }
 
18
 
 
19
  public function getCommandHelp() {
 
20
    return phutil_console_format(<<<EOTEXT
 
21
Start tracking work in Phrequent.
 
22
EOTEXT
 
23
      );
 
24
  }
 
25
 
 
26
  public function requiresConduit() {
 
27
    return true;
 
28
  }
 
29
 
 
30
  public function desiresWorkingCopy() {
 
31
    return false;
 
32
  }
 
33
 
 
34
  public function requiresAuthentication() {
 
35
    return true;
 
36
  }
 
37
 
 
38
  public function getArguments() {
 
39
    return array(
 
40
      'note' => array(
 
41
        'param' => 'note',
 
42
        'help' =>
 
43
          'A note to attach to the tracked time.',
 
44
      ),
 
45
      '*' => 'name',
 
46
    );
 
47
  }
 
48
 
 
49
  public function run() {
 
50
    $conduit = $this->getConduit();
 
51
 
 
52
    $names = $this->getArgument('name');
 
53
 
 
54
    $object_lookup = $conduit->callMethodSynchronous(
 
55
      'phid.lookup',
 
56
      array(
 
57
        'names' => $names,
 
58
      ));
 
59
 
 
60
    foreach ($names as $object_name) {
 
61
      if (!array_key_exists($object_name, $object_lookup)) {
 
62
        throw new ArcanistUsageException(
 
63
          "No such object '".$object_name."' found.");
 
64
        return 1;
 
65
      }
 
66
    }
 
67
 
 
68
    if (count($names) === 0) {
 
69
      // Implicit stop; add an entry so the loop will call
 
70
      // phrequent.pop with a null objectPHID.
 
71
      $object_lookup[] = array('phid' => null);
 
72
    }
 
73
 
 
74
    $stopped_phids = array();
 
75
    foreach ($object_lookup as $ref) {
 
76
      $object_phid = $ref['phid'];
 
77
 
 
78
      $stopped_phid = $conduit->callMethodSynchronous(
 
79
        'phrequent.pop',
 
80
        array(
 
81
          'objectPHID' => $object_phid,
 
82
          'note' => $this->getArgument('note'),
 
83
        ));
 
84
      if ($stopped_phid !== null) {
 
85
        $stopped_phids[] = $stopped_phid;
 
86
      }
 
87
    }
 
88
 
 
89
    if (count($stopped_phids) === 0) {
 
90
      if (count($names) === 0) {
 
91
        echo phutil_console_format(
 
92
          "Not currently tracking time against any object\n");
 
93
      } else {
 
94
        $name = '';
 
95
        foreach ($object_lookup as $ref) {
 
96
          if ($name === '') {
 
97
            $name = $ref['fullName'];
 
98
          } else {
 
99
            $name = ', '.$ref['fullName'];
 
100
          }
 
101
        }
 
102
 
 
103
        echo phutil_console_format(
 
104
          "Not currently tracking time against %s\n",
 
105
          $name);
 
106
      }
 
107
      return 1;
 
108
    }
 
109
 
 
110
    $phid_query = $conduit->callMethodSynchronous(
 
111
      'phid.query',
 
112
      array(
 
113
        'phids' => $stopped_phids,
 
114
      ));
 
115
 
 
116
    $name = '';
 
117
    foreach ($phid_query as $ref) {
 
118
      if ($name === '') {
 
119
        $name = $ref['fullName'];
 
120
      } else {
 
121
        $name .= ', '.$ref['fullName'];
 
122
      }
 
123
    }
 
124
 
 
125
    echo phutil_console_format(
 
126
      "Stopped:  %s\n\n",
 
127
      $name);
 
128
 
 
129
    $this->printCurrentTracking(true);
 
130
  }
 
131
 
 
132
}