2014-02-19 01:25:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialDraft extends DifferentialDAO {
|
|
|
|
|
|
|
|
protected $objectPHID;
|
|
|
|
protected $authorPHID;
|
|
|
|
protected $draftKey;
|
|
|
|
|
2015-01-13 20:47:05 +01:00
|
|
|
protected function getConfiguration() {
|
2014-09-29 00:12:58 +02:00
|
|
|
return array(
|
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'draftKey' => 'text64',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_unique' => array(
|
|
|
|
'columns' => array('objectPHID', 'authorPHID', 'draftKey'),
|
|
|
|
'unique' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:25:16 +01:00
|
|
|
public static function markHasDraft(
|
|
|
|
$author_phid,
|
|
|
|
$object_phid,
|
|
|
|
$draft_key) {
|
|
|
|
try {
|
|
|
|
id(new DifferentialDraft())
|
|
|
|
->setObjectPHID($object_phid)
|
|
|
|
->setAuthorPHID($author_phid)
|
|
|
|
->setDraftKey($draft_key)
|
|
|
|
->save();
|
2014-08-05 23:51:21 +02:00
|
|
|
} catch (AphrontDuplicateKeyQueryException $ex) {
|
2014-02-19 01:25:16 +01:00
|
|
|
// no worries
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function deleteHasDraft(
|
|
|
|
$author_phid,
|
|
|
|
$object_phid,
|
|
|
|
$draft_key) {
|
|
|
|
$draft = id(new DifferentialDraft())->loadOneWhere(
|
|
|
|
'objectPHID = %s AND authorPHID = %s AND draftKey = %s',
|
|
|
|
$object_phid,
|
|
|
|
$author_phid,
|
|
|
|
$draft_key);
|
|
|
|
if ($draft) {
|
|
|
|
$draft->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function deleteAllDrafts(
|
|
|
|
$author_phid,
|
|
|
|
$object_phid) {
|
|
|
|
|
|
|
|
$drafts = id(new DifferentialDraft())->loadAllWhere(
|
|
|
|
'objectPHID = %s AND authorPHID = %s',
|
|
|
|
$object_phid,
|
|
|
|
$author_phid);
|
|
|
|
foreach ($drafts as $draft) {
|
|
|
|
$draft->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|