@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

Add MAILTAGs to Badges

Summary: Still doesn't mail yet, but the settings now show up.

Test Plan: View email settings, see Badges options.

Reviewers: eadler, epriestley

Reviewed By: eadler, epriestley

Subscribers: epriestley, Korvin

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

+122 -1
+2
resources/sql/autopatches/20150725.badges.mailkey.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_badges.badges_badge 2 + ADD mailKey binary(20) NOT NULL;
+18
resources/sql/autopatches/20150725.badges.mailkey.2.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorBadgesBadge(); 4 + $conn_w = $table->establishConnection('w'); 5 + $iterator = new LiskMigrationIterator($table); 6 + foreach ($iterator as $badge) { 7 + $id = $badge->getID(); 8 + 9 + echo pht('Adding mail key for badge %d...', $id); 10 + echo "\n"; 11 + 12 + queryfx( 13 + $conn_w, 14 + 'UPDATE %T SET mailKey = %s WHERE id = %d', 15 + $table->getTableName(), 16 + Filesystem::readRandomCharacters(20), 17 + $id); 18 + }
+4
src/__phutil_library_map__.php
··· 1631 1631 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 1632 1632 'PhabricatorBadgesIcon' => 'applications/badges/icon/PhabricatorBadgesIcon.php', 1633 1633 'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php', 1634 + 'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php', 1634 1635 'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php', 1635 1636 'PhabricatorBadgesQuery' => 'applications/badges/query/PhabricatorBadgesQuery.php', 1636 1637 'PhabricatorBadgesRecipientsListView' => 'applications/badges/view/PhabricatorBadgesRecipientsListView.php', 1637 1638 'PhabricatorBadgesRemoveRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php', 1639 + 'PhabricatorBadgesReplyHandler' => 'applications/badges/mail/PhabricatorBadgesReplyHandler.php', 1638 1640 'PhabricatorBadgesSchemaSpec' => 'applications/badges/storage/PhabricatorBadgesSchemaSpec.php', 1639 1641 'PhabricatorBadgesSearchEngine' => 'applications/badges/query/PhabricatorBadgesSearchEngine.php', 1640 1642 'PhabricatorBadgesTransaction' => 'applications/badges/storage/PhabricatorBadgesTransaction.php', ··· 5402 5404 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 5403 5405 'PhabricatorBadgesIcon' => 'Phobject', 5404 5406 'PhabricatorBadgesListController' => 'PhabricatorBadgesController', 5407 + 'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver', 5405 5408 'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType', 5406 5409 'PhabricatorBadgesQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5407 5410 'PhabricatorBadgesRecipientsListView' => 'AphrontTagView', 5408 5411 'PhabricatorBadgesRemoveRecipientsController' => 'PhabricatorBadgesController', 5412 + 'PhabricatorBadgesReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 5409 5413 'PhabricatorBadgesSchemaSpec' => 'PhabricatorConfigSchemaSpec', 5410 5414 'PhabricatorBadgesSearchEngine' => 'PhabricatorApplicationSearchEngine', 5411 5415 'PhabricatorBadgesTransaction' => 'PhabricatorApplicationTransaction',
+18 -1
src/applications/badges/editor/PhabricatorBadgesEditor.php
··· 142 142 return $errors; 143 143 } 144 144 145 + protected function shouldSendMail( 146 + PhabricatorLiskDAO $object, 147 + array $xactions) { 148 + return true; 149 + } 150 + 151 + public function getMailTagsMap() { 152 + return array( 153 + PhabricatorBadgesTransaction::MAILTAG_DETAILS => 154 + pht('Someone changes the badge\'s details.'), 155 + PhabricatorBadgesTransaction::MAILTAG_COMMENT => 156 + pht('Someone comments on a badge.'), 157 + PhabricatorBadgesTransaction::MAILTAG_OTHER => 158 + pht('Other badge activity not listed above occurs.'), 159 + ); 160 + } 161 + 145 162 protected function shouldPublishFeedStory( 146 163 PhabricatorLiskDAO $object, 147 164 array $xactions) { ··· 149 166 } 150 167 151 168 protected function buildReplyHandler(PhabricatorLiskDAO $object) { 152 - return id(new PhabricatorMacroReplyHandler()) 169 + return id(new PhabricatorBadgesReplyHandler()) 153 170 ->setMailReceiver($object); 154 171 } 155 172
+28
src/applications/badges/mail/PhabricatorBadgesMailReceiver.php
··· 1 + <?php 2 + 3 + final class PhabricatorBadgesMailReceiver 4 + extends PhabricatorObjectMailReceiver { 5 + 6 + public function isEnabled() { 7 + return PhabricatorApplication::isClassInstalled( 8 + 'PhabricatorBadgesApplication'); 9 + } 10 + 11 + protected function getObjectPattern() { 12 + return 'BDGE[1-9]\d*'; 13 + } 14 + 15 + protected function loadObject($pattern, PhabricatorUser $viewer) { 16 + $id = (int)substr($pattern, 4); 17 + 18 + return id(new PhabricatorBadgesQuery()) 19 + ->setViewer($viewer) 20 + ->withIDs(array($id)) 21 + ->executeOne(); 22 + } 23 + 24 + protected function getTransactionReplyHandler() { 25 + return new PhabricatorBadgesReplyHandler(); 26 + } 27 + 28 + }
+16
src/applications/badges/mail/PhabricatorBadgesReplyHandler.php
··· 1 + <?php 2 + 3 + final class PhabricatorBadgesReplyHandler 4 + extends PhabricatorApplicationTransactionReplyHandler { 5 + 6 + public function validateMailReceiver($mail_receiver) { 7 + if (!($mail_receiver instanceof PhabricatorBadgesBadge)) { 8 + throw new Exception(pht('Mail receiver is not a %s!', 'Badges')); 9 + } 10 + } 11 + 12 + public function getObjectPrefix() { 13 + return 'BDGE'; 14 + } 15 + 16 + }
+9
src/applications/badges/storage/PhabricatorBadgesBadge.php
··· 13 13 protected $description; 14 14 protected $icon; 15 15 protected $quality; 16 + protected $mailKey; 16 17 protected $viewPolicy; 17 18 protected $editPolicy; 18 19 protected $status; ··· 87 88 'icon' => 'text255', 88 89 'quality' => 'text255', 89 90 'status' => 'text32', 91 + 'mailKey' => 'bytes20', 90 92 ), 91 93 self::CONFIG_KEY_SCHEMA => array( 92 94 'key_creator' => array( ··· 112 114 113 115 public function getRecipientPHIDs() { 114 116 return $this->assertAttached($this->recipientPHIDs); 117 + } 118 + 119 + public function save() { 120 + if (!$this->getMailKey()) { 121 + $this->setMailKey(Filesystem::readRandomCharacters(20)); 122 + } 123 + return parent::save(); 115 124 } 116 125 117 126
+27
src/applications/badges/storage/PhabricatorBadgesTransaction.php
··· 10 10 const TYPE_STATUS = 'badges:status'; 11 11 const TYPE_FLAVOR = 'badges:flavor'; 12 12 13 + const MAILTAG_NAME = 'badges:name'; 14 + const MAILTAG_DETAILS = 'badges:details'; 15 + const MAILTAG_COMMENT = 'badges:comment'; 16 + const MAILTAG_OTHER = 'badges:other'; 17 + 13 18 public function getApplicationName() { 14 19 return 'badges'; 15 20 } ··· 166 171 } 167 172 168 173 return parent::getTitleForFeed(); 174 + } 175 + 176 + public function getMailTags() { 177 + $tags = parent::getMailTags(); 178 + 179 + switch ($this->getTransactionType()) { 180 + case PhabricatorTransactions::TYPE_COMMENT: 181 + $tags[] = self::MAILTAG_COMMENT; 182 + break; 183 + case self::TYPE_NAME: 184 + case self::TYPE_DESCRIPTION: 185 + case self::TYPE_FLAVOR: 186 + case self::TYPE_ICON: 187 + case self::TYPE_STATUS: 188 + case self::TYPE_QUALITY: 189 + $tags[] = self::MAILTAG_DETAILS; 190 + break; 191 + default: 192 + $tags[] = self::MAILTAG_OTHER; 193 + break; 194 + } 195 + return $tags; 169 196 } 170 197 171 198