2011-02-20 18:41:23 -08:00
|
|
|
<?php
|
|
|
|
|
2012-08-08 17:10:10 -07:00
|
|
|
final class PhabricatorProject extends PhabricatorProjectDAO
|
2013-10-25 12:52:00 -07:00
|
|
|
implements
|
2014-12-03 12:28:53 -08:00
|
|
|
PhabricatorApplicationTransactionInterface,
|
2013-10-25 12:52:00 -07:00
|
|
|
PhabricatorFlaggableInterface,
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 14:29:17 -08:00
|
|
|
PhabricatorPolicyInterface,
|
2015-12-23 03:42:51 -08:00
|
|
|
PhabricatorExtendedPolicyInterface,
|
2014-02-10 14:31:34 -08:00
|
|
|
PhabricatorSubscribableInterface,
|
2014-06-02 17:10:29 -07:00
|
|
|
PhabricatorCustomFieldInterface,
|
2015-12-21 09:02:55 -08:00
|
|
|
PhabricatorDestructibleInterface,
|
|
|
|
PhabricatorFulltextInterface {
|
2011-02-20 18:41:23 -08:00
|
|
|
|
|
|
|
protected $name;
|
2012-02-07 14:59:38 -08:00
|
|
|
protected $status = PhabricatorProjectStatus::STATUS_ACTIVE;
|
2011-02-20 18:41:23 -08:00
|
|
|
protected $authorPHID;
|
2015-12-19 08:08:26 -08:00
|
|
|
protected $primarySlug;
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
protected $profileImagePHID;
|
2014-05-23 10:41:24 -07:00
|
|
|
protected $icon;
|
2014-06-25 22:01:58 -07:00
|
|
|
protected $color;
|
2015-05-16 06:13:27 -07:00
|
|
|
protected $mailKey;
|
2011-07-19 15:50:15 -03:00
|
|
|
|
2012-08-11 07:05:01 -07:00
|
|
|
protected $viewPolicy;
|
|
|
|
protected $editPolicy;
|
|
|
|
protected $joinPolicy;
|
2014-09-18 11:00:50 -07:00
|
|
|
protected $isMembershipLocked;
|
2012-08-11 07:05:01 -07:00
|
|
|
|
2015-12-19 08:08:26 -08:00
|
|
|
protected $parentProjectPHID;
|
|
|
|
protected $hasWorkboard;
|
|
|
|
protected $hasMilestones;
|
|
|
|
protected $hasSubprojects;
|
|
|
|
protected $milestoneNumber;
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
protected $projectPath;
|
|
|
|
protected $projectDepth;
|
|
|
|
|
2013-09-03 06:02:14 -07:00
|
|
|
private $memberPHIDs = self::ATTACHABLE;
|
2014-05-19 12:40:57 -07:00
|
|
|
private $watcherPHIDs = self::ATTACHABLE;
|
|
|
|
private $sparseWatchers = self::ATTACHABLE;
|
2013-09-03 06:02:14 -07:00
|
|
|
private $sparseMembers = self::ATTACHABLE;
|
2014-02-10 14:31:34 -08:00
|
|
|
private $customFields = self::ATTACHABLE;
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
private $profileImageFile = self::ATTACHABLE;
|
2014-05-22 11:19:03 -07:00
|
|
|
private $slugs = self::ATTACHABLE;
|
2015-12-19 08:08:26 -08:00
|
|
|
private $parentProject = self::ATTACHABLE;
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2014-05-23 10:41:24 -07:00
|
|
|
const DEFAULT_ICON = 'fa-briefcase';
|
2014-06-25 22:01:58 -07:00
|
|
|
const DEFAULT_COLOR = 'blue';
|
2014-05-23 10:41:24 -07:00
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
const TABLE_DATASOURCE_TOKEN = 'project_datasourcetoken';
|
|
|
|
|
2014-02-10 14:30:17 -08:00
|
|
|
public static function initializeNewProject(PhabricatorUser $actor) {
|
2014-11-21 11:22:17 -08:00
|
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withClasses(array('PhabricatorProjectApplication'))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
$view_policy = $app->getPolicy(
|
|
|
|
ProjectDefaultViewCapability::CAPABILITY);
|
|
|
|
$edit_policy = $app->getPolicy(
|
|
|
|
ProjectDefaultEditCapability::CAPABILITY);
|
|
|
|
$join_policy = $app->getPolicy(
|
|
|
|
ProjectDefaultJoinCapability::CAPABILITY);
|
|
|
|
|
2014-02-10 14:30:17 -08:00
|
|
|
return id(new PhabricatorProject())
|
|
|
|
->setAuthorPHID($actor->getPHID())
|
2014-05-23 10:41:24 -07:00
|
|
|
->setIcon(self::DEFAULT_ICON)
|
2014-06-25 22:01:58 -07:00
|
|
|
->setColor(self::DEFAULT_COLOR)
|
2014-11-21 11:22:17 -08:00
|
|
|
->setViewPolicy($view_policy)
|
|
|
|
->setEditPolicy($edit_policy)
|
|
|
|
->setJoinPolicy($join_policy)
|
2014-09-18 11:00:50 -07:00
|
|
|
->setIsMembershipLocked(0)
|
2014-10-10 16:57:05 -07:00
|
|
|
->attachMemberPHIDs(array())
|
2015-12-19 08:08:26 -08:00
|
|
|
->attachSlugs(array())
|
|
|
|
->setHasWorkboard(0)
|
|
|
|
->setHasMilestones(0)
|
2015-12-23 03:42:51 -08:00
|
|
|
->setHasSubprojects(0)
|
|
|
|
->attachParentProject(null);
|
2014-02-10 14:30:17 -08:00
|
|
|
}
|
|
|
|
|
2012-08-08 17:10:10 -07:00
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
2012-08-11 07:05:01 -07:00
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
PhabricatorPolicyCapability::CAN_JOIN,
|
2012-08-08 17:10:10 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
2012-08-11 07:05:01 -07:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->getViewPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_JOIN:
|
|
|
|
return $this->getJoinPolicy();
|
|
|
|
}
|
2012-08-08 17:10:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
2015-12-23 03:42:51 -08:00
|
|
|
$can_edit = PhabricatorPolicyCapability::CAN_EDIT;
|
2012-08-11 07:05:01 -07:00
|
|
|
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
if ($this->isUserMember($viewer->getPHID())) {
|
|
|
|
// Project members can always view a project.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
2015-12-23 03:42:51 -08:00
|
|
|
$parent = $this->getParentProject();
|
|
|
|
if ($parent) {
|
|
|
|
$can_edit_parent = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$parent,
|
|
|
|
$can_edit);
|
|
|
|
if ($can_edit_parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-08-11 07:05:01 -07:00
|
|
|
break;
|
|
|
|
case PhabricatorPolicyCapability::CAN_JOIN:
|
|
|
|
if (PhabricatorPolicyFilter::hasCapability($viewer, $this, $can_edit)) {
|
|
|
|
// Project editors can always join a project.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-08 17:10:10 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-27 08:43:41 -07:00
|
|
|
public function describeAutomaticCapability($capability) {
|
2015-12-23 03:42:51 -08:00
|
|
|
|
|
|
|
// TODO: Clarify the additional rules that parent and subprojects imply.
|
|
|
|
|
2013-09-27 08:43:41 -07:00
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
2014-06-09 11:36:49 -07:00
|
|
|
return pht('Members of a project can always view it.');
|
2013-09-27 08:43:41 -07:00
|
|
|
case PhabricatorPolicyCapability::CAN_JOIN:
|
2014-06-09 11:36:49 -07:00
|
|
|
return pht('Users who can edit a project can always join it.');
|
2013-09-27 08:43:41 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
|
|
|
|
$extended = array();
|
|
|
|
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
$parent = $this->getParentProject();
|
|
|
|
if ($parent) {
|
|
|
|
$extended[] = array(
|
|
|
|
$parent,
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $extended;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-11 07:05:01 -07:00
|
|
|
public function isUserMember($user_phid) {
|
2014-02-10 14:30:17 -08:00
|
|
|
if ($this->memberPHIDs !== self::ATTACHABLE) {
|
|
|
|
return in_array($user_phid, $this->memberPHIDs);
|
|
|
|
}
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttachedKey($this->sparseMembers, $user_phid);
|
2012-08-11 07:05:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsUserMember($user_phid, $is_member) {
|
2013-09-03 06:02:14 -07:00
|
|
|
if ($this->sparseMembers === self::ATTACHABLE) {
|
|
|
|
$this->sparseMembers = array();
|
|
|
|
}
|
2012-08-11 07:05:01 -07:00
|
|
|
$this->sparseMembers[$user_phid] = $is_member;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-14 06:47:05 +11:00
|
|
|
protected function getConfiguration() {
|
2011-02-20 18:41:23 -08:00
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2014-10-01 07:37:01 -07:00
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
2014-10-01 08:18:53 -07:00
|
|
|
'name' => 'sort128',
|
2014-10-01 07:37:01 -07:00
|
|
|
'status' => 'text32',
|
2015-12-19 08:08:26 -08:00
|
|
|
'primarySlug' => 'text128?',
|
2014-10-01 07:37:01 -07:00
|
|
|
'isMembershipLocked' => 'bool',
|
|
|
|
'profileImagePHID' => 'phid?',
|
|
|
|
'icon' => 'text32',
|
|
|
|
'color' => 'text32',
|
2015-05-16 06:13:27 -07:00
|
|
|
'mailKey' => 'bytes20',
|
2015-12-19 08:08:26 -08:00
|
|
|
'joinPolicy' => 'policy',
|
|
|
|
'parentProjectPHID' => 'phid?',
|
|
|
|
'hasWorkboard' => 'bool',
|
|
|
|
'hasMilestones' => 'bool',
|
|
|
|
'hasSubprojects' => 'bool',
|
|
|
|
'milestoneNumber' => 'uint32?',
|
2015-12-23 03:42:51 -08:00
|
|
|
'projectPath' => 'hashpath64',
|
|
|
|
'projectDepth' => 'uint32',
|
2014-10-01 07:37:01 -07:00
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_phid' => null,
|
|
|
|
'phid' => array(
|
|
|
|
'columns' => array('phid'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'key_icon' => array(
|
|
|
|
'columns' => array('icon'),
|
|
|
|
),
|
|
|
|
'key_color' => array(
|
|
|
|
'columns' => array('color'),
|
|
|
|
),
|
|
|
|
'name' => array(
|
|
|
|
'columns' => array('name'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
2015-12-19 08:08:26 -08:00
|
|
|
'key_milestone' => array(
|
|
|
|
'columns' => array('parentProjectPHID', 'milestoneNumber'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
'key_primaryslug' => array(
|
|
|
|
'columns' => array('primarySlug'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
2015-12-23 03:42:51 -08:00
|
|
|
'key_path' => array(
|
|
|
|
'columns' => array('projectPath', 'projectDepth'),
|
|
|
|
),
|
2014-10-01 07:37:01 -07:00
|
|
|
),
|
2011-02-20 18:41:23 -08:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2011-03-02 18:58:21 -08:00
|
|
|
return PhabricatorPHID::generateNewPHID(
|
2014-07-24 08:05:46 +10:00
|
|
|
PhabricatorProjectProjectPHIDType::TYPECONST);
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
2012-08-07 18:02:05 -07:00
|
|
|
public function attachMemberPHIDs(array $phids) {
|
|
|
|
$this->memberPHIDs = $phids;
|
|
|
|
return $this;
|
2012-08-07 11:55:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-07 18:02:05 -07:00
|
|
|
public function getMemberPHIDs() {
|
2013-09-03 06:02:14 -07:00
|
|
|
return $this->assertAttached($this->memberPHIDs);
|
2012-01-17 16:29:35 -08:00
|
|
|
}
|
|
|
|
|
2014-02-10 14:30:47 -08:00
|
|
|
public function isArchived() {
|
|
|
|
return ($this->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED);
|
|
|
|
}
|
|
|
|
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
public function getProfileImageURI() {
|
|
|
|
return $this->getProfileImageFile()->getBestURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachProfileImageFile(PhabricatorFile $file) {
|
|
|
|
$this->profileImageFile = $file;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProfileImageFile() {
|
|
|
|
return $this->assertAttached($this->profileImageFile);
|
|
|
|
}
|
|
|
|
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 14:29:17 -08:00
|
|
|
|
2014-05-19 12:40:57 -07:00
|
|
|
public function isUserWatcher($user_phid) {
|
|
|
|
if ($this->watcherPHIDs !== self::ATTACHABLE) {
|
|
|
|
return in_array($user_phid, $this->watcherPHIDs);
|
|
|
|
}
|
|
|
|
return $this->assertAttachedKey($this->sparseWatchers, $user_phid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsUserWatcher($user_phid, $is_watcher) {
|
|
|
|
if ($this->sparseWatchers === self::ATTACHABLE) {
|
|
|
|
$this->sparseWatchers = array();
|
|
|
|
}
|
|
|
|
$this->sparseWatchers[$user_phid] = $is_watcher;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachWatcherPHIDs(array $phids) {
|
|
|
|
$this->watcherPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getWatcherPHIDs() {
|
|
|
|
return $this->assertAttached($this->watcherPHIDs);
|
|
|
|
}
|
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
public function attachSlugs(array $slugs) {
|
|
|
|
$this->slugs = $slugs;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSlugs() {
|
|
|
|
return $this->assertAttached($this->slugs);
|
|
|
|
}
|
|
|
|
|
2014-06-25 22:01:58 -07:00
|
|
|
public function getColor() {
|
|
|
|
if ($this->isArchived()) {
|
|
|
|
return PHUITagView::COLOR_DISABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->color;
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
public function save() {
|
2015-05-16 19:39:22 -07:00
|
|
|
if (!$this->getMailKey()) {
|
|
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
if (!strlen($this->getPHID())) {
|
|
|
|
$this->setPHID($this->generatePHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = array();
|
|
|
|
$depth = 0;
|
|
|
|
if ($this->parentProjectPHID) {
|
|
|
|
$parent = $this->getParentProject();
|
|
|
|
$path[] = $parent->getProjectPath();
|
|
|
|
$depth = $parent->getProjectDepth() + 1;
|
|
|
|
}
|
|
|
|
$hash = PhabricatorHash::digestForIndex($this->getPHID());
|
|
|
|
$path[] = substr($hash, 0, 4);
|
|
|
|
|
|
|
|
$path = implode('', $path);
|
|
|
|
|
|
|
|
$limit = self::getProjectDepthLimit();
|
|
|
|
if (strlen($path) > ($limit * 4)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht('Unable to save project: path length is too long.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setProjectPath($path);
|
|
|
|
$this->setProjectDepth($depth);
|
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
$this->openTransaction();
|
|
|
|
$result = parent::save();
|
|
|
|
$this->updateDatasourceTokens();
|
|
|
|
$this->saveTransaction();
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
public static function getProjectDepthLimit() {
|
|
|
|
// This is limited by how many path hashes we can fit in the path
|
|
|
|
// column.
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
public function updateDatasourceTokens() {
|
|
|
|
$table = self::TABLE_DATASOURCE_TOKEN;
|
|
|
|
$conn_w = $this->establishConnection('w');
|
|
|
|
$id = $this->getID();
|
|
|
|
|
|
|
|
$slugs = queryfx_all(
|
|
|
|
$conn_w,
|
|
|
|
'SELECT * FROM %T WHERE projectPHID = %s',
|
|
|
|
id(new PhabricatorProjectSlug())->getTableName(),
|
|
|
|
$this->getPHID());
|
|
|
|
|
|
|
|
$all_strings = ipull($slugs, 'slug');
|
|
|
|
$all_strings[] = $this->getName();
|
|
|
|
$all_strings = implode(' ', $all_strings);
|
|
|
|
|
|
|
|
$tokens = PhabricatorTypeaheadDatasource::tokenizeString($all_strings);
|
|
|
|
|
|
|
|
$sql = array();
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
$sql[] = qsprintf($conn_w, '(%d, %s)', $id, $token);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->openTransaction();
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'DELETE FROM %T WHERE projectID = %d',
|
|
|
|
$table,
|
|
|
|
$id);
|
|
|
|
|
|
|
|
foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
|
|
|
|
queryfx(
|
|
|
|
$conn_w,
|
|
|
|
'INSERT INTO %T (projectID, token) VALUES %Q',
|
|
|
|
$table,
|
|
|
|
$chunk);
|
|
|
|
}
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-19 08:08:26 -08:00
|
|
|
public function isMilestone() {
|
|
|
|
return ($this->getMilestoneNumber() !== null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getParentProject() {
|
|
|
|
return $this->assertAttached($this->parentProject);
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
public function attachParentProject(PhabricatorProject $project = null) {
|
2015-12-19 08:08:26 -08:00
|
|
|
$this->parentProject = $project;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
public function getAncestorProjectPaths() {
|
|
|
|
$parts = array();
|
|
|
|
|
|
|
|
$path = $this->getProjectPath();
|
|
|
|
$parent_length = (strlen($path) - 4);
|
|
|
|
|
|
|
|
for ($ii = $parent_length; $ii >= 0; $ii -= 4) {
|
|
|
|
$parts[] = substr($path, 0, $ii);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $parts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAncestorProjects() {
|
|
|
|
$ancestors = array();
|
|
|
|
|
|
|
|
$cursor = $this->getParentProject();
|
|
|
|
while ($cursor) {
|
|
|
|
$ancestors[] = $cursor;
|
|
|
|
$cursor = $cursor->getParentProject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ancestors;
|
|
|
|
}
|
|
|
|
|
2014-05-19 12:40:57 -07:00
|
|
|
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 14:29:17 -08:00
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldShowSubscribersProperty() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAllowSubscription($phid) {
|
2014-05-19 12:40:57 -07:00
|
|
|
return $this->isUserMember($phid) &&
|
|
|
|
!$this->isUserWatcher($phid);
|
Make Projects a PhabricatorSubscribableInterface, but with restricted defaults
Summary:
Ref T4379. I want project subscriptions to work like this (yell if this seems whacky, since it makes subscriptions mean somethign a little different for projects than they do for other objects):
- You can only subscribe to a project if you're a project member.
- When you're added as a member, you're added as a subscriber.
- When you're removed as a member, you're removed as a subscriber.
- While you're a member, you can optionally unsubscribe.
From a UI perspective:
- We don't show the subscriber list, since it's going to be some uninteresting subset of the member list.
- We don't show CC transactions in history, since they're an uninteresting near-approximation of the membership transactions.
- You only see the subscription controls if you're a member.
To do this, I've augmented `PhabricatorSubscribableInterface` with two new methods. It would be nice if we were on PHP 5.4+ and could just use traits for this, but we should get data about version usage before we think about this. For now, copy/paste the default implementations into every implementing class.
Then, I implemented the interface in `PhabricatorProject` but with alternate defaults.
Test Plan:
- Used the normal interaction on existing objects.
- This has no actual effect on projects, verified no subscription stuff mysteriously appeared.
- Hit the new error case by fiddling with the UI.
Reviewers: btrahan
Reviewed By: btrahan
CC: chad, aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8165
2014-02-10 14:29:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 14:31:34 -08:00
|
|
|
/* -( PhabricatorCustomFieldInterface )------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCustomFieldSpecificationForRole($role) {
|
|
|
|
return PhabricatorEnv::getEnvConfig('projects.fields');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomFieldBaseClass() {
|
|
|
|
return 'PhabricatorProjectCustomField';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCustomFields() {
|
|
|
|
return $this->assertAttached($this->customFields);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
|
|
|
|
$this->customFields = $fields;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-03 12:28:53 -08:00
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
|
|
|
return new PhabricatorProjectTransactionEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
|
|
|
return new PhabricatorProjectTransaction();
|
|
|
|
}
|
|
|
|
|
2014-12-04 13:58:52 -08:00
|
|
|
public function willRenderTimeline(
|
|
|
|
PhabricatorApplicationTransactionView $timeline,
|
|
|
|
AphrontRequest $request) {
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
|
2014-12-03 12:28:53 -08:00
|
|
|
|
2014-07-21 23:59:22 +10:00
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
2014-06-02 17:10:29 -07:00
|
|
|
|
2015-12-21 09:02:55 -08:00
|
|
|
|
2014-06-02 17:10:29 -07:00
|
|
|
public function destroyObjectPermanently(
|
|
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
|
|
|
|
$this->openTransaction();
|
|
|
|
$this->delete();
|
|
|
|
|
|
|
|
$columns = id(new PhabricatorProjectColumn())
|
|
|
|
->loadAllWhere('projectPHID = %s', $this->getPHID());
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
$engine->destroyObject($column);
|
|
|
|
}
|
|
|
|
|
|
|
|
$slugs = id(new PhabricatorProjectSlug())
|
|
|
|
->loadAllWhere('projectPHID = %s', $this->getPHID());
|
|
|
|
foreach ($slugs as $slug) {
|
|
|
|
$slug->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
|
|
|
|
2015-12-21 09:02:55 -08:00
|
|
|
|
|
|
|
/* -( PhabricatorFulltextInterface )--------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function newFulltextEngine() {
|
|
|
|
return new PhabricatorProjectFulltextEngine();
|
|
|
|
}
|
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|