[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/draft/storage/ -> PhabricatorDraft.php (source)

   1  <?php
   2  
   3  final class PhabricatorDraft extends PhabricatorDraftDAO {
   4  
   5    protected $authorPHID;
   6    protected $draftKey;
   7    protected $draft;
   8    protected $metadata = array();
   9  
  10    private $deleted = false;
  11  
  12    public function getConfiguration() {
  13      return array(
  14        self::CONFIG_SERIALIZATION => array(
  15          'metadata' => self::SERIALIZATION_JSON,
  16        ),
  17        self::CONFIG_COLUMN_SCHEMA => array(
  18          'draftKey' => 'text64',
  19          'draft' => 'text',
  20        ),
  21        self::CONFIG_KEY_SCHEMA => array(
  22          'authorPHID' => array(
  23            'columns' => array('authorPHID', 'draftKey'),
  24            'unique' => true,
  25          ),
  26        ),
  27      ) + parent::getConfiguration();
  28    }
  29  
  30    public function replaceOrDelete() {
  31      if ($this->draft == '' && !array_filter($this->metadata)) {
  32        queryfx(
  33          $this->establishConnection('w'),
  34          'DELETE FROM %T WHERE authorPHID = %s AND draftKey = %s',
  35          $this->getTableName(),
  36          $this->authorPHID,
  37          $this->draftKey);
  38        $this->deleted = true;
  39        return $this;
  40      }
  41      return parent::replace();
  42    }
  43  
  44    protected function didDelete() {
  45      $this->deleted = true;
  46    }
  47  
  48    public function isDeleted() {
  49      return $this->deleted;
  50    }
  51  
  52    public static function newFromUserAndKey(PhabricatorUser $user, $key) {
  53      if ($user->getPHID() && strlen($key)) {
  54        $draft = id(new PhabricatorDraft())->loadOneWhere(
  55          'authorPHID = %s AND draftKey = %s',
  56          $user->getPHID(),
  57          $key);
  58        if ($draft) {
  59          return $draft;
  60        }
  61      }
  62  
  63      $draft = new PhabricatorDraft();
  64      if ($user->getPHID()) {
  65        $draft
  66          ->setAuthorPHID($user->getPHID())
  67          ->setDraftKey($key);
  68      }
  69  
  70      return $draft;
  71    }
  72  
  73    public static function buildFromRequest(AphrontRequest $request) {
  74      $user = $request->getUser();
  75      if (!$user->getPHID()) {
  76        return null;
  77      }
  78  
  79      if (!$request->getStr('__draft__')) {
  80        return null;
  81      }
  82  
  83      $draft = id(new PhabricatorDraft())
  84        ->setAuthorPHID($user->getPHID())
  85        ->setDraftKey($request->getStr('__draft__'));
  86  
  87      // If this is a preview, add other data. If not, leave the draft empty so
  88      // that replaceOrDelete() will delete it.
  89      if ($request->isPreviewRequest()) {
  90        $other_data = $request->getPassthroughRequestData();
  91        unset($other_data['comment']);
  92  
  93        $draft
  94          ->setDraft($request->getStr('comment'))
  95          ->setMetadata($other_data);
  96      }
  97  
  98      return $draft;
  99    }
 100  
 101  }


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