Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F4981158
migration.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
amckinley
May 28 2017, 10:51 PM
2017-05-28 22:51:28 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
migration.php
View Options
<?php
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
// find all tasks with status = dupe
$tasks
=
id
(
new
ManiphestTaskQuery
())
->
setViewer
(
$viewer
)
->
withStatus
(
'status-duplicate'
)
->
execute
();
foreach
(
$tasks
as
$task
)
{
// find the merge transaction
$merge_xaction
=
id
(
new
ManiphestTransactionQuery
())
->
setViewer
(
$viewer
)
->
withObjectPHIDs
(
array
(
$task
->
getPHID
()))
->
withTransactionTypes
(
array
(
'mergedinto'
))
->
needComments
(
true
)
->
executeOne
();
// find the merge transaction's author to use as the viewer
$author_phid
=
$merge_xaction
->
getAuthorPHID
();
$author
=
id
(
new
PhabricatorPeopleQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$author_phid
))
->
executeOne
();
// find the task we merged into
$target_phid
=
$merge_xaction
->
getNewValue
();
$merged_into
=
id
(
new
ManiphestTaskQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$target_phid
))
->
executeOne
();
// build the relationship object
$list
=
PhabricatorObjectRelationshipList
::
newForObject
(
$author
,
$task
);
$relkey
=
ManiphestTaskCloseAsDuplicateRelationship
::
RELATIONSHIPKEY
;
$relationship
=
$list
->
getRelationship
(
$relkey
)
->
setContentSource
(
id
(
new
PhabricatorUnknownContentSource
()));
$edge_type
=
$relationship
->
getEdgeConstant
();
// build the edge transactions
$add_phids
=
array
(
$merged_into
->
getPHID
());
$rem_phids
=
array
();
$xactions
=
array
();
$xactions
[]
=
$task
->
getApplicationTransactionTemplate
()
->
setTransactionType
(
PhabricatorTransactions
::
TYPE_EDGE
)
->
setMetadataValue
(
'edge:type'
,
$edge_type
)
->
setNewValue
(
array
(
'+'
=>
array_fuse
(
$add_phids
),
'-'
=>
array_fuse
(
$rem_phids
),
));
// // invoke willUpdateRelationships, which creates more transactions
// $add_objects = array($merged_into);
// $rem_objects = array();
// $more_xactions = $relationship->willUpdateRelationships(
// $task,
// $add_objects,
// $rem_objects);
// foreach ($more_xactions as $xaction) {
// $xactions[] = $xaction;
// }
$editor
=
$task
->
getApplicationTransactionEditor
()
->
setActor
(
$author
)
->
setContentSource
(
id
(
new
PhabricatorUnknownContentSource
()))
->
setContinueOnMissingFields
(
true
)
->
setContinueOnNoEffect
(
true
);
// apply all the transactions we have so far
$editor
->
applyTransactions
(
$task
,
$xactions
);
// // invoke didUpdateRelationships, which applies its own transactions
// if ($add_objects || $rem_objects) {
// $relationship->didUpdateRelationships(
// $task,
// $add_objects,
// $rem_objects);
// }
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
670064
Default Alt Text
migration.php (2 KB)
Attached To
Mode
P2055 migration.php
Attached
Detach File
Event Timeline
Log In to Comment