private function materializeProject(PhabricatorProject $project) { if ($project->isMilestone()) { return; } $material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST; $member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $project_phid = $project->getPHID(); $descendants = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withAncestorProjectPHIDs(array($project->getPHID()))->withIsMilestone(false)->withHasSubprojects(false)->execute(); $descendant_phids = mpull($descendants, 'getPHID'); if ($descendant_phids) { $source_phids = $descendant_phids; $has_subprojects = true; } else { $source_phids = array($project->getPHID()); $has_subprojects = false; } $conn_w = $project->establishConnection('w'); $project->openTransaction(); // Delete any existing materialized member edges. queryfx($conn_w, 'DELETE FROM %T WHERE src = %s AND type = %s', PhabricatorEdgeConfig::TABLE_NAME_EDGE, $project_phid, $material_type); // Copy current member edges to create new materialized edges. queryfx($conn_w, 'INSERT IGNORE INTO %T (src, type, dst, dateCreated, seq) SELECT %s, %d, dst, dateCreated, seq FROM %T WHERE src IN (%Ls) AND type = %d', PhabricatorEdgeConfig::TABLE_NAME_EDGE, $project_phid, $material_type, PhabricatorEdgeConfig::TABLE_NAME_EDGE, $source_phids, $member_type); // Update the hasSubprojects flag. queryfx($conn_w, 'UPDATE %T SET hasSubprojects = %d WHERE id = %d', $project->getTableName(), (int) $has_subprojects, $project->getID()); $project->saveTransaction(); }
public function buildIconNavView(PhabricatorProject $project) { $id = $project->getID(); $nav = parent::buildIconNavView($project); $nav->selectFilter("board/{$id}/"); return $nav; }
protected function buildLocalNavigation(PhabricatorProject $project) { $id = $project->getID(); $nav_view = new AphrontSideNavFilterView(); $uri = new PhutilURI('/project/view/' . $id . '/'); $nav_view->setBaseURI($uri); $external_arrow = "↗"; $tasks_uri = '/maniphest/view/all/?projects=' . $project->getPHID(); $slug = PhabricatorSlug::normalize($project->getName()); $phriction_uri = '/w/projects/' . $slug; $edit_uri = '/project/edit/' . $id . '/'; $members_uri = '/project/members/' . $id . '/'; $nav_view->addFilter('dashboard', 'Dashboard'); $nav_view->addSpacer(); $nav_view->addFilter('feed', 'Feed'); $nav_view->addFilter(null, 'Tasks ' . $external_arrow, $tasks_uri); $nav_view->addFilter(null, 'Wiki ' . $external_arrow, $phriction_uri); $nav_view->addFilter('people', 'People'); $nav_view->addFilter('about', 'About'); $user = $this->getRequest()->getUser(); $can_edit = PhabricatorPolicyCapability::CAN_EDIT; $nav_view->addSpacer(); if (PhabricatorPolicyFilter::hasCapability($user, $project, $can_edit)) { $nav_view->addFilter('edit', "Edit Project…", $edit_uri); $nav_view->addFilter('members', "Edit Members…", $members_uri); } else { $nav_view->addFilter('edit', "Edit Project…", $edit_uri, $relative = false, 'disabled'); $nav_view->addFilter('members', "Edit Members…", $members_uri, $relative = false, 'disabled'); } return $nav_view; }
private function buildActionList(PhabricatorProject $project, array $milestones, array $subprojects) { $viewer = $this->getViewer(); $id = $project->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $allows_milestones = $project->supportsMilestones(); $allows_subprojects = $project->supportsSubprojects(); $view = id(new PhabricatorActionListView())->setUser($viewer); if ($allows_milestones && $milestones) { $milestone_text = pht('Create Next Milestone'); } else { $milestone_text = pht('Create Milestone'); } $can_milestone = $can_edit && $allows_milestones; $milestone_href = "/project/edit/?milestone={$id}"; $view->addAction(id(new PhabricatorActionView())->setName($milestone_text)->setIcon('fa-plus')->setHref($milestone_href)->setDisabled(!$can_milestone)->setWorkflow(!$can_milestone)); $can_subproject = $can_edit && $allows_subprojects; // If we're offering to create the first subproject, we're going to warn // the user about the effects before moving forward. if ($can_subproject && !$subprojects) { $subproject_href = "/project/warning/{$id}/"; $subproject_disabled = false; $subproject_workflow = true; } else { $subproject_href = "/project/edit/?parent={$id}"; $subproject_disabled = !$can_subproject; $subproject_workflow = !$can_subproject; } $view->addAction(id(new PhabricatorActionView())->setName(pht('Create Subproject'))->setIcon('fa-plus')->setHref($subproject_href)->setDisabled($subproject_disabled)->setWorkflow($subproject_workflow)); return $view; }
public function loadPage() { $table = new PhabricatorProject(); $conn_r = $table->establishConnection('r'); // NOTE: Because visibility checks for projects depend on whether or not // the user is a project member, we always load their membership. If we're // loading all members anyway we can piggyback on that; otherwise we // do an explicit join. $select_clause = ''; if (!$this->needMembers) { $select_clause = ', vm.dst viewerIsMember'; } $data = queryfx_all($conn_r, 'SELECT p.* %Q FROM %T p %Q %Q %Q %Q %Q', $select_clause, $table->getTableName(), $this->buildJoinClause($conn_r), $this->buildWhereClause($conn_r), $this->buildGroupClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); $projects = $table->loadAllFromArray($data); if ($projects) { $viewer_phid = $this->getViewer()->getPHID(); if ($this->needMembers) { $etype = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER; $members = id(new PhabricatorEdgeQuery())->withSourcePHIDs(mpull($projects, 'getPHID'))->withEdgeTypes(array($etype))->execute(); foreach ($projects as $project) { $phid = $project->getPHID(); $project->attachMemberPHIDs(array_keys($members[$phid][$etype])); $project->setIsUserMember($viewer_phid, isset($members[$phid][$etype][$viewer_phid])); } } else { foreach ($data as $row) { $projects[$row['id']]->setIsUserMember($viewer_phid, $row['viewerIsMember'] !== null); } } } return $projects; }
private function buildActionListView(PhabricatorProject $project) { $request = $this->getRequest(); $viewer = $request->getUser(); $id = $project->getID(); $view = id(new PhabricatorActionListView())->setUser($viewer)->setObject($project)->setObjectURI($request->getRequestURI()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Details'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("details/{$id}/"))->setDisabled(!$can_edit)); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Picture'))->setIcon('fa-picture-o')->setHref($this->getApplicationURI("picture/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); if ($project->isArchived()) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Activate Project'))->setIcon('fa-check')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } else { $view->addAction(id(new PhabricatorActionView())->setName(pht('Archive Project'))->setIcon('fa-ban')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } $action = null; if (!$project->isUserMember($viewer->getPHID())) { $can_join = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_JOIN); $action = id(new PhabricatorActionView())->setUser($viewer)->setRenderAsForm(true)->setHref('/project/update/' . $project->getID() . '/join/')->setIcon('fa-plus')->setDisabled(!$can_join)->setName(pht('Join Project')); $view->addAction($action); } else { $action = id(new PhabricatorActionView())->setWorkflow(true)->setHref('/project/update/' . $project->getID() . '/leave/')->setIcon('fa-times')->setName(pht('Leave Project...')); $view->addAction($action); if (!$project->isUserWatcher($viewer->getPHID())) { $action = id(new PhabricatorActionView())->setWorkflow(true)->setHref('/project/watch/' . $project->getID() . '/')->setIcon('fa-eye')->setName(pht('Watch Project')); $view->addAction($action); } else { $action = id(new PhabricatorActionView())->setWorkflow(true)->setHref('/project/unwatch/' . $project->getID() . '/')->setIcon('fa-eye-slash')->setName(pht('Unwatch Project')); $view->addAction($action); } } return $view; }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $project = new PhabricatorProject(); $project->setAuthorPHID($user->getPHID()); $profile = new PhabricatorProjectProfile(); $e_name = true; $errors = array(); if ($request->isFormPost()) { try { $editor = new PhabricatorProjectEditor($project); $editor->setUser($user); $editor->setName($request->getStr('name')); $editor->save(); } catch (PhabricatorProjectNameCollisionException $ex) { $e_name = 'Not Unique'; $errors[] = $ex->getMessage(); } $project->setStatus(PhabricatorProjectStatus::ONGOING); $profile->setBlurb($request->getStr('blurb')); if (!$errors) { $project->save(); $profile->setProjectPHID($project->getPHID()); $profile->save(); id(new PhabricatorProjectAffiliation())->setUserPHID($user->getPHID())->setProjectPHID($project->getPHID())->setRole('Owner')->setIsOwner(true)->save(); if ($request->isAjax()) { return id(new AphrontAjaxResponse())->setContent(array('phid' => $project->getPHID(), 'name' => $project->getName())); } else { return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } } } $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } if ($request->isAjax()) { $form = new AphrontFormLayoutView(); } else { $form = new AphrontFormView(); $form->setUser($user); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($project->getName())->setError($e_name))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Blurb')->setName('blurb')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setValue($profile->getBlurb())); if ($request->isAjax()) { if ($error_view) { $error_view->setWidth(AphrontErrorView::WIDTH_DIALOG); } $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle('Create a New Project')->appendChild($error_view)->appendChild($form)->addSubmitButton('Create Project')->addCancelButton('/project/'); return id(new AphrontDialogResponse())->setDialog($dialog); } else { $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Create')->addCancelButton('/project/')); $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM)->setHeader('Create a New Project')->appendChild($form); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create new Project')); } }
private function buildPropertyListView(PhabricatorProject $project, PhabricatorActionListView $actions) { $request = $this->getRequest(); $viewer = $request->getUser(); $view = id(new PHUIPropertyListView())->setUser($viewer)->setActionList($actions); $view->addProperty(pht('Looks Like'), $viewer->renderHandle($project->getPHID())->setAsTag(true)); return $view; }
private function buildPropertyListView(PhabricatorProject $project) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView())->setUser($viewer); $view->addProperty(pht('Looks Like'), $viewer->renderHandle($project->getPHID())->setAsTag(true)); $field_list = PhabricatorCustomField::getObjectFields($project, PhabricatorCustomField::ROLE_VIEW); $field_list->appendFieldsToPropertyList($project, $viewer, $view); return $view; }
private function renderFeedPage(PhabricatorProject $project) { $query = new PhabricatorFeedQuery(); $query->setFilterPHIDs(array($project->getPHID())); $query->setViewer($this->getRequest()->getUser()); $query->setLimit(100); $stories = $query->execute(); if (!$stories) { return pht('There are no stories about this project.'); } return $this->renderStories($stories); }
public static function updateProjectSubproject(PhabricatorProject $project) { $dao = new PhabricatorProjectSubproject(); $conn = $dao->establishConnection('w'); $sql = array(); foreach ($project->getSubprojectPHIDs() as $subproject_phid) { $sql[] = qsprintf($conn, '(%s, %s)', $project->getPHID(), $subproject_phid); } queryfx($conn, 'DELETE FROM %T WHERE projectPHID = %s', $dao->getTableName(), $project->getPHID()); if ($sql) { queryfx($conn, 'INSERT INTO %T (projectPHID, subprojectPHID) VALUES %Q', $dao->getTableName(), implode(', ', $sql)); } }
private function renderMemberList(PhabricatorProject $project, array $handles) { $request = $this->getRequest(); $viewer = $request->getUser(); $list = id(new PHUIObjectItemListView())->setNoDataString(pht('This project does not have any members.')); foreach ($handles as $handle) { $remove_uri = $this->getApplicationURI('/members/' . $project->getID() . '/remove/?phid=' . $handle->getPHID()); $item = id(new PHUIObjectItemView())->setHeader($handle->getFullName())->setHref($handle->getURI())->setImageURI($handle->getImageURI()); $item->addAction(id(new PHUIListItemView())->setIcon('fa-times')->setName(pht('Remove'))->setHref($remove_uri)->setWorkflow(true)); $list->addItem($item); } return $list; }
private function validateName(PhabricatorProject $project) { $slug = $project->getPhrictionSlug(); $name = $project->getName(); if ($slug == '/') { throw new PhabricatorProjectNameCollisionException("Project names must be unique and contain some letters or numbers."); } $id = $project->getID(); $collision = id(new PhabricatorProject())->loadOneWhere('(name = %s OR phrictionSlug = %s) AND id %Q %nd', $name, $slug, $id ? '!=' : 'IS NOT', $id ? $id : null); if ($collision) { $other_name = $collision->getName(); $other_id = $collision->getID(); throw new PhabricatorProjectNameCollisionException("Project names must be unique. The name '{$name}' is too similar to " . "the name of another project, '{$other_name}' (Project ID: " . "{$other_id}). Choose a unique name."); } }
public function generate() { $title = $this->generateTitle(); // Prepend or append 'Sprint' $title = mt_rand(0, 1) ? $title . ' Sprint' : 'Sprint ' . $title; $author = $this->loadPhabrictorUser(); $authorPHID = $author->getPHID(); $project = PhabricatorProject::initializeNewProject($author); $this->addTransaction(PhabricatorProjectTransaction::TYPE_NAME, $title); $this->addTransaction(PhabricatorProjectTransaction::TYPE_ICON, 'fa-briefcase'); $this->addTransaction(PhabricatorProjectTransaction::TYPE_COLOR, 'blue'); // $this->addTransaction( // PhabricatorProjectTransaction::TYPE_MEMBERS, // $this->loadMembersWithAuthor($authorPHID)); $this->addTransaction(PhabricatorTransactions::TYPE_VIEW_POLICY, PhabricatorPolicies::POLICY_PUBLIC); $this->addTransaction(PhabricatorTransactions::TYPE_EDIT_POLICY, PhabricatorPolicies::POLICY_PUBLIC); $this->addTransaction(PhabricatorTransactions::TYPE_JOIN_POLICY, PhabricatorPolicies::POLICY_PUBLIC); // Pick a date to be the start date for the sprint // Random between 4 weeks ago and one week from now $start = mt_rand(time() - 28 * 24 * 60 * 60, time() + 7 * 24 * 60 * 60); $this->xactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)->setMetadataValue('customfield:key', 'isdc:sprint:startdate')->setOldValue(null)->setNewValue($start); // Pick a date to be the end date for the sprint // Sprint is between 3 days and 3 weeks long $end = $start + mt_rand(3 * 24 * 60 * 60, 21 * 24 * 60 * 60); $this->xactions[] = id(new ManiphestTransaction())->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)->setMetadataValue('customfield:key', 'isdc:sprint:enddate')->setOldValue(null)->setNewValue($end); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($author)->setContentSource(PhabricatorContentSource::newConsoleSource())->setContinueOnNoEffect(true)->setContinueOnMissingFields(true)->applyTransactions($project, $this->xactions); $project->save(); // Generate a bunch of tasks created the before the sprint starts for ($i = 0, $num = mt_rand(5, 40); $i <= $num; $i++) { echo "."; $this->generateTask($project, $start, $end); } return $project; }
private function buildColumnsList(PhabricatorProject $board, array $columns) { assert_instances_of($columns, 'PhabricatorProjectColumn'); $board_id = $board->getID(); $view = id(new PHUIObjectItemListView())->setNoDataString(pht('This board has no columns.')); foreach ($columns as $column) { $column_id = $column->getID(); $detail_uri = "/project/board/{$board_id}/column/{$column_id}/"; $item = id(new PHUIObjectItemView())->setHeader($column->getDisplayName())->setHref($detail_uri); if ($column->isHidden()) { $item->setDisabled(true); } $view->addItem($item); } return id(new PHUIObjectBoxView())->setHeaderText(pht('Columns'))->setObjectList($view); }
private function buildActionListView(PhabricatorProject $project) { $request = $this->getRequest(); $viewer = $request->getUser(); $id = $project->getID(); $view = id(new PhabricatorActionListView())->setUser($viewer)->setObjectURI($request->getRequestURI()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Details'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("details/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Picture'))->setIcon('fa-picture-o')->setHref($this->getApplicationURI("picture/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); if ($project->isArchived()) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Unarchive Project'))->setIcon('fa-check')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } else { $view->addAction(id(new PhabricatorActionView())->setName(pht('Archive Project'))->setIcon('fa-ban')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } return $view; }
private function renderWatchAction(PhabricatorProject $project) { $viewer = $this->getViewer(); $viewer_phid = $viewer->getPHID(); $id = $project->getID(); $is_watcher = $viewer_phid && $project->isUserWatcher($viewer_phid); if (!$is_watcher) { $watch_icon = 'fa-eye'; $watch_text = pht('Watch Project'); $watch_href = "/project/watch/{$id}/?via=profile"; } else { $watch_icon = 'fa-eye-slash'; $watch_text = pht('Unwatch Project'); $watch_href = "/project/unwatch/{$id}/?via=profile"; } $watch_icon = id(new PHUIIconView())->setIcon($watch_icon); return id(new PHUIButtonView())->setTag('a')->setWorkflow(true)->setIcon($watch_icon)->setText($watch_text)->setHref($watch_href); }
protected function newEditableObject() { $project = PhabricatorProject::initializeNewProject($this->getViewer()); $milestone = $this->getMilestoneProject(); if ($milestone) { $default_name = pht('Milestone %s', new PhutilNumber($milestone->loadNextMilestoneNumber())); $project->setName($default_name); } return $project; }
public function testProjectPolicyMembership() { $author = $this->generateNewTestUser(); $proj_a = PhabricatorProject::initializeNewProject($author)->setName('A')->save(); $proj_b = PhabricatorProject::initializeNewProject($author)->setName('B')->save(); $proj_a->setViewPolicy($proj_b->getPHID())->save(); $proj_b->setViewPolicy($proj_a->getPHID())->save(); $user = new PhabricatorUser(); $results = id(new PhabricatorProjectQuery())->setViewer($user)->execute(); $this->assertEqual(0, count($results)); }
function addProject($project_name) { $user = getAdmin(); $project = PhabricatorProject::initializeNewProject($user); $xactions = array(); # set name $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorProjectTransaction::TYPE_NAME)->setNewValue($project_name); # set members $members = array(); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)->setNewValue(array('+' => array_fuse($members))); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromConduitRequest(new ConduitAPIRequest(array())); $editor->applyTransactions($project, $xactions); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $this->requireApplicationCapability(ProjectCreateProjectsCapability::CAPABILITY); $project = PhabricatorProject::initializeNewProject($user); $e_name = true; $type_name = PhabricatorProjectTransaction::TYPE_NAME; $v_name = $project->getName(); $validation_exception = null; if ($request->isFormPost()) { $xactions = array(); $v_name = $request->getStr('name'); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType($type_name)->setNewValue($v_name); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)->setNewValue(array('+' => array($user->getPHID() => $user->getPHID()))); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request); try { $editor->applyTransactions($project, $xactions); if ($request->isAjax()) { return id(new AphrontAjaxResponse())->setContent(array('phid' => $project->getPHID(), 'name' => $project->getName())); } else { return id(new AphrontRedirectResponse())->setURI('/project/view/' . $project->getID() . '/'); } } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); } } if ($request->isAjax()) { $form = new PHUIFormLayoutView(); } else { $form = new AphrontFormView(); $form->setUser($user); } $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($v_name)->setError($e_name)); if ($request->isAjax()) { $errors = array(); if ($validation_exception) { $errors = mpull($ex->getErrors(), 'getMessage'); } $dialog = id(new AphrontDialogView())->setUser($user)->setWidth(AphrontDialogView::WIDTH_FORM)->setTitle(pht('Create a New Project'))->setErrors($errors)->appendChild($form)->addSubmitButton(pht('Create Project'))->addCancelButton('/project/'); return id(new AphrontDialogResponse())->setDialog($dialog); } else { $form->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Create'))->addCancelButton('/project/')); $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()); $crumbs->addTextCrumb(pht('Create Project'), $this->getApplicationURI() . 'create/'); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Create New Project'))->setValidationException($validation_exception)->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => pht('Create New Project'))); } }
protected function execute(ConduitAPIRequest $request) { $user = $request->getUser(); $this->requireApplicationCapability(ProjectCreateProjectsCapability::CAPABILITY, $user); $project = PhabricatorProject::initializeNewProject($user); $type_name = PhabricatorProjectTransaction::TYPE_NAME; $members = $request->getValue('members'); $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType($type_name)->setNewValue($request->getValue('name')); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)->setNewValue(array('+' => array_fuse($members))); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromConduitRequest($request); $editor->applyTransactions($project, $xactions); return $this->buildProjectInfoDictionary($project); }
public function generate() { $title = $this->generateTitle(); $author = $this->loadPhabrictorUser(); $author_phid = $author->getPHID(); $project = PhabricatorProject::initializeNewProject($author)->setName($title); $this->addTransaction(PhabricatorProjectTransaction::TYPE_NAME, $title); $project->attachMemberPHIDs($this->loadMembersWithAuthor($author_phid)); $this->addTransaction(PhabricatorProjectTransaction::TYPE_STATUS, $this->generateProjectStatus()); $this->addTransaction(PhabricatorTransactions::TYPE_VIEW_POLICY, PhabricatorPolicies::POLICY_PUBLIC); $this->addTransaction(PhabricatorTransactions::TYPE_EDIT_POLICY, PhabricatorPolicies::POLICY_PUBLIC); $this->addTransaction(PhabricatorTransactions::TYPE_JOIN_POLICY, PhabricatorPolicies::POLICY_PUBLIC); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($author)->setContentSource(PhabricatorContentSource::newConsoleSource())->setContinueOnNoEffect(true)->applyTransactions($project, $this->xactions); return $project->save(); }
protected function execute(ConduitAPIRequest $request) { $user = $request->getUser(); $this->requireApplicationCapability(ProjectCreateProjectsCapability::CAPABILITY, $user); $project = PhabricatorProject::initializeNewProject($user); $type_name = PhabricatorProjectTransaction::TYPE_NAME; $members = $request->getValue('members'); $xactions = array(); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType($type_name)->setNewValue($request->getValue('name')); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)->setNewValue(array('+' => array_fuse($members))); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorProjectTransaction::TYPE_ICON)->setNewValue('fa-calendar'); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorProjectTransaction::TYPE_COLOR)->setNewValue('green'); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)->setMetadataValue('customfield:key', 'isdc:sprint:issprint')->setOldValue(null)->setNewValue(1); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)->setMetadataValue('customfield:key', 'isdc:sprint:startdate')->setOldValue(null)->setNewValue(strtotime($request->getValue('startdate'))); $xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)->setMetadataValue('customfield:key', 'isdc:sprint:enddate')->setOldValue(0)->setNewValue(strtotime($request->getValue('enddate'))); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromConduitRequest($request); $editor->applyTransactions($project, $xactions); return $this->buildProjectInfoDictionary($project); }
public function generateObject() { $author = $this->loadRandomUser(); $project = PhabricatorProject::initializeNewProject($author); $xactions = array(); $xactions[] = $this->newTransaction(PhabricatorProjectTransaction::TYPE_NAME, $this->newProjectTitle()); $xactions[] = $this->newTransaction(PhabricatorProjectTransaction::TYPE_STATUS, $this->newProjectStatus()); // Almost always make the author a member. $members = array(); if ($this->roll(1, 20) > 2) { $members[] = $author->getPHID(); } // Add a few other members. $size = $this->roll(2, 6, -2); for ($ii = 0; $ii < $size; $ii++) { $members[] = $this->loadRandomUser()->getPHID(); } $xactions[] = $this->newTransaction(PhabricatorTransactions::TYPE_EDGE, array('+' => array_fuse($members)), array('edge:type' => PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)); $editor = id(new PhabricatorProjectTransactionEditor())->setActor($author)->setContentSource($this->getLipsumContentSource())->setContinueOnNoEffect(true)->applyTransactions($project, $xactions); return $project; }
private function initializeWorkboardDialog(PhabricatorProject $project) { $instructions = pht('This workboard has not been setup yet.'); $new_selector = id(new AphrontFormRadioButtonControl())->setName('initialize-type')->setValue('backlog-only')->addButton('backlog-only', pht('New Empty Board'), pht('Create a new board with just a backlog column.'))->addButton('import', pht('Import Columns'), pht('Import board columns from another project.')); $dialog = id(new AphrontDialogView())->setUser($this->getRequest()->getUser())->setTitle(pht('New Workboard'))->addSubmitButton('Continue')->addCancelButton($this->getApplicationURI('view/' . $project->getID() . '/'))->appendParagraph($instructions)->appendChild($new_selector); return id(new AphrontDialogResponse())->setDialog($dialog); }
private function setDefaultProfilePicture(PhabricatorProject $project) { if ($project->isMilestone()) { return; } $compose_color = $project->getDisplayIconComposeColor(); $compose_icon = $project->getDisplayIconComposeIcon(); $builtin = id(new PhabricatorFilesComposeIconBuiltinFile())->setColor($compose_color)->setIcon($compose_icon); $data = $builtin->loadBuiltinFileData(); $file = PhabricatorFile::newFromFileData($data, array('name' => $builtin->getBuiltinDisplayName(), 'profile' => true, 'canCDN' => true)); $project->setProfileImagePHID($file->getPHID())->save(); }
/** * This is enforced in @{class:PhabricatorProjectTransactionEditor}. We use * this logic to render a better form for users hitting this case. */ private function userCannotLeave(PhabricatorProject $project) { $viewer = $this->getViewer(); return $project->getIsMembershipLocked() && !PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); }
protected function buildProjectInfoDictionary(PhabricatorProject $project) { $results = $this->buildProjectInfoDictionaries(array($project)); return idx($results, $project->getPHID()); }
<?php $project_table = new PhabricatorProject(); $table_name = $project_table->getTableName(); $conn_w = $project_table->establishConnection('w'); $slug_table_name = id(new PhabricatorProjectSlug())->getTableName(); $time = time(); echo pht('Migrating project phriction slugs...') . "\n"; foreach (new LiskMigrationIterator($project_table) as $project) { $id = $project->getID(); echo pht('Migrating project %d...', $id) . "\n"; $phriction_slug = rtrim($project->getPhrictionSlug(), '/'); $slug = id(new PhabricatorProjectSlug())->loadOneWhere('slug = %s', $phriction_slug); if ($slug) { echo pht('Already migrated %d... Continuing.', $id) . "\n"; continue; } queryfx($conn_w, 'INSERT INTO %T (projectPHID, slug, dateCreated, dateModified) ' . 'VALUES (%s, %s, %d, %d)', $slug_table_name, $project->getPHID(), $phriction_slug, $time, $time); echo pht('Migrated %d.', $id) . "\n"; } echo pht('Done.') . "\n";