Differential D12475 Diff 29945 src/applications/maniphest/controller/ManiphestBatchEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/maniphest/controller/ManiphestBatchEditController.php
| <?php | <?php | ||||
| final class ManiphestBatchEditController extends ManiphestController { | final class ManiphestBatchEditController extends ManiphestController { | ||||
| public function processRequest() { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $this->getViewer(); | |||||
| $this->requireApplicationCapability( | $this->requireApplicationCapability( | ||||
| ManiphestBulkEditCapability::CAPABILITY); | ManiphestBulkEditCapability::CAPABILITY); | ||||
| $request = $this->getRequest(); | $project = null; | ||||
| $user = $request->getUser(); | $board_id = $request->getInt('board'); | ||||
| if ($board_id) { | |||||
| $project = id(new PhabricatorProjectQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withIDs(array($board_id)) | |||||
| ->executeOne(); | |||||
| if (!$project) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| } | |||||
| $task_ids = $request->getArr('batch'); | $task_ids = $request->getArr('batch'); | ||||
| if (!$task_ids) { | |||||
| $task_ids = $request->getStrList('batch'); | |||||
| } | |||||
| $tasks = id(new ManiphestTaskQuery()) | $tasks = id(new ManiphestTaskQuery()) | ||||
| ->setViewer($user) | ->setViewer($viewer) | ||||
| ->withIDs($task_ids) | ->withIDs($task_ids) | ||||
| ->requireCapabilities( | ->requireCapabilities( | ||||
| array( | array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
| )) | )) | ||||
| ->needSubscriberPHIDs(true) | ->needSubscriberPHIDs(true) | ||||
| ->needProjectPHIDs(true) | ->needProjectPHIDs(true) | ||||
| ->execute(); | ->execute(); | ||||
| if ($project) { | |||||
| $cancel_uri = '/project/board/'.$project->getID().'/'; | |||||
| $redirect_uri = $cancel_uri; | |||||
| } else { | |||||
| $cancel_uri = '/maniphest/'; | |||||
| $redirect_uri = '/maniphest/?ids='.implode(',', mpull($tasks, 'getID')); | |||||
| } | |||||
| $actions = $request->getStr('actions'); | $actions = $request->getStr('actions'); | ||||
| if ($actions) { | if ($actions) { | ||||
| $actions = json_decode($actions, true); | $actions = json_decode($actions, true); | ||||
| } | } | ||||
| if ($request->isFormPost() && is_array($actions)) { | if ($request->isFormPost() && is_array($actions)) { | ||||
| foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
| $field_list = PhabricatorCustomField::getObjectFields( | $field_list = PhabricatorCustomField::getObjectFields( | ||||
| $task, | $task, | ||||
| PhabricatorCustomField::ROLE_EDIT); | PhabricatorCustomField::ROLE_EDIT); | ||||
| $field_list->readFieldsFromStorage($task); | $field_list->readFieldsFromStorage($task); | ||||
| $xactions = $this->buildTransactions($actions, $task); | $xactions = $this->buildTransactions($actions, $task); | ||||
| if ($xactions) { | if ($xactions) { | ||||
| // TODO: Set content source to "batch edit". | // TODO: Set content source to "batch edit". | ||||
| $editor = id(new ManiphestTransactionEditor()) | $editor = id(new ManiphestTransactionEditor()) | ||||
| ->setActor($user) | ->setActor($viewer) | ||||
| ->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
| ->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
| ->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
| ->applyTransactions($task, $xactions); | ->applyTransactions($task, $xactions); | ||||
| } | } | ||||
| } | } | ||||
| $task_ids = implode(',', mpull($tasks, 'getID')); | return id(new AphrontRedirectResponse())->setURI($redirect_uri); | ||||
| return id(new AphrontRedirectResponse()) | |||||
| ->setURI('/maniphest/?ids='.$task_ids); | |||||
| } | } | ||||
| $handles = ManiphestTaskListView::loadTaskHandles($user, $tasks); | $handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks); | ||||
| $list = new ManiphestTaskListView(); | $list = new ManiphestTaskListView(); | ||||
| $list->setTasks($tasks); | $list->setTasks($tasks); | ||||
| $list->setUser($user); | $list->setUser($viewer); | ||||
| $list->setHandles($handles); | $list->setHandles($handles); | ||||
| $template = new AphrontTokenizerTemplateView(); | $template = new AphrontTokenizerTemplateView(); | ||||
| $template = $template->render(); | $template = $template->render(); | ||||
| $projects_source = new PhabricatorProjectDatasource(); | $projects_source = new PhabricatorProjectDatasource(); | ||||
| $mailable_source = new PhabricatorMetaMTAMailableDatasource(); | $mailable_source = new PhabricatorMetaMTAMailableDatasource(); | ||||
| $mailable_source->setViewer($user); | $mailable_source->setViewer($viewer); | ||||
| $owner_source = new PhabricatorTypeaheadOwnerDatasource(); | $owner_source = new PhabricatorTypeaheadOwnerDatasource(); | ||||
| $owner_source->setViewer($user); | $owner_source->setViewer($viewer); | ||||
| require_celerity_resource('maniphest-batch-editor'); | require_celerity_resource('maniphest-batch-editor'); | ||||
| Javelin::initBehavior( | Javelin::initBehavior( | ||||
| 'maniphest-batch-editor', | 'maniphest-batch-editor', | ||||
| array( | array( | ||||
| 'root' => 'maniphest-batch-edit-form', | 'root' => 'maniphest-batch-edit-form', | ||||
| 'tokenizerTemplate' => $template, | 'tokenizerTemplate' => $template, | ||||
| 'sources' => array( | 'sources' => array( | ||||
| Show All 14 Lines | Javelin::initBehavior( | ||||
| 'browseURI' => $mailable_source->getBrowseURI(), | 'browseURI' => $mailable_source->getBrowseURI(), | ||||
| ), | ), | ||||
| ), | ), | ||||
| 'input' => 'batch-form-actions', | 'input' => 'batch-form-actions', | ||||
| 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), | 'priorityMap' => ManiphestTaskPriority::getTaskPriorityMap(), | ||||
| 'statusMap' => ManiphestTaskStatus::getTaskStatusMap(), | 'statusMap' => ManiphestTaskStatus::getTaskStatusMap(), | ||||
| )); | )); | ||||
| $form = new AphrontFormView(); | $form = id(new AphrontFormView()) | ||||
| $form->setUser($user); | ->setUser($viewer) | ||||
| $form->setID('maniphest-batch-edit-form'); | ->addHiddenInput('board', $board_id) | ||||
| ->setID('maniphest-batch-edit-form'); | |||||
| foreach ($tasks as $task) { | foreach ($tasks as $task) { | ||||
| $form->appendChild( | $form->appendChild( | ||||
| phutil_tag( | phutil_tag( | ||||
| 'input', | 'input', | ||||
| array( | array( | ||||
| 'type' => 'hidden', | 'type' => 'hidden', | ||||
| 'name' => 'batch[]', | 'name' => 'batch[]', | ||||
| Show All 26 Lines | $form->appendChild( | ||||
| array( | array( | ||||
| 'sigil' => 'maniphest-batch-actions', | 'sigil' => 'maniphest-batch-actions', | ||||
| 'class' => 'maniphest-batch-actions-table', | 'class' => 'maniphest-batch-actions-table', | ||||
| ), | ), | ||||
| ''))) | ''))) | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
| ->setValue(pht('Update Tasks')) | ->setValue(pht('Update Tasks')) | ||||
| ->addCancelButton('/maniphest/')); | ->addCancelButton($cancel_uri)); | ||||
| $title = pht('Batch Editor'); | $title = pht('Batch Editor'); | ||||
| $crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
| $crumbs->addTextCrumb($title); | $crumbs->addTextCrumb($title); | ||||
| $task_box = id(new PHUIObjectBoxView()) | $task_box = id(new PHUIObjectBoxView()) | ||||
| ->setHeaderText(pht('Selected Tasks')) | ->setHeaderText(pht('Selected Tasks')) | ||||
| ▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines | |||||