Changeset View
Changeset View
Standalone View
Standalone View
src/applications/system/engine/PhabricatorDestructionEngine.php
Show All 32 Lines | public function destroyObject(PhabricatorDestructibleInterface $object) { | ||||
$log->save(); | $log->save(); | ||||
if (!$this->rootLogID) { | if (!$this->rootLogID) { | ||||
$this->rootLogID = $log->getID(); | $this->rootLogID = $log->getID(); | ||||
} | } | ||||
$object->destroyObjectPermanently($this); | $object->destroyObjectPermanently($this); | ||||
if ($object_phid) { | |||||
$extensions = PhabricatorDestructionEngineExtension::getAllExtensions(); | $extensions = PhabricatorDestructionEngineExtension::getAllExtensions(); | ||||
foreach ($extensions as $key => $extension) { | foreach ($extensions as $key => $extension) { | ||||
if (!$extension->canDestroyObject($this, $object)) { | if (!$extension->canDestroyObject($this, $object)) { | ||||
unset($extensions[$key]); | unset($extensions[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
foreach ($extensions as $key => $extension) { | foreach ($extensions as $key => $extension) { | ||||
$extension->destroyObject($this, $object); | $extension->destroyObject($this, $object); | ||||
} | } | ||||
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 | private function getObjectPHID($object) { | ||||
// 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? | |||||
if ($object instanceof PhabricatorFlaggableInterface) { | |||||
$flags = id(new PhabricatorFlag())->loadAllWhere( | |||||
'objectPHID = %s', $object_phid); | |||||
foreach ($flags as $flag) { | |||||
$flag->delete(); | |||||
} | |||||
} | |||||
$flags = id(new PhabricatorFlag())->loadAllWhere( | |||||
'ownerPHID = %s', $object_phid); | |||||
foreach ($flags as $flag) { | |||||
$flag->delete(); | |||||
} | |||||
if ($object instanceof PhabricatorTokenReceiverInterface) { | |||||
$tokens = id(new PhabricatorTokenGiven())->loadAllWhere( | |||||
'objectPHID = %s', $object_phid); | |||||
foreach ($tokens as $token) { | |||||
$token->delete(); | |||||
} | |||||
} | |||||
} | |||||
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) { | |||||
$table = new PhabricatorFeedStoryNotification(); | |||||
$conn_w = $table->establishConnection('w'); | |||||
queryfx( | |||||
$conn_w, | |||||
'DELETE FROM %T WHERE primaryObjectPHID = %s', | |||||
$table->getTableName(), | |||||
$object_phid); | |||||
} | |||||
private function destroyAlmanacProperties($object_phid) {} | |||||
public function getObjectPHID($object) { | |||||
if (!is_object($object)) { | if (!is_object($object)) { | ||||
return null; | return null; | ||||
} | } | ||||
if (!method_exists($object, 'getPHID')) { | if (!method_exists($object, 'getPHID')) { | ||||
return null; | return null; | ||||
} | } | ||||
try { | try { | ||||
return $object->getPHID(); | return $object->getPHID(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
} | } |