Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/storage/PhabricatorProject.php
| <?php | <?php | ||||
| final class PhabricatorProject extends PhabricatorProjectDAO | final class PhabricatorProject extends PhabricatorProjectDAO | ||||
| implements | implements | ||||
| PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
| PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
| PhabricatorCustomFieldInterface, | PhabricatorCustomFieldInterface, | ||||
| PhabricatorDestructibleInterface { | PhabricatorDestructibleInterface { | ||||
| protected $name; | protected $name; | ||||
| protected $status = PhabricatorProjectStatus::STATUS_ACTIVE; | protected $status = PhabricatorProjectStatus::STATUS_ACTIVE; | ||||
| protected $authorPHID; | protected $authorPHID; | ||||
| protected $subprojectPHIDs = array(); | protected $primarySlug; | ||||
| protected $phrictionSlug; | |||||
| protected $profileImagePHID; | protected $profileImagePHID; | ||||
| protected $icon; | protected $icon; | ||||
| protected $color; | protected $color; | ||||
| protected $mailKey; | protected $mailKey; | ||||
| protected $viewPolicy; | protected $viewPolicy; | ||||
| protected $editPolicy; | protected $editPolicy; | ||||
| protected $joinPolicy; | protected $joinPolicy; | ||||
| protected $isMembershipLocked; | protected $isMembershipLocked; | ||||
| protected $parentProjectPHID; | |||||
| protected $hasWorkboard; | |||||
| protected $hasMilestones; | |||||
| protected $hasSubprojects; | |||||
| protected $milestoneNumber; | |||||
| 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; | ||||
| private $parentProject = self::ATTACHABLE; | |||||
| const DEFAULT_ICON = 'fa-briefcase'; | const DEFAULT_ICON = 'fa-briefcase'; | ||||
| const DEFAULT_COLOR = 'blue'; | const DEFAULT_COLOR = 'blue'; | ||||
| const TABLE_DATASOURCE_TOKEN = 'project_datasourcetoken'; | const TABLE_DATASOURCE_TOKEN = 'project_datasourcetoken'; | ||||
| public static function initializeNewProject(PhabricatorUser $actor) { | public static function initializeNewProject(PhabricatorUser $actor) { | ||||
| $app = id(new PhabricatorApplicationQuery()) | $app = id(new PhabricatorApplicationQuery()) | ||||
| Show All 12 Lines | return id(new PhabricatorProject()) | ||||
| ->setAuthorPHID($actor->getPHID()) | ->setAuthorPHID($actor->getPHID()) | ||||
| ->setIcon(self::DEFAULT_ICON) | ->setIcon(self::DEFAULT_ICON) | ||||
| ->setColor(self::DEFAULT_COLOR) | ->setColor(self::DEFAULT_COLOR) | ||||
| ->setViewPolicy($view_policy) | ->setViewPolicy($view_policy) | ||||
| ->setEditPolicy($edit_policy) | ->setEditPolicy($edit_policy) | ||||
| ->setJoinPolicy($join_policy) | ->setJoinPolicy($join_policy) | ||||
| ->setIsMembershipLocked(0) | ->setIsMembershipLocked(0) | ||||
| ->attachMemberPHIDs(array()) | ->attachMemberPHIDs(array()) | ||||
| ->attachSlugs(array()); | ->attachSlugs(array()) | ||||
| ->setHasWorkboard(0) | |||||
| ->setHasMilestones(0) | |||||
| ->setHasSubprojects(0); | |||||
| } | } | ||||
| public function getCapabilities() { | public function getCapabilities() { | ||||
| return array( | return array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
| PhabricatorPolicyCapability::CAN_JOIN, | PhabricatorPolicyCapability::CAN_JOIN, | ||||
| ); | ); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | public function setIsUserMember($user_phid, $is_member) { | ||||
| } | } | ||||
| $this->sparseMembers[$user_phid] = $is_member; | $this->sparseMembers[$user_phid] = $is_member; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getConfiguration() { | protected function getConfiguration() { | ||||
| return array( | return array( | ||||
| self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
| self::CONFIG_SERIALIZATION => array( | |||||
| 'subprojectPHIDs' => self::SERIALIZATION_JSON, | |||||
| ), | |||||
| self::CONFIG_COLUMN_SCHEMA => array( | self::CONFIG_COLUMN_SCHEMA => array( | ||||
| 'name' => 'sort128', | 'name' => 'sort128', | ||||
| 'status' => 'text32', | 'status' => 'text32', | ||||
| 'phrictionSlug' => 'text128?', | 'primarySlug' => 'text128?', | ||||
| 'isMembershipLocked' => 'bool', | 'isMembershipLocked' => 'bool', | ||||
| 'profileImagePHID' => 'phid?', | 'profileImagePHID' => 'phid?', | ||||
| 'icon' => 'text32', | 'icon' => 'text32', | ||||
| 'color' => 'text32', | 'color' => 'text32', | ||||
| 'mailKey' => 'bytes20', | 'mailKey' => 'bytes20', | ||||
| 'joinPolicy' => 'policy', | |||||
| // T6203/NULLABILITY | 'parentProjectPHID' => 'phid?', | ||||
| // These are definitely wrong and should always exist. | 'hasWorkboard' => 'bool', | ||||
| 'editPolicy' => 'policy?', | 'hasMilestones' => 'bool', | ||||
| 'viewPolicy' => 'policy?', | 'hasSubprojects' => 'bool', | ||||
| 'joinPolicy' => 'policy?', | 'milestoneNumber' => 'uint32?', | ||||
| ), | ), | ||||
| 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( | ||||
| 'columns' => array('icon'), | 'columns' => array('icon'), | ||||
| ), | ), | ||||
| 'key_color' => array( | 'key_color' => array( | ||||
| 'columns' => array('color'), | 'columns' => array('color'), | ||||
| ), | ), | ||||
| 'phrictionSlug' => array( | |||||
| 'columns' => array('phrictionSlug'), | |||||
| 'unique' => true, | |||||
| ), | |||||
| 'name' => array( | 'name' => array( | ||||
| 'columns' => array('name'), | 'columns' => array('name'), | ||||
| 'unique' => true, | 'unique' => true, | ||||
| ), | ), | ||||
| 'key_milestone' => array( | |||||
| 'columns' => array('parentProjectPHID', 'milestoneNumber'), | |||||
| 'unique' => true, | |||||
| ), | |||||
| 'key_primaryslug' => array( | |||||
| 'columns' => array('primarySlug'), | |||||
| 'unique' => true, | |||||
| ), | |||||
| ), | ), | ||||
| ) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
| } | } | ||||
| public function generatePHID() { | public function generatePHID() { | ||||
| return PhabricatorPHID::generateNewPHID( | return PhabricatorPHID::generateNewPHID( | ||||
| PhabricatorProjectProjectPHIDType::TYPECONST); | PhabricatorProjectProjectPHIDType::TYPECONST); | ||||
| } | } | ||||
| public function attachMemberPHIDs(array $phids) { | public function attachMemberPHIDs(array $phids) { | ||||
| $this->memberPHIDs = $phids; | $this->memberPHIDs = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getMemberPHIDs() { | public function getMemberPHIDs() { | ||||
| return $this->assertAttached($this->memberPHIDs); | return $this->assertAttached($this->memberPHIDs); | ||||
| } | } | ||||
| public function setPrimarySlug($slug) { | |||||
| $this->phrictionSlug = $slug.'/'; | |||||
| return $this; | |||||
| } | |||||
| // TODO - once we sever project => phriction automagicalness, | |||||
| // migrate getPhrictionSlug to have no trailing slash and be called | |||||
| // getPrimarySlug | |||||
| public function getPrimarySlug() { | |||||
| $slug = $this->getPhrictionSlug(); | |||||
| return rtrim($slug, '/'); | |||||
| } | |||||
| public function isArchived() { | public function isArchived() { | ||||
| return ($this->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED); | return ($this->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED); | ||||
| } | } | ||||
| public function getProfileImageURI() { | public function getProfileImageURI() { | ||||
| return $this->getProfileImageFile()->getBestURI(); | return $this->getProfileImageFile()->getBestURI(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | $this->openTransaction(); | ||||
| $conn_w, | $conn_w, | ||||
| 'INSERT INTO %T (projectID, token) VALUES %Q', | 'INSERT INTO %T (projectID, token) VALUES %Q', | ||||
| $table, | $table, | ||||
| $chunk); | $chunk); | ||||
| } | } | ||||
| $this->saveTransaction(); | $this->saveTransaction(); | ||||
| } | } | ||||
| public function isMilestone() { | |||||
| return ($this->getMilestoneNumber() !== null); | |||||
| } | |||||
| public function getParentProject() { | |||||
| return $this->assertAttached($this->parentProject); | |||||
| } | |||||
| public function attachParentProject(PhabricatorProject $project) { | |||||
| $this->parentProject = $project; | |||||
| return $this; | |||||
| } | |||||
| /* -( PhabricatorSubscribableInterface )----------------------------------- */ | /* -( PhabricatorSubscribableInterface )----------------------------------- */ | ||||
| public function isAutomaticallySubscribed($phid) { | public function isAutomaticallySubscribed($phid) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines | |||||