[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/system/engine/ -> PhabricatorDestructionEngine.php (source)

   1  <?php
   2  
   3  final class PhabricatorDestructionEngine extends Phobject {
   4  
   5    private $rootLogID;
   6  
   7    public function destroyObject(PhabricatorDestructibleInterface $object) {
   8      $log = id(new PhabricatorSystemDestructionLog())
   9        ->setEpoch(time())
  10        ->setObjectClass(get_class($object));
  11  
  12      if ($this->rootLogID) {
  13        $log->setRootLogID($this->rootLogID);
  14      }
  15  
  16      $object_phid = null;
  17      if (method_exists($object, 'getPHID')) {
  18        try {
  19          $object_phid = $object->getPHID();
  20          $log->setObjectPHID($object_phid);
  21        } catch (Exception $ex) {
  22          // Ignore.
  23        }
  24      }
  25  
  26      if (method_exists($object, 'getMonogram')) {
  27        try {
  28          $log->setObjectMonogram($object->getMonogram());
  29        } catch (Exception $ex) {
  30          // Ignore.
  31        }
  32      }
  33  
  34      $log->save();
  35  
  36      if (!$this->rootLogID) {
  37        $this->rootLogID = $log->getID();
  38      }
  39  
  40      $object->destroyObjectPermanently($this);
  41  
  42      if ($object_phid) {
  43        $this->destroyEdges($object_phid);
  44  
  45        if ($object instanceof PhabricatorApplicationTransactionInterface) {
  46          $template = $object->getApplicationTransactionTemplate();
  47          $this->destroyTransactions($template, $object_phid);
  48        }
  49      }
  50  
  51      // Nuke any Herald transcripts of the object, because they may contain
  52      // field data.
  53  
  54      // TODO: Define an interface so we don't have to do this for transactions
  55      // and other objects with no Herald adapters?
  56      $transcripts = id(new HeraldTranscript())->loadAllWhere(
  57        'objectPHID = %s',
  58        $object_phid);
  59      foreach ($transcripts as $transcript) {
  60        $transcript->destroyObjectPermanently($this);
  61      }
  62  
  63      // TODO: Remove stuff from search indexes?
  64      // TODO: PhabricatorFlaggableInterface
  65      // TODO: PhabricatorTokenReceiverInterface
  66    }
  67  
  68    private function destroyEdges($src_phid) {
  69      try {
  70        $edges = id(new PhabricatorEdgeQuery())
  71          ->withSourcePHIDs(array($src_phid))
  72          ->execute();
  73      } catch (Exception $ex) {
  74        // This is (presumably) a "no edges for this PHID type" exception.
  75        return;
  76      }
  77  
  78      $editor = new PhabricatorEdgeEditor();
  79      foreach ($edges as $type => $type_edges) {
  80        foreach ($type_edges as $src => $src_edges) {
  81          foreach ($src_edges as $dst => $edge) {
  82            $editor->removeEdge($edge['src'], $edge['type'], $edge['dst']);
  83          }
  84        }
  85      }
  86      $editor->save();
  87    }
  88  
  89    private function destroyTransactions(
  90      PhabricatorApplicationTransaction $template,
  91      $object_phid) {
  92  
  93      $xactions = $template->loadAllWhere('objectPHID = %s', $object_phid);
  94      foreach ($xactions as $xaction) {
  95        $this->destroyObject($xaction);
  96      }
  97  
  98    }
  99  
 100  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1