mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-13 09:06:14 +01:00
11cf8f05b1
Summary: Depends on D19919. Ref T11351. This method appeared in D8802 (note that "get...Object" was renamed to "get...Transaction" there, so this method was actually "new" even though a method of the same name had existed before). The goal at the time was to let Harbormaster post build results to Diffs and have them end up on Revisions, but this eventually got a better implementation (see below) where the Harbormaster-specific code can just specify a "publishable object" where build results should go. The new `get...Object` semantics ultimately broke some stuff, and the actual implementation in Differential was removed in D10911, so this method hasn't really served a purpose since December 2014. I think that broke the Harbormaster thing by accident and we just lived with it for a bit, then Harbormaster got some more work and D17139 introduced "publishable" objects which was a better approach. This was later refined by D19281. So: the original problem (sending build results to the right place) has a good solution now, this method hasn't done anything for 4 years, and it was probably a bad idea in the first place since it's pretty weird/surprising/fragile. Note that `Comment` objects still have an unrelated method with the same name. In that case, the method ties the `Comment` storage object to the related `Transaction` storage object. Test Plan: Grepped for `getApplicationTransactionObject`, verified that all remaining callsites are related to `Comment` objects. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T11351 Differential Revision: https://secure.phabricator.com/D19920
204 lines
5.2 KiB
PHP
204 lines
5.2 KiB
PHP
<?php
|
|
|
|
final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|
implements
|
|
PhabricatorPolicyInterface,
|
|
PhabricatorApplicationTransactionInterface,
|
|
PhabricatorSubscribableInterface,
|
|
PhabricatorFlaggableInterface,
|
|
PhabricatorDestructibleInterface,
|
|
PhabricatorConduitResultInterface,
|
|
PhabricatorNgramsInterface {
|
|
|
|
protected $name;
|
|
protected $flavor;
|
|
protected $description;
|
|
protected $icon;
|
|
protected $quality;
|
|
protected $mailKey;
|
|
protected $editPolicy;
|
|
protected $status;
|
|
protected $creatorPHID;
|
|
|
|
const STATUS_ACTIVE = 'open';
|
|
const STATUS_ARCHIVED = 'closed';
|
|
|
|
const DEFAULT_ICON = 'fa-star';
|
|
|
|
public static function getStatusNameMap() {
|
|
return array(
|
|
self::STATUS_ACTIVE => pht('Active'),
|
|
self::STATUS_ARCHIVED => pht('Archived'),
|
|
);
|
|
}
|
|
|
|
public static function initializeNewBadge(PhabricatorUser $actor) {
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
->setViewer($actor)
|
|
->withClasses(array('PhabricatorBadgesApplication'))
|
|
->executeOne();
|
|
|
|
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
|
|
|
|
$edit_policy =
|
|
$app->getPolicy(PhabricatorBadgesDefaultEditCapability::CAPABILITY);
|
|
|
|
return id(new PhabricatorBadgesBadge())
|
|
->setIcon(self::DEFAULT_ICON)
|
|
->setQuality(PhabricatorBadgesQuality::DEFAULT_QUALITY)
|
|
->setCreatorPHID($actor->getPHID())
|
|
->setEditPolicy($edit_policy)
|
|
->setFlavor('')
|
|
->setDescription('')
|
|
->setStatus(self::STATUS_ACTIVE);
|
|
}
|
|
|
|
protected function getConfiguration() {
|
|
return array(
|
|
self::CONFIG_AUX_PHID => true,
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
'name' => 'sort255',
|
|
'flavor' => 'text255',
|
|
'description' => 'text',
|
|
'icon' => 'text255',
|
|
'quality' => 'uint32',
|
|
'status' => 'text32',
|
|
'mailKey' => 'bytes20',
|
|
),
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
'key_creator' => array(
|
|
'columns' => array('creatorPHID', 'dateModified'),
|
|
),
|
|
),
|
|
) + parent::getConfiguration();
|
|
}
|
|
|
|
public function generatePHID() {
|
|
return
|
|
PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
|
|
}
|
|
|
|
public function isArchived() {
|
|
return ($this->getStatus() == self::STATUS_ARCHIVED);
|
|
}
|
|
|
|
public function getViewURI() {
|
|
return '/badges/view/'.$this->getID().'/';
|
|
}
|
|
|
|
public function save() {
|
|
if (!$this->getMailKey()) {
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
}
|
|
return parent::save();
|
|
}
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
public function getCapabilities() {
|
|
return array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
);
|
|
}
|
|
|
|
public function getPolicy($capability) {
|
|
switch ($capability) {
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
return PhabricatorPolicies::getMostOpenPolicy();
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
return $this->getEditPolicy();
|
|
}
|
|
}
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
return false;
|
|
}
|
|
|
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
|
return new PhabricatorBadgesEditor();
|
|
}
|
|
|
|
public function getApplicationTransactionTemplate() {
|
|
return new PhabricatorBadgesTransaction();
|
|
}
|
|
|
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
|
|
|
|
|
public function destroyObjectPermanently(
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
$awards = id(new PhabricatorBadgesAwardQuery())
|
|
->setViewer($engine->getViewer())
|
|
->withBadgePHIDs(array($this->getPHID()))
|
|
->execute();
|
|
|
|
foreach ($awards as $award) {
|
|
$engine->destroyObject($award);
|
|
}
|
|
|
|
$this->openTransaction();
|
|
$this->delete();
|
|
$this->saveTransaction();
|
|
}
|
|
|
|
/* -( PhabricatorConduitResultInterface )---------------------------------- */
|
|
|
|
|
|
public function getFieldSpecificationsForConduit() {
|
|
return array(
|
|
id(new PhabricatorConduitSearchFieldSpecification())
|
|
->setKey('name')
|
|
->setType('string')
|
|
->setDescription(pht('The name of the badge.')),
|
|
id(new PhabricatorConduitSearchFieldSpecification())
|
|
->setKey('creatorPHID')
|
|
->setType('phid')
|
|
->setDescription(pht('User PHID of the creator.')),
|
|
id(new PhabricatorConduitSearchFieldSpecification())
|
|
->setKey('status')
|
|
->setType('string')
|
|
->setDescription(pht('Active or archived status of the badge.')),
|
|
);
|
|
}
|
|
|
|
public function getFieldValuesForConduit() {
|
|
return array(
|
|
'name' => $this->getName(),
|
|
'creatorPHID' => $this->getCreatorPHID(),
|
|
'status' => $this->getStatus(),
|
|
);
|
|
}
|
|
|
|
public function getConduitSearchAttachments() {
|
|
return array();
|
|
}
|
|
|
|
/* -( PhabricatorNgramInterface )------------------------------------------ */
|
|
|
|
|
|
public function newNgrams() {
|
|
return array(
|
|
id(new PhabricatorBadgesBadgeNameNgrams())
|
|
->setValue($this->getName()),
|
|
);
|
|
}
|
|
|
|
}
|