Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / metamta / storage / PhabricatorMetaMTAMailProperties.php
blobeb454b650e148be6066cd926c1afc57e379991f3
1 <?php
3 final class PhabricatorMetaMTAMailProperties
4 extends PhabricatorMetaMTADAO
5 implements PhabricatorPolicyInterface {
7 protected $objectPHID;
8 protected $mailProperties = array();
10 protected function getConfiguration() {
11 return array(
12 self::CONFIG_SERIALIZATION => array(
13 'mailProperties' => self::SERIALIZATION_JSON,
15 self::CONFIG_COLUMN_SCHEMA => array(),
16 self::CONFIG_KEY_SCHEMA => array(
17 'key_object' => array(
18 'columns' => array('objectPHID'),
19 'unique' => true,
22 ) + parent::getConfiguration();
25 public function getMailProperty($key, $default = null) {
26 return idx($this->mailProperties, $key, $default);
29 public function setMailProperty($key, $value) {
30 $this->mailProperties[$key] = $value;
31 return $this;
34 public static function loadMailKey($object) {
35 // If this is an older object with an onboard "mailKey" property, just
36 // use it.
37 // TODO: We should eventually get rid of these and get rid of this
38 // piece of code.
39 if ($object->hasProperty('mailKey')) {
40 return $object->getMailKey();
43 $viewer = PhabricatorUser::getOmnipotentUser();
44 $object_phid = $object->getPHID();
46 $properties = id(new PhabricatorMetaMTAMailPropertiesQuery())
47 ->setViewer($viewer)
48 ->withObjectPHIDs(array($object_phid))
49 ->executeOne();
50 if (!$properties) {
51 $properties = id(new self())
52 ->setObjectPHID($object_phid);
55 $mail_key = $properties->getMailProperty('mailKey');
56 if ($mail_key !== null) {
57 return $mail_key;
60 $mail_key = Filesystem::readRandomCharacters(20);
61 $properties->setMailProperty('mailKey', $mail_key);
63 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
64 $properties->save();
65 unset($unguarded);
67 return $mail_key;
71 /* -( PhabricatorPolicyInterface )----------------------------------------- */
74 public function getCapabilities() {
75 return array(
76 PhabricatorPolicyCapability::CAN_VIEW,
80 public function getPolicy($capability) {
81 switch ($capability) {
82 case PhabricatorPolicyCapability::CAN_VIEW:
83 return PhabricatorPolicies::POLICY_NOONE;
87 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
88 return false;