3 final class PhabricatorDraft
extends PhabricatorDraftDAO
{
8 protected $metadata = array();
10 private $deleted = false;
12 protected function getConfiguration() {
14 self
::CONFIG_SERIALIZATION
=> array(
15 'metadata' => self
::SERIALIZATION_JSON
,
17 self
::CONFIG_COLUMN_SCHEMA
=> array(
18 'draftKey' => 'text64',
21 self
::CONFIG_KEY_SCHEMA
=> array(
22 'authorPHID' => array(
23 'columns' => array('authorPHID', 'draftKey'),
27 ) + parent
::getConfiguration();
30 public function replaceOrDelete() {
31 if ($this->draft
== '' && !array_filter($this->metadata
)) {
33 $this->establishConnection('w'),
34 'DELETE FROM %T WHERE authorPHID = %s AND draftKey = %s',
35 $this->getTableName(),
38 $this->deleted
= true;
41 return parent
::replace();
44 protected function didDelete() {
45 $this->deleted
= true;
48 public function isDeleted() {
49 return $this->deleted
;
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',
63 $draft = new PhabricatorDraft();
64 if ($user->getPHID()) {
66 ->setAuthorPHID($user->getPHID())
73 public static function buildFromRequest(AphrontRequest
$request) {
74 $user = $request->getUser();
75 if (!$user->getPHID()) {
79 if (!$request->getStr('__draft__')) {
83 $draft = id(new PhabricatorDraft())
84 ->setAuthorPHID($user->getPHID())
85 ->setDraftKey($request->getStr('__draft__'));
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']);
94 ->setDraft($request->getStr('comment'))
95 ->setMetadata($other_data);