Changeset View
Changeset View
Standalone View
Standalone View
src/applications/system/engine/PhabricatorDestructionEngine.php
<?php | <?php | ||||
final class PhabricatorDestructionEngine extends Phobject { | final class PhabricatorDestructionEngine extends Phobject { | ||||
private $rootLogID; | private $rootLogID; | ||||
private $collectNotes; | private $collectNotes; | ||||
private $notes = array(); | private $notes = array(); | ||||
private $depth = 0; | |||||
private $destroyedObjects = array(); | |||||
private $waitToFinalizeDestruction = false; | |||||
public function setCollectNotes($collect_notes) { | public function setCollectNotes($collect_notes) { | ||||
$this->collectNotes = $collect_notes; | $this->collectNotes = $collect_notes; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getNotes() { | public function getNotes() { | ||||
return $this->notes; | return $this->notes; | ||||
} | } | ||||
public function getViewer() { | public function getViewer() { | ||||
return PhabricatorUser::getOmnipotentUser(); | return PhabricatorUser::getOmnipotentUser(); | ||||
} | } | ||||
public function setWaitToFinalizeDestruction($wait) { | |||||
$this->waitToFinalizeDestruction = $wait; | |||||
return $this; | |||||
} | |||||
public function getWaitToFinalizeDestruction() { | |||||
return $this->waitToFinalizeDestruction; | |||||
} | |||||
public function destroyObject(PhabricatorDestructibleInterface $object) { | public function destroyObject(PhabricatorDestructibleInterface $object) { | ||||
$this->depth++; | |||||
$log = id(new PhabricatorSystemDestructionLog()) | $log = id(new PhabricatorSystemDestructionLog()) | ||||
->setEpoch(time()) | ->setEpoch(PhabricatorTime::getNow()) | ||||
->setObjectClass(get_class($object)); | ->setObjectClass(get_class($object)); | ||||
if ($this->rootLogID) { | if ($this->rootLogID) { | ||||
$log->setRootLogID($this->rootLogID); | $log->setRootLogID($this->rootLogID); | ||||
} | } | ||||
$object_phid = $this->getObjectPHID($object); | $object_phid = $this->getObjectPHID($object); | ||||
if ($object_phid) { | if ($object_phid) { | ||||
Show All 35 Lines | if ($object_phid) { | ||||
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); | ||||
} | } | ||||
$this->destroyedObjects[] = $object; | |||||
} | |||||
$this->depth--; | |||||
// If this is a root-level invocation of "destroyObject()", flush the | |||||
// queue of destroyed objects and fire "didDestroyObject()" hooks. This | |||||
// hook allows extensions to do things like queue cache updates which | |||||
// might race if we fire them during object destruction. | |||||
if (!$this->depth) { | |||||
if (!$this->getWaitToFinalizeDestruction()) { | |||||
$this->finalizeDestruction(); | |||||
} | } | ||||
} | } | ||||
return $this; | |||||
} | |||||
public function finalizeDestruction() { | |||||
$extensions = PhabricatorDestructionEngineExtension::getAllExtensions(); | |||||
foreach ($this->destroyedObjects as $object) { | |||||
foreach ($extensions as $extension) { | |||||
if (!$extension->canDestroyObject($this, $object)) { | |||||
continue; | |||||
} | |||||
$extension->didDestroyObject($this, $object); | |||||
} | |||||
} | |||||
$this->destroyedObjects = array(); | |||||
return $this; | |||||
} | |||||
private function getObjectPHID($object) { | private 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; | ||||
} | } | ||||
Show All 9 Lines |