@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add conduit method for deleting user status

Test Plan: All four eventualities.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2383

vrana e4f4b6a3 3fa310f3

+111 -3
+2
src/__phutil_library_map__.php
··· 179 179 'ConduitAPI_slowvote_info_Method' => 'applications/conduit/method/slowvote/info', 180 180 'ConduitAPI_user_Method' => 'applications/conduit/method/user/base', 181 181 'ConduitAPI_user_addstatus_Method' => 'applications/conduit/method/user/addstatus', 182 + 'ConduitAPI_user_removestatus_Method' => 'applications/conduit/method/user/removestatus', 182 183 'ConduitAPI_user_find_Method' => 'applications/conduit/method/user/find', 183 184 'ConduitAPI_user_info_Method' => 'applications/conduit/method/user/info', 184 185 'ConduitAPI_user_whoami_Method' => 'applications/conduit/method/user/whoami', ··· 1200 1201 'ConduitAPI_slowvote_info_Method' => 'ConduitAPIMethod', 1201 1202 'ConduitAPI_user_Method' => 'ConduitAPIMethod', 1202 1203 'ConduitAPI_user_addstatus_Method' => 'ConduitAPI_user_Method', 1204 + 'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method', 1203 1205 'ConduitAPI_user_find_Method' => 'ConduitAPI_user_Method', 1204 1206 'ConduitAPI_user_info_Method' => 'ConduitAPI_user_Method', 1205 1207 'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method',
+7 -3
src/applications/conduit/method/user/addstatus/ConduitAPI_user_addstatus_Method.php
··· 21 21 */ 22 22 final class ConduitAPI_user_addstatus_Method extends ConduitAPI_user_Method { 23 23 24 + public function getMethodStatus() { 25 + return self::METHOD_STATUS_UNSTABLE; 26 + } 27 + 24 28 public function getMethodDescription() { 25 29 return "Add status information to the logged-in user."; 26 30 } ··· 46 50 } 47 51 48 52 protected function execute(ConduitAPIRequest $request) { 49 - $userPHID = $request->getUser()->getPHID(); 53 + $user_phid = $request->getUser()->getPHID(); 50 54 $from = $request->getValue('fromEpoch'); 51 55 $to = $request->getValue('toEpoch'); 52 56 ··· 58 62 // with the next INSERT. 59 63 $overlap = id(new PhabricatorUserStatus())->loadAllWhere( 60 64 'userPHID = %s AND dateFrom < %d AND dateTo > %d', 61 - $userPHID, 65 + $user_phid, 62 66 $to, 63 67 $from); 64 68 if ($overlap) { ··· 74 78 break; 75 79 } 76 80 id(new PhabricatorUserStatus()) 77 - ->setUserPHID($userPHID) 81 + ->setUserPHID($user_phid) 78 82 ->setDateFrom($from) 79 83 ->setDateTo($to) 80 84 ->setStatus($status)
+86
src/applications/conduit/method/user/removestatus/ConduitAPI_user_removestatus_Method.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + /** 20 + * @group conduit 21 + */ 22 + final class ConduitAPI_user_removestatus_Method extends ConduitAPI_user_Method { 23 + 24 + public function getMethodStatus() { 25 + return self::METHOD_STATUS_UNSTABLE; 26 + } 27 + 28 + public function getMethodDescription() { 29 + return "Delete status information of the logged-in user."; 30 + } 31 + 32 + public function defineParamTypes() { 33 + return array( 34 + 'fromEpoch' => 'required int', 35 + 'toEpoch' => 'required int', 36 + ); 37 + } 38 + 39 + public function defineReturnType() { 40 + return 'int'; 41 + } 42 + 43 + public function defineErrorTypes() { 44 + return array( 45 + 'ERR-BAD-EPOCH' => "'toEpoch' must be bigger than 'fromEpoch'.", 46 + ); 47 + } 48 + 49 + protected function execute(ConduitAPIRequest $request) { 50 + $user_phid = $request->getUser()->getPHID(); 51 + $from = $request->getValue('fromEpoch'); 52 + $to = $request->getValue('toEpoch'); 53 + 54 + if ($to <= $from) { 55 + throw new ConduitException('ERR-BAD-EPOCH'); 56 + } 57 + 58 + $overlap = id(new PhabricatorUserStatus())->loadAllWhere( 59 + 'userPHID = %s AND dateFrom < %d AND dateTo > %d', 60 + $user_phid, 61 + $to, 62 + $from); 63 + foreach ($overlap as $status) { 64 + if ($status->getDateFrom() < $from) { 65 + if ($status->getDateTo() > $to) { 66 + // Split the interval. 67 + id(new PhabricatorUserStatus()) 68 + ->setUserPHID($user_phid) 69 + ->setDateFrom($to) 70 + ->setDateTo($status->getDateTo()) 71 + ->setStatus($status->getStatus()) 72 + ->save(); 73 + } 74 + $status->setDateTo($from); 75 + $status->save(); 76 + } else if ($status->getDateTo() > $to) { 77 + $status->setDateFrom($to); 78 + $status->save(); 79 + } else { 80 + $status->delete(); 81 + } 82 + } 83 + return count($overlap); 84 + } 85 + 86 + }
+16
src/applications/conduit/method/user/removestatus/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/conduit/method/user/base'); 10 + phutil_require_module('phabricator', 'applications/conduit/protocol/exception'); 11 + phutil_require_module('phabricator', 'applications/people/storage/userstatus'); 12 + 13 + phutil_require_module('phutil', 'utils'); 14 + 15 + 16 + phutil_require_source('ConduitAPI_user_removestatus_Method.php');