3 final class DifferentialViewState
4 extends DifferentialDAO
5 implements PhabricatorPolicyInterface
{
9 protected $viewState = array();
11 private $hasModifications;
13 protected function getConfiguration() {
15 self
::CONFIG_SERIALIZATION
=> array(
16 'viewState' => self
::SERIALIZATION_JSON
,
18 self
::CONFIG_KEY_SCHEMA
=> array(
19 'key_viewer' => array(
20 'columns' => array('viewerPHID', 'objectPHID'),
23 'key_object' => array(
24 'columns' => array('objectPHID'),
26 'key_modified' => array(
27 'columns' => array('dateModified'),
30 ) + parent
::getConfiguration();
33 public function setChangesetProperty(
34 DifferentialChangeset
$changeset,
38 if ($this->getChangesetProperty($changeset, $key) === $value) {
44 'epoch' => PhabricatorTime
::getNow(),
47 $diff_id = $changeset->getDiffID();
48 if ($diff_id !== null) {
49 $properties['diffID'] = (int)$diff_id;
52 $changeset_id = $changeset->getID();
53 if ($changeset_id !== null) {
54 $properties['changesetID'] = (int)$changeset_id;
57 $path_hash = $this->getChangesetPathHash($changeset);
58 $changeset_phid = $this->getChangesetKey($changeset);
60 $this->hasModifications
= true;
62 $this->viewState
['changesets'][$path_hash][$key][$changeset_phid] =
66 public function getChangesetProperty(
67 DifferentialChangeset
$changeset,
71 $entries = $this->getChangesetPropertyEntries(
75 $entries = isort($entries, 'epoch');
77 $entry = last($entries);
78 if (!is_array($entry)) {
82 return idx($entry, 'value', $default);
85 public function getChangesetPropertyEntries(
86 DifferentialChangeset
$changeset,
88 $path_hash = $this->getChangesetPathHash($changeset);
90 $entries = idxv($this->viewState
, array('changesets', $path_hash, $key));
91 if (!is_array($entries)) {
98 public function getHasModifications() {
99 return $this->hasModifications
;
102 private function getChangesetPathHash(DifferentialChangeset
$changeset) {
103 $path = $changeset->getFilename();
104 return PhabricatorHash
::digestForIndex($path);
107 private function getChangesetKey(DifferentialChangeset
$changeset) {
108 $key = $changeset->getID();
117 public static function copyViewStatesToObject($src_phid, $dst_phid) {
119 $conn = $table->establishConnection('w');
123 'INSERT IGNORE INTO %R
124 (viewerPHID, objectPHID, viewState, dateCreated, dateModified)
125 SELECT viewerPHID, %s, viewState, dateCreated, dateModified
126 FROM %R WHERE objectPHID = %s',
133 /* -( PhabricatorPolicyInterface )----------------------------------------- */
136 public function getCapabilities() {
138 PhabricatorPolicyCapability
::CAN_VIEW
,
142 public function getPolicy($capability) {
143 return PhabricatorPolicies
::POLICY_NOONE
;
146 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
147 return ($viewer->getPHID() === $this->getViewerPHID());