2016-06-22 17:04:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchRelationshipController
|
|
|
|
extends PhabricatorSearchBaseController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
2016-06-29 01:05:05 +02:00
|
|
|
$object = $this->loadRelationshipObject();
|
2016-06-22 17:04:14 +02:00
|
|
|
if (!$object) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-06-29 01:05:05 +02:00
|
|
|
$relationship = $this->loadRelationship($object);
|
2016-06-22 17:04:14 +02:00
|
|
|
if (!$relationship) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$src_phid = $object->getPHID();
|
|
|
|
$edge_type = $relationship->getEdgeConstant();
|
|
|
|
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
// If this is a normal relationship, users can remove related objects. If
|
|
|
|
// it's a special relationship like a merge, we can't undo it, so we won't
|
|
|
|
// prefill the current related objects.
|
|
|
|
if ($relationship->canUndoRelationship()) {
|
|
|
|
$dst_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
|
|
$src_phid,
|
|
|
|
$edge_type);
|
|
|
|
} else {
|
|
|
|
$dst_phids = array();
|
|
|
|
}
|
2016-06-22 17:04:14 +02:00
|
|
|
|
|
|
|
$all_phids = $dst_phids;
|
|
|
|
$all_phids[] = $src_phid;
|
|
|
|
|
|
|
|
$handles = $viewer->loadHandles($all_phids);
|
|
|
|
$src_handle = $handles[$src_phid];
|
|
|
|
|
|
|
|
$done_uri = $src_handle->getURI();
|
2016-06-22 17:20:50 +02:00
|
|
|
$initial_phids = $dst_phids;
|
2016-06-22 17:04:14 +02:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$phids = explode(';', $request->getStr('phids'));
|
|
|
|
$phids = array_filter($phids);
|
|
|
|
$phids = array_values($phids);
|
|
|
|
|
2016-06-22 17:20:50 +02:00
|
|
|
$initial_phids = $request->getStrList('initialPHIDs');
|
2016-06-22 17:04:14 +02:00
|
|
|
|
2016-06-22 17:20:50 +02:00
|
|
|
// Apply the changes as adds and removes relative to the original state
|
|
|
|
// of the object when the dialog was rendered so that two users adding
|
|
|
|
// relationships at the same time don't race and overwrite one another.
|
|
|
|
$add_phids = array_diff($phids, $initial_phids);
|
|
|
|
$rem_phids = array_diff($initial_phids, $phids);
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
$all_phids = array_merge($add_phids, $rem_phids);
|
|
|
|
|
|
|
|
$capabilities = $relationship->getRequiredRelationshipCapabilities();
|
2016-06-22 17:04:14 +02:00
|
|
|
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
if ($all_phids) {
|
2016-06-22 17:04:14 +02:00
|
|
|
$dst_objects = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($viewer)
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
->withPHIDs($all_phids)
|
2016-06-22 17:04:14 +02:00
|
|
|
->setRaisePolicyExceptions(true)
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
->requireCapabilities($capabilities)
|
2016-06-22 17:04:14 +02:00
|
|
|
->execute();
|
|
|
|
$dst_objects = mpull($dst_objects, null, 'getPHID');
|
|
|
|
} else {
|
|
|
|
$dst_objects = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
foreach ($add_phids as $add_phid) {
|
|
|
|
$dst_object = idx($dst_objects, $add_phid);
|
|
|
|
if (!$dst_object) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'You can not create a relationship to object "%s" because '.
|
|
|
|
'the object does not exist or could not be loaded.',
|
|
|
|
$add_phid));
|
|
|
|
}
|
|
|
|
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
if ($add_phid == $src_phid) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'You can not create a relationship to object "%s" because '.
|
|
|
|
'objects can not be related to themselves.',
|
|
|
|
$add_phid));
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:04:14 +02:00
|
|
|
if (!$relationship->canRelateObjects($object, $dst_object)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'You can not create a relationship (of type "%s") to object '.
|
|
|
|
'"%s" because it is not the right type of object for this '.
|
|
|
|
'relationship.',
|
|
|
|
$relationship->getRelationshipConstant(),
|
|
|
|
$add_phid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
return $this->newUnrelatableObjectResponse($ex, $done_uri);
|
|
|
|
}
|
|
|
|
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
$content_source = PhabricatorContentSource::newFromRequest($request);
|
|
|
|
$relationship->setContentSource($content_source);
|
|
|
|
|
2016-06-22 17:04:14 +02:00
|
|
|
$editor = $object->getApplicationTransactionEditor()
|
|
|
|
->setActor($viewer)
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
->setContentSource($content_source)
|
2016-06-22 17:04:14 +02:00
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect(true);
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = $object->getApplicationTransactionTemplate()
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $edge_type)
|
|
|
|
->setNewValue(array(
|
|
|
|
'+' => array_fuse($add_phids),
|
|
|
|
'-' => array_fuse($rem_phids),
|
|
|
|
));
|
|
|
|
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
$add_objects = array_select_keys($dst_objects, $add_phids);
|
|
|
|
$rem_objects = array_select_keys($dst_objects, $rem_phids);
|
|
|
|
|
|
|
|
if ($add_objects || $rem_objects) {
|
|
|
|
$more_xactions = $relationship->willUpdateRelationships(
|
|
|
|
$object,
|
|
|
|
$add_objects,
|
|
|
|
$rem_objects);
|
|
|
|
foreach ($more_xactions as $xaction) {
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:04:14 +02:00
|
|
|
try {
|
|
|
|
$editor->applyTransactions($object, $xactions);
|
|
|
|
|
Convert Maniphest merge operations to modern Relationship code
Summary:
Ref T4788. Fixes T7820. This updates the "Merge Duplicates In" interaction, and adds a "Close as Duplicate" action.
These are the last interactions that were using the old code, so it removes that code.
Merges are now recorded as real edges, so we can show them in the UI later on (originally from T9390, etc).
Also provides more general support for relationships which need EDIT permission, not-undoable relationships like merges, preventing relating an object to itself, and relationship side effects like merges.
Finally, fixes a couple of behaviors around typing an exact object name (like `T123`) to find the related object.
Test Plan:
- Merged tasks into the current task.
- Closed the current task as a duplicate of another task.
- Edited other relationships.
- Searched for tasks, commits, etc., by object monogram.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T4788, T7820
Differential Revision: https://secure.phabricator.com/D16196
2016-06-29 20:09:27 +02:00
|
|
|
if ($add_objects || $rem_objects) {
|
|
|
|
$relationship->didUpdateRelationships(
|
|
|
|
$object,
|
|
|
|
$add_objects,
|
|
|
|
$rem_objects);
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:04:14 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($done_uri);
|
|
|
|
} catch (PhabricatorEdgeCycleException $ex) {
|
|
|
|
return $this->newGraphCycleResponse($ex, $done_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$handles = iterator_to_array($handles);
|
|
|
|
$handles = array_select_keys($handles, $dst_phids);
|
|
|
|
|
|
|
|
// TODO: These are hard-coded for now.
|
|
|
|
$filters = array(
|
|
|
|
'assigned' => pht('Assigned to Me'),
|
|
|
|
'created' => pht('Created By Me'),
|
|
|
|
'open' => pht('All Open Objects'),
|
|
|
|
'all' => pht('All Objects'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$dialog_title = $relationship->getDialogTitleText();
|
|
|
|
$dialog_header = $relationship->getDialogHeaderText();
|
|
|
|
$dialog_button = $relationship->getDialogButtonText();
|
|
|
|
$dialog_instructions = $relationship->getDialogInstructionsText();
|
|
|
|
|
2016-06-29 01:05:05 +02:00
|
|
|
$source_uri = $relationship->getSourceURI($object);
|
2016-06-22 17:04:14 +02:00
|
|
|
|
|
|
|
return id(new PhabricatorObjectSelectorDialog())
|
|
|
|
->setUser($viewer)
|
2016-06-22 17:20:50 +02:00
|
|
|
->setInitialPHIDs($initial_phids)
|
2016-06-22 17:04:14 +02:00
|
|
|
->setHandles($handles)
|
|
|
|
->setFilters($filters)
|
|
|
|
->setSelectedFilter('created')
|
2016-06-29 01:05:05 +02:00
|
|
|
->setExcluded($src_phid)
|
2016-06-22 17:04:14 +02:00
|
|
|
->setCancelURI($done_uri)
|
2016-06-29 01:05:05 +02:00
|
|
|
->setSearchURI($source_uri)
|
2016-06-22 17:04:14 +02:00
|
|
|
->setTitle($dialog_title)
|
|
|
|
->setHeader($dialog_header)
|
|
|
|
->setButtonText($dialog_button)
|
|
|
|
->setInstructions($dialog_instructions)
|
|
|
|
->buildDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function newGraphCycleResponse(
|
|
|
|
PhabricatorEdgeCycleException $ex,
|
|
|
|
$done_uri) {
|
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$cycle = $ex->getCycle();
|
|
|
|
|
|
|
|
$handles = $this->loadViewerHandles($cycle);
|
|
|
|
$names = array();
|
|
|
|
foreach ($cycle as $cycle_phid) {
|
|
|
|
$names[] = $handles[$cycle_phid]->getFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = pht(
|
|
|
|
'You can not create that relationship because it would create a '.
|
2016-06-22 19:24:54 +02:00
|
|
|
'circular dependency:');
|
|
|
|
|
|
|
|
$list = implode(" \xE2\x86\x92 ", $names);
|
2016-06-22 17:04:14 +02:00
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Circular Dependency'))
|
|
|
|
->appendParagraph($message)
|
2016-06-22 19:24:54 +02:00
|
|
|
->appendParagraph($list)
|
2016-06-22 17:04:14 +02:00
|
|
|
->addCancelButton($done_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function newUnrelatableObjectResponse(Exception $ex, $done_uri) {
|
|
|
|
$message = $ex->getMessage();
|
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle(pht('Invalid Relationship'))
|
|
|
|
->appendParagraph($message)
|
|
|
|
->addCancelButton($done_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|