Path: blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMailProperties.php
12256 views
<?php12final class PhabricatorMetaMTAMailProperties3extends PhabricatorMetaMTADAO4implements PhabricatorPolicyInterface {56protected $objectPHID;7protected $mailProperties = array();89protected function getConfiguration() {10return array(11self::CONFIG_SERIALIZATION => array(12'mailProperties' => self::SERIALIZATION_JSON,13),14self::CONFIG_COLUMN_SCHEMA => array(),15self::CONFIG_KEY_SCHEMA => array(16'key_object' => array(17'columns' => array('objectPHID'),18'unique' => true,19),20),21) + parent::getConfiguration();22}2324public function getMailProperty($key, $default = null) {25return idx($this->mailProperties, $key, $default);26}2728public function setMailProperty($key, $value) {29$this->mailProperties[$key] = $value;30return $this;31}3233public static function loadMailKey($object) {34// If this is an older object with an onboard "mailKey" property, just35// use it.36// TODO: We should eventually get rid of these and get rid of this37// piece of code.38if ($object->hasProperty('mailKey')) {39return $object->getMailKey();40}4142$viewer = PhabricatorUser::getOmnipotentUser();43$object_phid = $object->getPHID();4445$properties = id(new PhabricatorMetaMTAMailPropertiesQuery())46->setViewer($viewer)47->withObjectPHIDs(array($object_phid))48->executeOne();49if (!$properties) {50$properties = id(new self())51->setObjectPHID($object_phid);52}5354$mail_key = $properties->getMailProperty('mailKey');55if ($mail_key !== null) {56return $mail_key;57}5859$mail_key = Filesystem::readRandomCharacters(20);60$properties->setMailProperty('mailKey', $mail_key);6162$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();63$properties->save();64unset($unguarded);6566return $mail_key;67}686970/* -( PhabricatorPolicyInterface )----------------------------------------- */717273public function getCapabilities() {74return array(75PhabricatorPolicyCapability::CAN_VIEW,76);77}7879public function getPolicy($capability) {80switch ($capability) {81case PhabricatorPolicyCapability::CAN_VIEW:82return PhabricatorPolicies::POLICY_NOONE;83}84}8586public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {87return false;88}8990}919293