Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F972154
PhabricatorDestructionEngine.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
PhabricatorDestructionEngine.php
View Options
<?php
final
class
PhabricatorDestructionEngine
extends
Phobject
{
private
$rootLogID
;
public
function
destroyObject
(
PhabricatorDestructibleInterface
$object
)
{
$log
=
id
(
new
PhabricatorSystemDestructionLog
())
->
setEpoch
(
time
())
->
setObjectClass
(
get_class
(
$object
));
if
(
$this
->
rootLogID
)
{
$log
->
setRootLogID
(
$this
->
rootLogID
);
}
$object_phid
=
null
;
if
(
method_exists
(
$object
,
'getPHID'
))
{
try
{
$object_phid
=
$object
->
getPHID
();
$log
->
setObjectPHID
(
$object_phid
);
}
catch
(
Exception
$ex
)
{
// Ignore.
}
}
if
(
method_exists
(
$object
,
'getMonogram'
))
{
try
{
$log
->
setObjectMonogram
(
$object
->
getMonogram
());
}
catch
(
Exception
$ex
)
{
// Ignore.
}
}
$log
->
save
();
if
(!
$this
->
rootLogID
)
{
$this
->
rootLogID
=
$log
->
getID
();
}
$object
->
destroyObjectPermanently
(
$this
);
if
(
$object_phid
)
{
$this
->
destroyEdges
(
$object_phid
);
if
(
$object
instanceof
PhabricatorApplicationTransactionInterface
)
{
$template
=
$object
->
getApplicationTransactionTemplate
();
$this
->
destroyTransactions
(
$template
,
$object_phid
);
}
$this
->
destroyWorkerTasks
(
$object_phid
);
$this
->
destroyNotifications
(
$object_phid
);
}
// Nuke any Herald transcripts of the object, because they may contain
// field data.
// TODO: Define an interface so we don't have to do this for transactions
// and other objects with no Herald adapters?
$transcripts
=
id
(
new
HeraldTranscript
())->
loadAllWhere
(
'objectPHID = %s'
,
$object_phid
);
foreach
(
$transcripts
as
$transcript
)
{
$transcript
->
destroyObjectPermanently
(
$this
);
}
// TODO: Remove stuff from search indexes?
// TODO: PhabricatorFlaggableInterface
// TODO: PhabricatorTokenReceiverInterface
}
private
function
destroyEdges
(
$src_phid
)
{
try
{
$edges
=
id
(
new
PhabricatorEdgeQuery
())
->
withSourcePHIDs
(
array
(
$src_phid
))
->
execute
();
}
catch
(
Exception
$ex
)
{
// This is (presumably) a "no edges for this PHID type" exception.
return
;
}
$editor
=
new
PhabricatorEdgeEditor
();
foreach
(
$edges
as
$type
=>
$type_edges
)
{
foreach
(
$type_edges
as
$src
=>
$src_edges
)
{
foreach
(
$src_edges
as
$dst
=>
$edge
)
{
$editor
->
removeEdge
(
$edge
[
'src'
],
$edge
[
'type'
],
$edge
[
'dst'
]);
}
}
}
$editor
->
save
();
}
private
function
destroyTransactions
(
PhabricatorApplicationTransaction
$template
,
$object_phid
)
{
$xactions
=
$template
->
loadAllWhere
(
'objectPHID = %s'
,
$object_phid
);
foreach
(
$xactions
as
$xaction
)
{
$this
->
destroyObject
(
$xaction
);
}
}
private
function
destroyWorkerTasks
(
$object_phid
)
{
$tasks
=
id
(
new
PhabricatorWorkerActiveTask
())->
loadAllWhere
(
'objectPHID = %s'
,
$object_phid
);
foreach
(
$tasks
as
$task
)
{
$task
->
archiveTask
(
PhabricatorWorkerArchiveTask
::
RESULT_CANCELLED
,
0
);
}
}
private
function
destroyNotifications
(
$object_phid
)
{
$notifications
=
id
(
new
PhabricatorFeedStoryNotification
())->
loadAllWhere
(
'primaryObjectPHID = %s'
,
$object_phid
);
foreach
(
$notifications
as
$notification
)
{
$notification
->
delete
();
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jun 18, 6:04 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
229272
Default Alt Text
PhabricatorDestructionEngine.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment