Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
Show First 20 Lines • Show All 786 Lines • ▼ Show 20 Lines | private function buildEditResponse($object) { | ||||
$controller = $this->getController(); | $controller = $this->getController(); | ||||
$request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
$fields = $this->buildEditFields($object); | $fields = $this->buildEditFields($object); | ||||
$template = $object->getApplicationTransactionTemplate(); | $template = $object->getApplicationTransactionTemplate(); | ||||
$validation_exception = null; | $validation_exception = null; | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
foreach ($fields as $field) { | $submit_fields = $fields; | ||||
foreach ($submit_fields as $key => $field) { | |||||
if (!$field->shouldGenerateTransactionsFromSubmit()) { | |||||
unset($submit_fields[$key]); | |||||
continue; | |||||
} | |||||
$field->setIsSubmittedForm(true); | $field->setIsSubmittedForm(true); | ||||
if ($field->getIsLocked() || $field->getIsHidden()) { | if (!$field->shouldReadValueFromSubmit()) { | ||||
continue; | continue; | ||||
} | } | ||||
$field->readValueFromSubmit($request); | $field->readValueFromSubmit($request); | ||||
} | } | ||||
$xactions = array(); | $xactions = array(); | ||||
foreach ($fields as $field) { | foreach ($submit_fields as $field) { | ||||
$types = $field->getWebEditTypes(); | $type_xactions = $field->generateTransactions( | ||||
foreach ($types as $type) { | |||||
$type_xactions = $type->generateTransactions( | |||||
clone $template, | clone $template, | ||||
array( | array( | ||||
'value' => $field->getValueForTransaction(), | 'value' => $field->getValueForTransaction(), | ||||
)); | )); | ||||
if (!$type_xactions) { | |||||
continue; | |||||
} | |||||
foreach ($type_xactions as $type_xaction) { | foreach ($type_xactions as $type_xaction) { | ||||
$xactions[] = $type_xaction; | $xactions[] = $type_xaction; | ||||
} | } | ||||
} | } | ||||
} | |||||
$editor = $object->getApplicationTransactionEditor() | $editor = $object->getApplicationTransactionEditor() | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true); | ->setContinueOnNoEffect(true); | ||||
try { | try { | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if ($request->isFormPost()) { | ||||
unset($copy_fields[$copy_key]); | unset($copy_fields[$copy_key]); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
$copy_fields = array(); | $copy_fields = array(); | ||||
} | } | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
if ($field->getIsLocked() || $field->getIsHidden()) { | if (!$field->shouldReadValueFromRequest()) { | ||||
continue; | continue; | ||||
} | } | ||||
$field_key = $field->getKey(); | $field_key = $field->getKey(); | ||||
if (isset($copy_fields[$field_key])) { | if (isset($copy_fields[$field_key])) { | ||||
$field->readValueFromField($copy_fields[$field_key]); | $field->readValueFromField($copy_fields[$field_key]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | final public function buildEditEngineCommentView($object) { | ||||
if ($draft) { | if ($draft) { | ||||
$view->setVersionedDraft($draft); | $view->setVersionedDraft($draft); | ||||
} | } | ||||
$view->setCurrentVersion($this->loadDraftVersion($object)); | $view->setCurrentVersion($this->loadDraftVersion($object)); | ||||
$fields = $this->buildEditFields($object); | $fields = $this->buildEditFields($object); | ||||
$all_types = array(); | $comment_actions = array(); | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
if (!$this->isCommentField($field)) { | if (!$field->shouldGenerateTransactionsFromComment()) { | ||||
continue; | continue; | ||||
} | } | ||||
$types = $field->getCommentEditTypes(); | $comment_action = $field->getCommentAction(); | ||||
foreach ($types as $type) { | if (!$comment_action) { | ||||
$all_types[] = $type; | continue; | ||||
} | } | ||||
$key = $comment_action->getKey(); | |||||
// TODO: Validate these better. | |||||
$comment_actions[$key] = $comment_action; | |||||
} | } | ||||
$view->setEditTypes($all_types); | $view->setCommentActions($comment_actions); | ||||
return $view; | return $view; | ||||
} | } | ||||
protected function loadDraftVersion($object) { | protected function loadDraftVersion($object) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
if (!$viewer->isLoggedIn()) { | if (!$viewer->isLoggedIn()) { | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | if ($is_preview) { | ||||
->setProperty('actions', $actions) | ->setProperty('actions', $actions) | ||||
->save(); | ->save(); | ||||
} | } | ||||
} | } | ||||
$xactions = array(); | $xactions = array(); | ||||
if ($actions) { | if ($actions) { | ||||
$type_map = array(); | $action_map = array(); | ||||
foreach ($fields as $field) { | foreach ($actions as $action) { | ||||
if (!$this->isCommentField($field)) { | $type = idx($action, 'type'); | ||||
if (!$type) { | |||||
continue; | continue; | ||||
} | } | ||||
$types = $field->getCommentEditTypes(); | if (empty($fields[$type])) { | ||||
foreach ($types as $type) { | continue; | ||||
$type_map[$type->getEditType()] = array( | |||||
'type' => $type, | |||||
'field' => $field, | |||||
); | |||||
} | |||||
} | } | ||||
foreach ($actions as $action) { | $action_map[$type] = $action; | ||||
$type = idx($action, 'type'); | |||||
if (!$type) { | |||||
continue; | |||||
} | } | ||||
$spec = idx($type_map, $type); | foreach ($action_map as $type => $action) { | ||||
if (!$spec) { | $field = $fields[$type]; | ||||
if (!$field->shouldGenerateTransactionsFromComment()) { | |||||
continue; | continue; | ||||
} | } | ||||
$edit_type = $spec['type']; | if (array_key_exists('initialValue', $action)) { | ||||
$field = $spec['field']; | $field->setInitialValue($action['initialValue']); | ||||
} | |||||
$field->readValueFromComment($action); | $field->readValueFromComment(idx($action, 'value')); | ||||
$type_xactions = $edit_type->generateTransactions( | $type_xactions = $field->generateTransactions( | ||||
$template, | clone $template, | ||||
array( | array( | ||||
'value' => $field->getValueForTransaction(), | 'value' => $field->getValueForTransaction(), | ||||
)); | )); | ||||
foreach ($type_xactions as $type_xaction) { | foreach ($type_xactions as $type_xaction) { | ||||
$xactions[] = $type_xaction; | $xactions[] = $type_xaction; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | final public function buildConduitResponse(ConduitAPIRequest $request) { | ||||
$xactions = $this->getConduitTransactions($request, $types, $template); | $xactions = $this->getConduitTransactions($request, $types, $template); | ||||
$editor = $object->getApplicationTransactionEditor() | $editor = $object->getApplicationTransactionEditor() | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromConduitRequest($request) | ->setContentSourceFromConduitRequest($request) | ||||
->setContinueOnNoEffect(true); | ->setContinueOnNoEffect(true); | ||||
if (!$this->getIsCreate()) { | |||||
$editor->setContinueOnMissingFields(true); | |||||
} | |||||
$xactions = $editor->applyTransactions($object, $xactions); | $xactions = $editor->applyTransactions($object, $xactions); | ||||
$xactions_struct = array(); | $xactions_struct = array(); | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$xactions_struct[] = array( | $xactions_struct[] = array( | ||||
'phid' => $xaction->getPHID(), | 'phid' => $xaction->getPHID(), | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | /* -( Conduit )------------------------------------------------------------ */ | ||||
private function hasCreateCapability() { | private function hasCreateCapability() { | ||||
return PhabricatorPolicyFilter::hasCapability( | return PhabricatorPolicyFilter::hasCapability( | ||||
$this->getViewer(), | $this->getViewer(), | ||||
$this, | $this, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
} | } | ||||
private function isCommentField(PhabricatorEditField $field) { | |||||
// TODO: This is a little bit hacky. | |||||
if ($field->getKey() == 'comment') { | |||||
return true; | |||||
} | |||||
if ($field->getIsLocked()) { | |||||
return false; | |||||
} | |||||
if ($field->getIsHidden()) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getPHID() { | public function getPHID() { | ||||
return get_class($this); | return get_class($this); | ||||
} | } | ||||
Show All 24 Lines |