Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F438315
20170528.maniphestdupes.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
20170528.maniphestdupes.php
View Options
<?php
$table
=
new
ManiphestTransaction
();
$add_edges
=
array
();
foreach
(
new
LiskMigrationIterator
(
$table
)
as
$txn
)
{
$txn_type
=
$txn
->
getTransactionType
();
if
(
$txn_type
==
'mergedinto'
)
{
// dupe handling as implemented in D10427, which creates a specific txn
$add_edges
[]
=
array
(
'src'
=>
$txn
->
getObjectPHID
(),
'dst'
=>
$txn
->
getNewValue
(),
);
}
else
if
(
$txn_type
==
'status'
&&
$txn
->
getNewValue
()
==
'duplicate'
)
{
// dupe handling as originally implemented, which just changes the status
// and adds a comment
$src_phid
=
$txn
->
getObjectPHID
();
// get all the comment transactions associated with this task
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$comment_txns
=
id
(
new
ManiphestTransactionQuery
())
->
setViewer
(
$viewer
)
->
withObjectPHIDs
(
array
(
$src_phid
))
->
needComments
(
true
)
->
execute
();
// check each comment, looking for the "Merged Into" message
foreach
(
$comment_txns
as
$comment_txn
)
{
if
(
$comment_txn
->
hasComment
())
{
$comment
=
$comment_txn
->
getComment
()->
getContent
();
$pattern
=
'/^
\x
E2
\x
9C
\x
98 Merged into T(
\d
+)
\.
$/'
;
$matches
=
array
();
if
(
preg_match
(
$pattern
,
$comment
,
$matches
))
{
$dst_task
=
id
(
new
ManiphestTaskQuery
())
->
setViewer
(
$viewer
)
->
withIDs
(
array
(
$matches
[
1
]))
->
executeOne
();
if
(
$dst_task
)
{
$dst_phid
=
$dst_task
->
getPHID
();
$add_edges
[]
=
array
(
'src'
=>
$src_phid
,
'dst'
=>
$dst_phid
,
);
}
}
}
}
}
}
if
(
$add_edges
)
{
foreach
(
$add_edges
as
$edge
)
{
$src_phid
=
$edge
[
'src'
];
$dst_phid
=
$edge
[
'dst'
];
$type
=
ManiphestTaskIsDuplicateOfTaskEdgeType
::
EDGECONST
;
try
{
$editor
=
id
(
new
PhabricatorEdgeEditor
())
->
addEdge
(
$src_phid
,
$type
,
$dst_phid
)
->
save
();
}
catch
(
PhabricatorEdgeCycleException
$ex
)
{
// Some earlier or later merge made this invalid, just skip it.
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 2:21 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
63029
Default Alt Text
20170528.maniphestdupes.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment