Index: src/__phutil_library_map__.php =================================================================== --- src/__phutil_library_map__.php +++ 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( Index: src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php =================================================================== --- /dev/null +++ src/applications/phrequent/conduit/ConduitAPI_phrequent_Method.php @@ -0,0 +1,13 @@ + '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; + } + +} Index: src/applications/phrequent/conduit/ConduitAPI_phrequent_push_Method.php =================================================================== --- /dev/null +++ src/applications/phrequent/conduit/ConduitAPI_phrequent_push_Method.php @@ -0,0 +1,42 @@ + '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; + } + +} Index: src/applications/phrequent/controller/PhrequentTrackController.php =================================================================== --- src/applications/phrequent/controller/PhrequentTrackController.php +++ src/applications/phrequent/controller/PhrequentTrackController.php @@ -14,6 +14,7 @@ public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); + $editor = new PhrequentTrackingEditor(); if (!$this->isStartingTracking() && !$this->isStoppingTracking()) { @@ -21,9 +22,9 @@ } 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); - } - } Index: src/applications/phrequent/editor/PhrequentTrackingEditor.php =================================================================== --- /dev/null +++ src/applications/phrequent/editor/PhrequentTrackingEditor.php @@ -0,0 +1,36 @@ +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); + } + +}