Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/storage/AlmanacNamespace.php
<?php | <?php | ||||
final class AlmanacNamespace | final class AlmanacNamespace | ||||
extends AlmanacDAO | extends AlmanacDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
PhabricatorProjectInterface, | PhabricatorProjectInterface, | ||||
PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
PhabricatorNgramsInterface, | PhabricatorNgramsInterface, | ||||
PhabricatorConduitResultInterface { | PhabricatorConduitResultInterface { | ||||
protected $name; | protected $name; | ||||
protected $nameIndex; | protected $nameIndex; | ||||
protected $mailKey; | |||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
public static function initializeNewNamespace() { | public static function initializeNewNamespace() { | ||||
return id(new self()) | return id(new self()) | ||||
->setViewPolicy(PhabricatorPolicies::POLICY_USER) | ->setViewPolicy(PhabricatorPolicies::POLICY_USER) | ||||
->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN); | ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN); | ||||
} | } | ||||
protected function getConfiguration() { | protected function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
'name' => 'text128', | 'name' => 'text128', | ||||
'nameIndex' => 'bytes12', | 'nameIndex' => 'bytes12', | ||||
'mailKey' => 'bytes20', | |||||
), | ), | ||||
self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
'key_nameindex' => array( | 'key_nameindex' => array( | ||||
'columns' => array('nameIndex'), | 'columns' => array('nameIndex'), | ||||
'unique' => true, | 'unique' => true, | ||||
), | ), | ||||
'key_name' => array( | 'key_name' => array( | ||||
'columns' => array('name'), | 'columns' => array('name'), | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
public function generatePHID() { | public function getPHIDType() { | ||||
return PhabricatorPHID::generateNewPHID( | return AlmanacNamespacePHIDType::TYPECONST; | ||||
AlmanacNamespacePHIDType::TYPECONST); | |||||
} | } | ||||
public function save() { | public function save() { | ||||
AlmanacNames::validateName($this->getName()); | AlmanacNames::validateName($this->getName()); | ||||
$this->nameIndex = PhabricatorHash::digestForIndex($this->getName()); | $this->nameIndex = PhabricatorHash::digestForIndex($this->getName()); | ||||
if (!$this->mailKey) { | |||||
$this->mailKey = Filesystem::readRandomCharacters(20); | |||||
} | |||||
return parent::save(); | return parent::save(); | ||||
} | } | ||||
public function getURI() { | public function getURI() { | ||||
return '/almanac/namespace/view/'.$this->getName().'/'; | return urisprintf( | ||||
'/almanac/namespace/view/%s/', | |||||
$this->getName()); | |||||
} | } | ||||
public function getNameLength() { | public function getNameLength() { | ||||
return strlen($this->getName()); | return strlen($this->getName()); | ||||
} | } | ||||
/** | /** | ||||
* Load the namespace which prevents use of an Almanac name, if one exists. | * Load the namespace which prevents use of an Almanac name, if one exists. | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |