protected function loadPage()
 {
     $table = new PhabricatorProjectColumn();
     $conn_r = $table->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     return $table->loadAllFromArray($data);
 }
 private function buildActionView(PhabricatorProjectColumn $column)
 {
     $viewer = $this->getRequest()->getUser();
     $id = $column->getID();
     $project_id = $this->getProject()->getID();
     $base_uri = '/board/' . $project_id . '/';
     $actions = id(new PhabricatorActionListView())->setUser($viewer);
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $column, PhabricatorPolicyCapability::CAN_EDIT);
     $actions->addAction(id(new PhabricatorActionView())->setName(pht('Edit Column'))->setIcon('fa-pencil')->setHref($this->getApplicationURI($base_uri . 'edit/' . $id . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit));
     return $actions;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $project_id = $request->getURIData('projectID');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($project_id))->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $this->setProject($project);
     $columns = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($project->getPHID()))->execute();
     if ($columns) {
         return new Aphront400Response();
     }
     $project_id = $project->getID();
     $board_uri = $this->getApplicationURI("board/{$project_id}/");
     if ($request->isFormPost()) {
         $import_phid = $request->getArr('importProjectPHID');
         $import_phid = reset($import_phid);
         $import_columns = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($import_phid))->execute();
         if (!$import_columns) {
             return new Aphront400Response();
         }
         $table = id(new PhabricatorProjectColumn())->openTransaction();
         foreach ($import_columns as $import_column) {
             if ($import_column->isHidden()) {
                 continue;
             }
             $new_column = PhabricatorProjectColumn::initializeNewColumn($viewer)->setSequence($import_column->getSequence())->setProjectPHID($project->getPHID())->setName($import_column->getName())->setProperties($import_column->getProperties())->save();
         }
         $table->saveTransaction();
         return id(new AphrontRedirectResponse())->setURI($board_uri);
     }
     $proj_selector = id(new AphrontFormTokenizerControl())->setName('importProjectPHID')->setUser($viewer)->setDatasource(id(new PhabricatorProjectDatasource())->setParameters(array('mustHaveColumns' => true))->setLimit(1));
     return $this->newDialog()->setTitle(pht('Import Columns'))->setWidth(AphrontDialogView::WIDTH_FORM)->appendParagraph(pht('Choose a project to import columns from:'))->appendChild($proj_selector)->addCancelButton($board_uri)->addSubmitButton(pht('Import'));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $project_id = $request->getURIData('projectID');
     $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->withIDs(array($project_id))->needImages(true)->executeOne();
     if (!$project) {
         return new Aphront404Response();
     }
     $this->setProject($project);
     $is_new = $id ? false : true;
     if (!$is_new) {
         $column = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$column) {
             return new Aphront404Response();
         }
     } else {
         $column = PhabricatorProjectColumn::initializeNewColumn($viewer);
     }
     $e_name = null;
     $e_limit = null;
     $v_limit = $column->getPointLimit();
     $v_name = $column->getName();
     $validation_exception = null;
     $base_uri = '/board/' . $project_id . '/';
     if ($is_new) {
         // we want to go back to the board
         $view_uri = $this->getApplicationURI($base_uri);
     } else {
         $view_uri = $this->getApplicationURI($base_uri . 'column/' . $id . '/');
     }
     if ($request->isFormPost()) {
         $v_name = $request->getStr('name');
         $v_limit = $request->getStr('limit');
         if ($is_new) {
             $column->setProjectPHID($project->getPHID());
             $column->attachProject($project);
             $columns = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array($project->getPHID()))->execute();
             $new_sequence = 1;
             if ($columns) {
                 $values = mpull($columns, 'getSequence');
                 $new_sequence = max($values) + 1;
             }
             $column->setSequence($new_sequence);
         }
         $xactions = array();
         $type_name = PhabricatorProjectColumnTransaction::TYPE_NAME;
         $xactions[] = id(new PhabricatorProjectColumnTransaction())->setTransactionType($type_name)->setNewValue($v_name);
         $type_limit = PhabricatorProjectColumnTransaction::TYPE_LIMIT;
         $xactions[] = id(new PhabricatorProjectColumnTransaction())->setTransactionType($type_limit)->setNewValue($v_limit);
         try {
             $editor = id(new PhabricatorProjectColumnTransactionEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->applyTransactions($column, $xactions);
             return id(new AphrontRedirectResponse())->setURI($view_uri);
         } catch (PhabricatorApplicationTransactionValidationException $ex) {
             $e_name = $ex->getShortMessage($type_name);
             $e_limit = $ex->getShortMessage($type_limit);
             $validation_exception = $ex;
         }
     }
     $form = new AphrontFormView();
     $form->setUser($request->getUser())->appendChild(id(new AphrontFormTextControl())->setValue($v_name)->setLabel(pht('Name'))->setName('name')->setError($e_name)->setCaption(pht('This will be displayed as the header of the column.')))->appendChild(id(new AphrontFormTextControl())->setValue($v_limit)->setLabel(pht('Point Limit'))->setName('limit')->setError($e_limit)->setCaption(pht('Maximum number of points of tasks allowed in the column.')));
     if ($is_new) {
         $title = pht('Create Column');
         $submit = pht('Create Column');
     } else {
         $title = pht('Edit %s', $column->getDisplayName());
         $submit = pht('Save Column');
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue($submit)->addCancelButton($view_uri));
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setValidationException($validation_exception)->setForm($form);
     $nav = $this->buildIconNavView($project);
     $nav->appendChild($form_box);
     return $this->buildApplicationPage($nav, array('title' => $title));
 }
 private function buildColumnMenu(PhabricatorProject $project, PhabricatorProjectColumn $column)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT);
     $column_items = array();
     $column_items[] = id(new PhabricatorActionView())->setIcon('fa-plus')->setName(pht('Create Task...'))->setHref('/maniphest/task/create/')->addSigil('column-add-task')->setMetadata(array('columnPHID' => $column->getPHID()))->setDisabled(!$can_edit);
     $edit_uri = $this->getApplicationURI('board/' . $this->id . '/column/' . $column->getID() . '/');
     $column_items[] = id(new PhabricatorActionView())->setIcon('fa-pencil')->setName(pht('Edit Column'))->setHref($edit_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit);
     $can_hide = $can_edit && !$column->isDefaultColumn();
     $hide_uri = 'board/' . $this->id . '/hide/' . $column->getID() . '/';
     $hide_uri = $this->getApplicationURI($hide_uri);
     $hide_uri = $this->getURIWithState($hide_uri);
     if (!$column->isHidden()) {
         $column_items[] = id(new PhabricatorActionView())->setName(pht('Hide Column'))->setIcon('fa-eye-slash')->setHref($hide_uri)->setDisabled(!$can_hide)->setWorkflow(true);
     } else {
         $column_items[] = id(new PhabricatorActionView())->setName(pht('Show Column'))->setIcon('fa-eye')->setHref($hide_uri)->setDisabled(!$can_hide)->setWorkflow(true);
     }
     $column_menu = id(new PhabricatorActionListView())->setUser($viewer);
     foreach ($column_items as $item) {
         $column_menu->addAction($item);
     }
     $column_button = id(new PHUIIconView())->setIconFont('fa-caret-down')->setHref('#')->addSigil('boards-dropdown-menu')->setMetadata(array('items' => hsprintf('%s', $column_menu)));
     return $column_button;
 }
예제 #6
0
<?php

// Was PhabricatorEdgeConfig::TYPE_COLUMN_HAS_OBJECT
$type_has_object = 44;
$column = new PhabricatorProjectColumn();
$conn_w = $column->establishConnection('w');
$rows = queryfx_all($conn_w, 'SELECT src, dst FROM %T WHERE type = %d', PhabricatorEdgeConfig::TABLE_NAME_EDGE, $type_has_object);
$cols = array();
foreach ($rows as $row) {
    $cols[$row['src']][] = $row['dst'];
}
$sql = array();
foreach ($cols as $col_phid => $obj_phids) {
    echo pht("Migrating column '%s'...", $col_phid) . "\n";
    $column = id(new PhabricatorProjectColumn())->loadOneWhere('phid = %s', $col_phid);
    if (!$column) {
        echo pht("Column '%s' does not exist.", $col_phid) . "\n";
        continue;
    }
    $sequence = 0;
    foreach ($obj_phids as $obj_phid) {
        $sql[] = qsprintf($conn_w, '(%s, %s, %s, %d)', $column->getProjectPHID(), $column->getPHID(), $obj_phid, $sequence++);
    }
}
echo pht('Inserting rows...') . "\n";
foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) {
    queryfx($conn_w, 'INSERT INTO %T (boardPHID, columnPHID, objectPHID, sequence)
      VALUES %Q', id(new PhabricatorProjectColumnPosition())->getTableName(), $chunk);
}
echo pht('Done.') . "\n";
예제 #7
0
<?php

$table = new PhabricatorProjectColumn();
$conn_w = $table->establishConnection('w');
foreach (new LiskMigrationIterator($table) as $column) {
    $id = $column->getID();
    echo pht('Adjusting column %d...', $id) . "\n";
    if ($column->getSequence() == 0) {
        $properties = $column->getProperties();
        $properties['isDefault'] = true;
        queryfx($conn_w, 'UPDATE %T SET properties = %s WHERE id = %d', $table->getTableName(), json_encode($properties), $id);
    }
}
echo pht('Done.') . "\n";
 private function buildInitializeContent(PhabricatorProject $project)
 {
     $request = $this->getRequest();
     $viewer = $this->getViewer();
     $type = $request->getStr('initialize-type');
     $id = $project->getID();
     $profile_uri = $this->getApplicationURI("profile/{$id}/");
     $board_uri = $this->getApplicationURI("board/{$id}/");
     $import_uri = $this->getApplicationURI("board/{$id}/import/");
     $set_default = $request->getBool('default');
     if ($set_default) {
         $this->getProfilePanelEngine()->adjustDefault(PhabricatorProject::PANEL_WORKBOARD);
     }
     if ($request->isFormPost()) {
         if ($type == 'backlog-only') {
             $column = PhabricatorProjectColumn::initializeNewColumn($viewer)->setSequence(0)->setProperty('isDefault', true)->setProjectPHID($project->getPHID())->save();
             $project->setHasWorkboard(1)->save();
             return id(new AphrontRedirectResponse())->setURI($board_uri);
         } else {
             return id(new AphrontRedirectResponse())->setURI($import_uri);
         }
     }
     $new_selector = id(new AphrontFormRadioButtonControl())->setLabel(pht('Columns'))->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.'));
     $default_checkbox = id(new AphrontFormCheckboxControl())->setLabel(pht('Make Default'))->addCheckbox('default', 1, pht('Make the workboard the default view for this project.'), true);
     $form = id(new AphrontFormView())->setUser($viewer)->appendRemarkupInstructions(pht('The workboard for this project has not been created yet.'))->appendControl($new_selector)->appendControl($default_checkbox)->appendControl(id(new AphrontFormSubmitControl())->addCancelButton($profile_uri)->setValue(pht('Create Workboard')));
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Create Workboard'))->setForm($form);
     return $box;
 }
 private function refreshColumn(PhabricatorUser $viewer, PhabricatorProjectColumn $column)
 {
     $results = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withIDs(array($column->getID()))->execute();
     if ($results) {
         return head($results);
     } else {
         return null;
     }
 }
 private function loadColumns(array $boards)
 {
     $viewer = $this->getViewer();
     $columns = id(new PhabricatorProjectColumnQuery())->setViewer($viewer)->withProjectPHIDs(array_keys($boards))->execute();
     $columns = msort($columns, 'getOrderingKey');
     $columns = mpull($columns, null, 'getPHID');
     $need_children = array();
     foreach ($boards as $phid => $board) {
         if ($board->getHasMilestones() || $board->getHasSubprojects()) {
             $need_children[] = $phid;
         }
     }
     if ($need_children) {
         $children = id(new PhabricatorProjectQuery())->setViewer($viewer)->withParentProjectPHIDs($need_children)->execute();
         $children = mpull($children, null, 'getPHID');
         $children = mgroup($children, 'getParentProjectPHID');
     } else {
         $children = array();
     }
     $columns = mgroup($columns, 'getProjectPHID');
     foreach ($boards as $board_phid => $board) {
         $board_columns = idx($columns, $board_phid, array());
         // If the project has milestones, create any missing columns.
         if ($board->getHasMilestones() || $board->getHasSubprojects()) {
             $child_projects = idx($children, $board_phid, array());
             if ($board_columns) {
                 $next_sequence = last($board_columns)->getSequence() + 1;
             } else {
                 $next_sequence = 1;
             }
             $proxy_columns = mpull($board_columns, null, 'getProxyPHID');
             foreach ($child_projects as $child_phid => $child) {
                 if (isset($proxy_columns[$child_phid])) {
                     continue;
                 }
                 $new_column = PhabricatorProjectColumn::initializeNewColumn($viewer)->attachProject($board)->attachProxy($child)->setSequence($next_sequence++)->setProjectPHID($board_phid)->setProxyPHID($child_phid);
                 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                 $new_column->save();
                 unset($unguarded);
                 $board_columns[$new_column->getPHID()] = $new_column;
             }
         }
         $board_columns = msort($board_columns, 'getOrderingKey');
         $columns[$board_phid] = $board_columns;
     }
     foreach ($columns as $board_phid => $board_columns) {
         foreach ($board_columns as $board_column) {
             $column_phid = $board_column->getPHID();
             $this->columnMap[$column_phid] = $board_column;
         }
     }
     return $columns;
 }
 private function addColumn(PhabricatorUser $viewer, PhabricatorProject $project, $sequence)
 {
     $project->setHasWorkboard(1)->save();
     return PhabricatorProjectColumn::initializeNewColumn($viewer)->setSequence(0)->setProperty('isDefault', $sequence == 0)->setProjectPHID($project->getPHID())->save();
 }