Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / phrequent / editor / PhrequentTrackingEditor.php
blobfec91ef7cbc8fdd2d2dea9bb92b53fdde16cc9d3
1 <?php
3 final class PhrequentTrackingEditor extends PhabricatorEditor {
5 public function startTracking(PhabricatorUser $user, $phid, $timestamp) {
6 $usertime = new PhrequentUserTime();
7 $usertime->setDateStarted($timestamp);
8 $usertime->setUserPHID($user->getPHID());
9 $usertime->setObjectPHID($phid);
10 $usertime->save();
12 return $phid;
15 public function stopTracking(
16 PhabricatorUser $user,
17 $phid,
18 $timestamp,
19 $note) {
21 if (!PhrequentUserTimeQuery::isUserTrackingObject($user, $phid)) {
22 // Don't do anything, it's not being tracked.
23 return null;
26 $usertime_dao = new PhrequentUserTime();
27 $conn = $usertime_dao->establishConnection('r');
29 queryfx(
30 $conn,
31 'UPDATE %T usertime '.
32 'SET usertime.dateEnded = %d, '.
33 'usertime.note = %s '.
34 'WHERE usertime.userPHID = %s '.
35 'AND usertime.objectPHID = %s '.
36 'AND usertime.dateEnded IS NULL '.
37 'ORDER BY usertime.dateStarted, usertime.id DESC '.
38 'LIMIT 1',
39 $usertime_dao->getTableName(),
40 $timestamp,
41 $note,
42 $user->getPHID(),
43 $phid);
45 return $phid;
48 public function stopTrackingTop(PhabricatorUser $user, $timestamp, $note) {
49 $times = id(new PhrequentUserTimeQuery())
50 ->setViewer($user)
51 ->withUserPHIDs(array($user->getPHID()))
52 ->withEnded(PhrequentUserTimeQuery::ENDED_NO)
53 ->setOrder(PhrequentUserTimeQuery::ORDER_STARTED_DESC)
54 ->execute();
56 if (count($times) === 0) {
57 // Nothing to stop tracking.
58 return null;
61 $current = head($times);
63 return $this->stopTracking(
64 $user,
65 $current->getObjectPHID(),
66 $timestamp,
67 $note);