Changeset View
Changeset View
Standalone View
Standalone View
src/applications/system/engine/PhabricatorDestructionEngine.php
Show All 11 Lines | public function destroyObject(PhabricatorDestructibleInterface $object) { | ||||
$log = id(new PhabricatorSystemDestructionLog()) | $log = id(new PhabricatorSystemDestructionLog()) | ||||
->setEpoch(time()) | ->setEpoch(time()) | ||||
->setObjectClass(get_class($object)); | ->setObjectClass(get_class($object)); | ||||
if ($this->rootLogID) { | if ($this->rootLogID) { | ||||
$log->setRootLogID($this->rootLogID); | $log->setRootLogID($this->rootLogID); | ||||
} | } | ||||
$object_phid = null; | $object_phid = $this->getObjectPHID($object); | ||||
if (method_exists($object, 'getPHID')) { | if ($object_phid) { | ||||
try { | |||||
$object_phid = $object->getPHID(); | |||||
$log->setObjectPHID($object_phid); | $log->setObjectPHID($object_phid); | ||||
} catch (Exception $ex) { | |||||
// Ignore. | |||||
} | |||||
} | } | ||||
if (method_exists($object, 'getMonogram')) { | if (method_exists($object, 'getMonogram')) { | ||||
try { | try { | ||||
$log->setObjectMonogram($object->getMonogram()); | $log->setObjectMonogram($object->getMonogram()); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
// Ignore. | // Ignore. | ||||
} | } | ||||
} | } | ||||
$log->save(); | $log->save(); | ||||
if (!$this->rootLogID) { | if (!$this->rootLogID) { | ||||
$this->rootLogID = $log->getID(); | $this->rootLogID = $log->getID(); | ||||
} | } | ||||
$object->destroyObjectPermanently($this); | $object->destroyObjectPermanently($this); | ||||
$extensions = PhabricatorDestructionEngineExtension::getAllExtensions(); | |||||
foreach ($extensions as $key => $extension) { | |||||
if (!$extension->canDestroyObject($this, $object)) { | |||||
unset($extensions[$key]); | |||||
continue; | |||||
} | |||||
} | |||||
foreach ($extensions as $key => $extension) { | |||||
$extension->destroyObject($this, $object); | |||||
} | |||||
if ($object_phid) { | if ($object_phid) { | ||||
$this->destroyEdges($object_phid); | $this->destroyEdges($object_phid); | ||||
if ($object instanceof PhabricatorApplicationTransactionInterface) { | if ($object instanceof PhabricatorApplicationTransactionInterface) { | ||||
$template = $object->getApplicationTransactionTemplate(); | $template = $object->getApplicationTransactionTemplate(); | ||||
$this->destroyTransactions($template, $object_phid); | $this->destroyTransactions($template, $object_phid); | ||||
} | } | ||||
Show All 33 Lines | public function destroyObject(PhabricatorDestructibleInterface $object) { | ||||
if ($object instanceof PhabricatorTokenReceiverInterface) { | if ($object instanceof PhabricatorTokenReceiverInterface) { | ||||
$tokens = id(new PhabricatorTokenGiven())->loadAllWhere( | $tokens = id(new PhabricatorTokenGiven())->loadAllWhere( | ||||
'objectPHID = %s', $object_phid); | 'objectPHID = %s', $object_phid); | ||||
foreach ($tokens as $token) { | foreach ($tokens as $token) { | ||||
$token->delete(); | $token->delete(); | ||||
} | } | ||||
} | } | ||||
if ($object instanceof AlmanacPropertyInterface) { | |||||
$this->destroyAlmanacProperties($object_phid); | |||||
} | |||||
} | } | ||||
private function destroyEdges($src_phid) { | private function destroyEdges($src_phid) { | ||||
try { | try { | ||||
$edges = id(new PhabricatorEdgeQuery()) | $edges = id(new PhabricatorEdgeQuery()) | ||||
->withSourcePHIDs(array($src_phid)) | ->withSourcePHIDs(array($src_phid)) | ||||
->execute(); | ->execute(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
Show All 40 Lines | private function destroyNotifications($object_phid) { | ||||
queryfx( | queryfx( | ||||
$conn_w, | $conn_w, | ||||
'DELETE FROM %T WHERE primaryObjectPHID = %s', | 'DELETE FROM %T WHERE primaryObjectPHID = %s', | ||||
$table->getTableName(), | $table->getTableName(), | ||||
$object_phid); | $object_phid); | ||||
} | } | ||||
private function destroyAlmanacProperties($object_phid) { | private function destroyAlmanacProperties($object_phid) {} | ||||
$table = new AlmanacProperty(); | |||||
$conn_w = $table->establishConnection('w'); | |||||
queryfx( | public function getObjectPHID($object) { | ||||
$conn_w, | if (!is_object($object)) { | ||||
'DELETE FROM %T WHERE objectPHID = %s', | return null; | ||||
$table->getTableName(), | } | ||||
$object_phid); | |||||
if (!method_exists($object, 'getPHID')) { | |||||
return null; | |||||
} | |||||
try { | |||||
return $object->getPHID(); | |||||
} catch (Exception $ex) { | |||||
return null; | |||||
} | |||||
} | } | ||||
} | } |