Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / differential / storage / DifferentialViewState.php
blob44c1f308d8aec98aad064a677bbb4a0fd6d1e9ad
1 <?php
3 final class DifferentialViewState
4 extends DifferentialDAO
5 implements PhabricatorPolicyInterface {
7 protected $viewerPHID;
8 protected $objectPHID;
9 protected $viewState = array();
11 private $hasModifications;
13 protected function getConfiguration() {
14 return array(
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'),
21 'unique' => true,
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,
35 $key,
36 $value) {
38 if ($this->getChangesetProperty($changeset, $key) === $value) {
39 return;
42 $properties = array(
43 'value' => $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] =
63 $properties;
66 public function getChangesetProperty(
67 DifferentialChangeset $changeset,
68 $key,
69 $default = null) {
71 $entries = $this->getChangesetPropertyEntries(
72 $changeset,
73 $key);
75 $entries = isort($entries, 'epoch');
77 $entry = last($entries);
78 if (!is_array($entry)) {
79 $entry = array();
82 return idx($entry, 'value', $default);
85 public function getChangesetPropertyEntries(
86 DifferentialChangeset $changeset,
87 $key) {
88 $path_hash = $this->getChangesetPathHash($changeset);
90 $entries = idxv($this->viewState, array('changesets', $path_hash, $key));
91 if (!is_array($entries)) {
92 $entries = array();
95 return $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();
110 if ($key === null) {
111 return '*';
114 return (string)$key;
117 public static function copyViewStatesToObject($src_phid, $dst_phid) {
118 $table = new self();
119 $conn = $table->establishConnection('w');
121 queryfx(
122 $conn,
123 'INSERT IGNORE INTO %R
124 (viewerPHID, objectPHID, viewState, dateCreated, dateModified)
125 SELECT viewerPHID, %s, viewState, dateCreated, dateModified
126 FROM %R WHERE objectPHID = %s',
127 $table,
128 $dst_phid,
129 $table,
130 $src_phid);
133 /* -( PhabricatorPolicyInterface )----------------------------------------- */
136 public function getCapabilities() {
137 return array(
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());