Page MenuHomePhabricator

D7326.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -205,6 +205,9 @@
'ConduitAPI_phpast_Method' => 'applications/phpast/conduit/ConduitAPI_phpast_Method.php',
'ConduitAPI_phpast_getast_Method' => 'applications/phpast/conduit/ConduitAPI_phpast_getast_Method.php',
'ConduitAPI_phpast_version_Method' => 'applications/phpast/conduit/ConduitAPI_phpast_version_Method.php',
+ 'ConduitAPI_phrequent_Method' => 'applications/phrequent/conduit/ConduitAPI_phrequent_Method.php',
+ 'ConduitAPI_phrequent_pop_Method' => 'applications/phrequent/conduit/ConduitAPI_phrequent_pop_Method.php',
+ 'ConduitAPI_phrequent_push_Method' => 'applications/phrequent/conduit/ConduitAPI_phrequent_push_Method.php',
'ConduitAPI_phriction_Method' => 'applications/phriction/conduit/ConduitAPI_phriction_Method.php',
'ConduitAPI_phriction_edit_Method' => 'applications/phriction/conduit/ConduitAPI_phriction_edit_Method.php',
'ConduitAPI_phriction_history_Method' => 'applications/phriction/conduit/ConduitAPI_phriction_history_Method.php',
@@ -2098,6 +2101,7 @@
'PhrequentTimeBlockTestCase' => 'applications/phrequent/storage/__tests__/PhrequentTimeBlockTestCase.php',
'PhrequentTrackController' => 'applications/phrequent/controller/PhrequentTrackController.php',
'PhrequentTrackableInterface' => 'applications/phrequent/interface/PhrequentTrackableInterface.php',
+ 'PhrequentTrackingEditor' => 'applications/phrequent/editor/PhrequentTrackingEditor.php',
'PhrequentUIEventListener' => 'applications/phrequent/event/PhrequentUIEventListener.php',
'PhrequentUserTime' => 'applications/phrequent/storage/PhrequentUserTime.php',
'PhrequentUserTimeQuery' => 'applications/phrequent/query/PhrequentUserTimeQuery.php',
@@ -2470,6 +2474,9 @@
'ConduitAPI_phpast_Method' => 'ConduitAPIMethod',
'ConduitAPI_phpast_getast_Method' => 'ConduitAPI_phpast_Method',
'ConduitAPI_phpast_version_Method' => 'ConduitAPI_phpast_Method',
+ 'ConduitAPI_phrequent_Method' => 'ConduitAPIMethod',
+ 'ConduitAPI_phrequent_pop_Method' => 'ConduitAPI_phrequent_Method',
+ 'ConduitAPI_phrequent_push_Method' => 'ConduitAPI_phrequent_Method',
'ConduitAPI_phriction_Method' => 'ConduitAPIMethod',
'ConduitAPI_phriction_edit_Method' => 'ConduitAPI_phriction_Method',
'ConduitAPI_phriction_history_Method' => 'ConduitAPI_phriction_Method',
@@ -4556,6 +4563,7 @@
'PhrequentTimeBlock' => 'Phobject',
'PhrequentTimeBlockTestCase' => 'PhabricatorTestCase',
'PhrequentTrackController' => 'PhrequentController',
+ 'PhrequentTrackingEditor' => 'PhabricatorEditor',
'PhrequentUIEventListener' => 'PhabricatorEventListener',
'PhrequentUserTime' =>
array(
diff --git a/src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php b/src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * @group conduit
+ */
+abstract class ConduitAPI_phrequent_Method extends ConduitAPIMethod {
+
+ public function getApplication() {
+ return PhabricatorApplication::getByClass(
+ 'PhabricatorApplicationPhrequent');
+ }
+
+
+}
diff --git a/src/applications/phrequent/conduit/ConduitAPI_phrequent_pop_Method.php b/src/applications/phrequent/conduit/ConduitAPI_phrequent_pop_Method.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phrequent/conduit/ConduitAPI_phrequent_pop_Method.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ *@group conduit
+ */
+final class ConduitAPI_phrequent_pop_Method
+ extends ConduitAPI_phrequent_Method {
+
+ public function getMethodDescription() {
+ return "Stop tracking time on an object by popping it from the stack.";
+ }
+
+ public function getMethodStatus() {
+ return self::METHOD_STATUS_UNSTABLE;
+ }
+
+ public function defineParamTypes() {
+ return array(
+ 'object' => 'required phid'
+ );
+ }
+
+ public function defineReturnType() {
+ return 'bool';
+ }
+
+ public function defineErrorTypes() {
+ return array(
+ );
+ }
+
+ protected function execute(ConduitAPIRequest $request) {
+ $user = $request->getUser();
+ $object_id = $request->getValue('object');
+
+ $editor = new PhrequentTrackingEditor();
+ $editor->stopTracking($user, $object_id);
+
+ return true;
+ }
+
+}
diff --git a/src/applications/phrequent/conduit/ConduitAPI_phrequent_push_Method.php b/src/applications/phrequent/conduit/ConduitAPI_phrequent_push_Method.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phrequent/conduit/ConduitAPI_phrequent_push_Method.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ *@group conduit
+ */
+final class ConduitAPI_phrequent_push_Method
+ extends ConduitAPI_phrequent_Method {
+
+ public function getMethodDescription() {
+ return "Start tracking time on an object by pushing it on the tracking stack.";
+ }
+
+ public function getMethodStatus() {
+ return self::METHOD_STATUS_UNSTABLE;
+ }
+
+ public function defineParamTypes() {
+ return array(
+ 'object' => 'required phid'
+ );
+ }
+
+ public function defineReturnType() {
+ return 'bool';
+ }
+
+ public function defineErrorTypes() {
+ return array(
+ );
+ }
+
+ protected function execute(ConduitAPIRequest $request) {
+ $user = $request->getUser();
+ $object_id = $request->getValue('object');
+
+ $editor = new PhrequentTrackingEditor();
+ $editor->startTracking($user, $object_id);
+
+ return true;
+ }
+
+}
diff --git a/src/applications/phrequent/controller/PhrequentTrackController.php b/src/applications/phrequent/controller/PhrequentTrackController.php
--- a/src/applications/phrequent/controller/PhrequentTrackController.php
+++ b/src/applications/phrequent/controller/PhrequentTrackController.php
@@ -14,16 +14,17 @@
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
+ $editor = new PhrequentTrackingEditor();
if (!$this->isStartingTracking() &&
!$this->isStoppingTracking()) {
throw new Exception('Unrecognized verb: ' . $this->verb);
}
if ($this->isStartingTracking()) {
- $this->startTracking($user, $this->phid);
+ $editor->startTracking($user, $this->phid);
} else if ($this->isStoppingTracking()) {
- $this->stopTracking($user, $this->phid);
+ $editor->stopTracking($user, $this->phid);
}
return id(new AphrontRedirectResponse());
@@ -37,35 +38,4 @@
return $this->verb === 'stop';
}
- private function startTracking($user, $phid) {
- $usertime = new PhrequentUserTime();
- $usertime->setDateStarted(time());
- $usertime->setUserPHID($user->getPHID());
- $usertime->setObjectPHID($phid);
- $usertime->save();
- }
-
- private function stopTracking($user, $phid) {
- if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) {
- // Don't do anything, it's not being tracked.
- return;
- }
-
- $usertime_dao = new PhrequentUserTime();
- $conn = $usertime_dao->establishConnection('r');
-
- queryfx(
- $conn,
- 'UPDATE %T usertime '.
- 'SET usertime.dateEnded = UNIX_TIMESTAMP() '.
- 'WHERE usertime.userPHID = %s '.
- 'AND usertime.objectPHID = %s '.
- 'AND usertime.dateEnded IS NULL '.
- 'ORDER BY usertime.dateStarted, usertime.id DESC '.
- 'LIMIT 1',
- $usertime_dao->getTableName(),
- $user->getPHID(),
- $phid);
- }
-
}
diff --git a/src/applications/phrequent/editor/PhrequentTrackingEditor.php b/src/applications/phrequent/editor/PhrequentTrackingEditor.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phrequent/editor/PhrequentTrackingEditor.php
@@ -0,0 +1,36 @@
+<?php
+
+class PhrequentTrackingEditor extends PhabricatorEditor {
+
+ public function startTracking($user, $phid) {
+ $usertime = new PhrequentUserTime();
+ $usertime->setDateStarted(time());
+ $usertime->setUserPHID($user->getPHID());
+ $usertime->setObjectPHID($phid);
+ $usertime->save();
+ }
+
+ public function stopTracking($user, $phid) {
+ if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) {
+ // Don't do anything, it's not being tracked.
+ return;
+ }
+
+ $usertime_dao = new PhrequentUserTime();
+ $conn = $usertime_dao->establishConnection('r');
+
+ queryfx(
+ $conn,
+ 'UPDATE %T usertime '.
+ 'SET usertime.dateEnded = UNIX_TIMESTAMP() '.
+ 'WHERE usertime.userPHID = %s '.
+ 'AND usertime.objectPHID = %s '.
+ 'AND usertime.dateEnded IS NULL '.
+ 'ORDER BY usertime.dateStarted, usertime.id DESC '.
+ 'LIMIT 1',
+ $usertime_dao->getTableName(),
+ $user->getPHID(),
+ $phid);
+ }
+
+}

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/en/py/ql7unvzozrcmmnxe
Default Alt Text
D7326.diff (8 KB)

Event Timeline