@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.

Move Audit to proper Subscriptions

Summary:
Ref T4896. Currently, subscriptions to commits are stored as auditors with a special "CC" type.

Instead, use normal subscriptions storage, reads and writes.

Test Plan:
- Ran migration and verified data still looked good.
- Viewed commits in UI and saw "subscribers".
- Saw "Automatically Subscribed", clicked Subscribe/Unsubscribe on a non-authored commit, saw subscriptions update.
- Pushed a commit through Herald rules and saw them trigger subscriptions and auditors.
- Used "Add CCs".
- Added CCs with mentions.

Reviewers: btrahan, joshuaspence

Reviewed By: btrahan, joshuaspence

Subscribers: epriestley

Maniphest Tasks: T4896

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

+102 -50
+30
resources/sql/autopatches/20140731.audit.1.subscribers.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorRepositoryAuditRequest(); 4 + $conn_w = $table->establishConnection('w'); 5 + 6 + echo "Migrating Audit subscribers to subscriptions...\n"; 7 + foreach (new LiskMigrationIterator($table) as $request) { 8 + $id = $request->getID(); 9 + 10 + echo "Migrating auditor {$id}...\n"; 11 + 12 + if ($request->getAuditStatus() != 'cc') { 13 + // This isn't a "subscriber", so skip it. 14 + continue; 15 + } 16 + 17 + queryfx( 18 + $conn_w, 19 + 'INSERT IGNORE INTO %T (src, type, dst) VALUES (%s, %d, %s)', 20 + PhabricatorEdgeConfig::TABLE_NAME_EDGE, 21 + $request->getCommitPHID(), 22 + PhabricatorEdgeConfig::TYPE_OBJECT_HAS_SUBSCRIBER, 23 + $request->getAuditorPHID()); 24 + 25 + 26 + // Wipe the row. 27 + $request->delete(); 28 + } 29 + 30 + echo "Done.\n";
+1
src/__phutil_library_map__.php
··· 4847 4847 'PhabricatorPolicyInterface', 4848 4848 'PhabricatorFlaggableInterface', 4849 4849 'PhabricatorTokenReceiverInterface', 4850 + 'PhabricatorSubscribableInterface', 4850 4851 'HarbormasterBuildableInterface', 4851 4852 'PhabricatorCustomFieldInterface', 4852 4853 ),
+40 -32
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 93 93 } 94 94 } 95 95 96 + $add_self_cc = false; 97 + 96 98 if ($action == PhabricatorAuditActionConstants::CLOSE) { 97 99 if (!PhabricatorEnv::getEnvConfig('audit.can-author-close-audit')) { 98 100 throw new Exception('Cannot Close Audit without enabling'. ··· 177 179 $new_status = null; 178 180 switch ($action) { 179 181 case PhabricatorAuditActionConstants::COMMENT: 180 - case PhabricatorAuditActionConstants::ADD_CCS: 181 182 case PhabricatorAuditActionConstants::ADD_AUDITORS: 182 - $new_status = PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED; 183 + case PhabricatorAuditActionConstants::ADD_CCS: 184 + $add_self_cc = true; 183 185 break; 184 186 case PhabricatorAuditActionConstants::ACCEPT: 185 187 $new_status = PhabricatorAuditStatusConstants::ACCEPTED; ··· 193 195 throw new Exception("Unknown or invalid action '{$action}'!"); 194 196 } 195 197 196 - $request = id(new PhabricatorRepositoryAuditRequest()) 197 - ->setCommitPHID($commit->getPHID()) 198 - ->setAuditorPHID($actor->getPHID()) 199 - ->setAuditStatus($new_status) 200 - ->setAuditReasons(array('Voluntary Participant')) 201 - ->save(); 202 - $requests[] = $request; 198 + if ($new_status !== null) { 199 + $request = id(new PhabricatorRepositoryAuditRequest()) 200 + ->setCommitPHID($commit->getPHID()) 201 + ->setAuditorPHID($actor->getPHID()) 202 + ->setAuditStatus($new_status) 203 + ->setAuditReasons(array('Voluntary Participant')) 204 + ->save(); 205 + $requests[] = $request; 206 + } 203 207 } 204 208 } 205 209 206 210 $auditors = array(); 207 211 $ccs = array(); 212 + 213 + if ($add_self_cc) { 214 + $ccs[] = $actor->getPHID(); 215 + } 216 + 208 217 foreach ($comments as $comment) { 209 218 $meta = $comment->getMetadata(); 210 219 ··· 244 253 } 245 254 } 246 255 247 - if ($ccs) { 248 - foreach ($ccs as $cc_phid) { 249 - $audit_cc = PhabricatorAuditStatusConstants::CC; 250 - $requests[] = id (new PhabricatorRepositoryAuditRequest()) 251 - ->setCommitPHID($commit->getPHID()) 252 - ->setAuditorPHID($cc_phid) 253 - ->setAuditStatus($audit_cc) 254 - ->setAuditReasons( 255 - array('Added by '.$actor->getUsername())) 256 - ->save(); 257 - } 258 - } 259 - 260 256 $commit->updateAuditStatus($requests); 261 257 $commit->save(); 258 + 259 + if ($ccs) { 260 + id(new PhabricatorSubscriptionsEditor()) 261 + ->setActor($actor) 262 + ->setObject($commit) 263 + ->subscribeExplicit($ccs) 264 + ->save(); 265 + } 262 266 263 267 $content_source = PhabricatorContentSource::newForSource( 264 268 PhabricatorContentSource::SOURCE_LEGACY, ··· 288 292 foreach ($requests as $request) { 289 293 $status = $request->getAuditStatus(); 290 294 switch ($status) { 291 - case PhabricatorAuditStatusConstants::RESIGNED: 292 - case PhabricatorAuditStatusConstants::NONE: 293 - case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED: 294 - case PhabricatorAuditStatusConstants::CC: 295 - $feed_dont_publish_phids[$request->getAuditorPHID()] = 1; 296 - break; 297 - default: 298 - unset($feed_dont_publish_phids[$request->getAuditorPHID()]); 299 - break; 295 + case PhabricatorAuditStatusConstants::RESIGNED: 296 + case PhabricatorAuditStatusConstants::NONE: 297 + case PhabricatorAuditStatusConstants::AUDIT_NOT_REQUIRED: 298 + $feed_dont_publish_phids[$request->getAuditorPHID()] = 1; 299 + break; 300 + default: 301 + unset($feed_dont_publish_phids[$request->getAuditorPHID()]); 302 + break; 300 303 } 301 304 } 302 305 $feed_dont_publish_phids = array_keys($feed_dont_publish_phids); ··· 452 455 $email_cc[$other_comment->getActorPHID()] = true; 453 456 } 454 457 458 + $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 459 + $commit->getPHID()); 460 + foreach ($subscribers as $subscriber) { 461 + $email_cc[$subscriber] = true; 462 + } 463 + 455 464 foreach ($requests as $request) { 456 465 switch ($request->getAuditStatus()) { 457 - case PhabricatorAuditStatusConstants::CC: 458 466 case PhabricatorAuditStatusConstants::AUDIT_REQUIRED: 459 467 $email_cc[$request->getAuditorPHID()] = true; 460 468 break;
-6
src/applications/diffusion/controller/DiffusionCommitController.php
··· 1100 1100 'blue', 1101 1101 pht('Closed')); 1102 1102 break; 1103 - case PhabricatorAuditStatusConstants::CC: 1104 - $item->setIcon( 1105 - PHUIStatusItemView::ICON_INFO, 1106 - 'dark', 1107 - pht('Subscribed')); 1108 - break; 1109 1103 default: 1110 1104 $item->setIcon( 1111 1105 PHUIStatusItemView::ICON_QUESTION,
+2 -11
src/applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php
··· 69 69 70 70 foreach ($requests as $request) { 71 71 $status = $request->getAuditStatus(); 72 - if ($status == PhabricatorAuditStatusConstants::CC) { 73 - // We handle these specially below. 74 - continue; 75 - } 76 72 77 73 $object = idx($objects, $request->getAuditorPHID()); 78 74 if (!$object) { ··· 133 129 } 134 130 135 131 public function getCCUserPHIDs($object) { 136 - $ccs = array(); 137 - foreach ($this->getAuditRequests() as $request) { 138 - if ($request->getAuditStatus() == PhabricatorAuditStatusConstants::CC) { 139 - $ccs[] = $request->getAuditorPHID(); 140 - } 141 - } 142 - return $ccs; 132 + return PhabricatorSubscribersQuery::loadSubscribersForPHID( 133 + $object->getPHID()); 143 134 } 144 135 145 136 public function getObjectTitle($object) {
+21
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 6 6 PhabricatorPolicyInterface, 7 7 PhabricatorFlaggableInterface, 8 8 PhabricatorTokenReceiverInterface, 9 + PhabricatorSubscribableInterface, 9 10 HarbormasterBuildableInterface, 10 11 PhabricatorCustomFieldInterface { 11 12 ··· 328 329 public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { 329 330 $this->customFields = $fields; 330 331 return $this; 332 + } 333 + 334 + 335 + /* -( PhabricatorSubscribableInterface )----------------------------------- */ 336 + 337 + 338 + public function isAutomaticallySubscribed($phid) { 339 + 340 + // TODO: This should also list auditors, but handling that is a bit messy 341 + // right now because we are not guaranteed to have the data. 342 + 343 + return ($phid == $this->getAuthorPHID()); 344 + } 345 + 346 + public function shouldShowSubscribersProperty() { 347 + return true; 348 + } 349 + 350 + public function shouldAllowSubscription($phid) { 351 + return true; 331 352 } 332 353 333 354 }
+8 -1
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 244 244 245 245 $maps = array( 246 246 PhabricatorAuditStatusConstants::AUDIT_REQUIRED => $map, 247 - PhabricatorAuditStatusConstants::CC => $ccmap, 248 247 ); 249 248 250 249 foreach ($maps as $status => $map) { ··· 281 280 282 281 $commit->updateAuditStatus($requests); 283 282 $commit->save(); 283 + 284 + if ($ccmap) { 285 + id(new PhabricatorSubscriptionsEditor()) 286 + ->setActor(PhabricatorUser::getOmnipotentUser()) 287 + ->setObject($commit) 288 + ->subscribeExplicit(array_keys($ccmap)) 289 + ->save(); 290 + } 284 291 } 285 292 286 293