Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/storage/PhabricatorProject.php
| Show All 27 Lines | final class PhabricatorProject extends PhabricatorProjectDAO | ||||
| protected $parentProjectPHID; | protected $parentProjectPHID; | ||||
| protected $hasWorkboard; | protected $hasWorkboard; | ||||
| protected $hasMilestones; | protected $hasMilestones; | ||||
| protected $hasSubprojects; | protected $hasSubprojects; | ||||
| protected $milestoneNumber; | protected $milestoneNumber; | ||||
| protected $projectPath; | protected $projectPath; | ||||
| protected $projectDepth; | protected $projectDepth; | ||||
| protected $projectPathKey; | |||||
| private $memberPHIDs = self::ATTACHABLE; | private $memberPHIDs = self::ATTACHABLE; | ||||
| private $watcherPHIDs = self::ATTACHABLE; | private $watcherPHIDs = self::ATTACHABLE; | ||||
| private $sparseWatchers = self::ATTACHABLE; | private $sparseWatchers = self::ATTACHABLE; | ||||
| private $sparseMembers = self::ATTACHABLE; | private $sparseMembers = self::ATTACHABLE; | ||||
| private $customFields = self::ATTACHABLE; | private $customFields = self::ATTACHABLE; | ||||
| private $profileImageFile = self::ATTACHABLE; | private $profileImageFile = self::ATTACHABLE; | ||||
| private $slugs = self::ATTACHABLE; | private $slugs = self::ATTACHABLE; | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | return array( | ||||
| 'joinPolicy' => 'policy', | 'joinPolicy' => 'policy', | ||||
| 'parentProjectPHID' => 'phid?', | 'parentProjectPHID' => 'phid?', | ||||
| 'hasWorkboard' => 'bool', | 'hasWorkboard' => 'bool', | ||||
| 'hasMilestones' => 'bool', | 'hasMilestones' => 'bool', | ||||
| 'hasSubprojects' => 'bool', | 'hasSubprojects' => 'bool', | ||||
| 'milestoneNumber' => 'uint32?', | 'milestoneNumber' => 'uint32?', | ||||
| 'projectPath' => 'hashpath64', | 'projectPath' => 'hashpath64', | ||||
| 'projectDepth' => 'uint32', | 'projectDepth' => 'uint32', | ||||
| 'projectPathKey' => 'bytes4', | |||||
| ), | ), | ||||
| self::CONFIG_KEY_SCHEMA => array( | self::CONFIG_KEY_SCHEMA => array( | ||||
| 'key_phid' => null, | 'key_phid' => null, | ||||
| 'phid' => array( | 'phid' => array( | ||||
| 'columns' => array('phid'), | 'columns' => array('phid'), | ||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| 'key_icon' => array( | 'key_icon' => array( | ||||
| Show All 12 Lines | return array( | ||||
| ), | ), | ||||
| 'key_primaryslug' => array( | 'key_primaryslug' => array( | ||||
| 'columns' => array('primarySlug'), | 'columns' => array('primarySlug'), | ||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| 'key_path' => array( | 'key_path' => array( | ||||
| 'columns' => array('projectPath', 'projectDepth'), | 'columns' => array('projectPath', 'projectDepth'), | ||||
| ), | ), | ||||
| 'key_pathkey' => array( | |||||
| 'columns' => array('projectPathKey'), | |||||
| 'unique' => true, | |||||
| ), | |||||
| ), | ), | ||||
| ) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
| } | } | ||||
| public function generatePHID() { | public function generatePHID() { | ||||
| return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
| PhabricatorProjectProjectPHIDType::TYPECONST); | PhabricatorProjectProjectPHIDType::TYPECONST); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | public function save() { | ||||
| if (!$this->getMailKey()) { | if (!$this->getMailKey()) { | ||||
| $this->setMailKey(Filesystem::readRandomCharacters(20)); | $this->setMailKey(Filesystem::readRandomCharacters(20)); | ||||
| } | } | ||||
| if (!strlen($this->getPHID())) { | if (!strlen($this->getPHID())) { | ||||
| $this->setPHID($this->generatePHID()); | $this->setPHID($this->generatePHID()); | ||||
| } | } | ||||
| if (!strlen($this->getProjectPathKey())) { | |||||
| $hash = PhabricatorHash::digestForIndex($this->getPHID()); | |||||
| $hash = substr($hash, 0, 4); | |||||
| $this->setProjectPathKey($hash); | |||||
| } | |||||
| $path = array(); | $path = array(); | ||||
| $depth = 0; | $depth = 0; | ||||
| if ($this->parentProjectPHID) { | if ($this->parentProjectPHID) { | ||||
| $parent = $this->getParentProject(); | $parent = $this->getParentProject(); | ||||
| $path[] = $parent->getProjectPath(); | $path[] = $parent->getProjectPath(); | ||||
| $depth = $parent->getProjectDepth() + 1; | $depth = $parent->getProjectDepth() + 1; | ||||
| } | } | ||||
| $hash = PhabricatorHash::digestForIndex($this->getPHID()); | $path[] = $this->getProjectPathKey(); | ||||
| $path[] = substr($hash, 0, 4); | |||||
| $path = implode('', $path); | $path = implode('', $path); | ||||
| $limit = self::getProjectDepthLimit(); | $limit = self::getProjectDepthLimit(); | ||||
| if (strlen($path) > ($limit * 4)) { | if ($depth >= $limit) { | ||||
| throw new Exception( | throw new Exception(pht('Project depth is too great.')); | ||||
| pht('Unable to save project: path length is too long.')); | |||||
| } | } | ||||
| $this->setProjectPath($path); | $this->setProjectPath($path); | ||||
| $this->setProjectDepth($depth); | $this->setProjectDepth($depth); | ||||
| $this->openTransaction(); | $this->openTransaction(); | ||||
| $result = parent::save(); | $result = parent::save(); | ||||
| $this->updateDatasourceTokens(); | $this->updateDatasourceTokens(); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | final class PhabricatorProject extends PhabricatorProjectDAO | ||||
| } | } | ||||
| public function getAncestorProjectPaths() { | public function getAncestorProjectPaths() { | ||||
| $parts = array(); | $parts = array(); | ||||
| $path = $this->getProjectPath(); | $path = $this->getProjectPath(); | ||||
| $parent_length = (strlen($path) - 4); | $parent_length = (strlen($path) - 4); | ||||
| for ($ii = $parent_length; $ii >= 0; $ii -= 4) { | for ($ii = $parent_length; $ii > 0; $ii -= 4) { | ||||
| $parts[] = substr($path, 0, $ii); | $parts[] = substr($path, 0, $ii); | ||||
| } | } | ||||
| return $parts; | return $parts; | ||||
| } | } | ||||
| public function getAncestorProjects() { | public function getAncestorProjects() { | ||||
| $ancestors = array(); | $ancestors = array(); | ||||
| ▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines | |||||