3
final class DivinerLiveSymbol extends DivinerDAO
4
implements PhabricatorPolicyInterface, PhabricatorMarkupInterface {
12
protected $identityHash;
16
protected $titleSlugHash;
19
protected $isDocumentable = 0;
21
private $book = self::ATTACHABLE;
22
private $atom = self::ATTACHABLE;
23
private $extends = self::ATTACHABLE;
24
private $children = self::ATTACHABLE;
26
public function getConfiguration() {
28
self::CONFIG_AUX_PHID => true,
29
self::CONFIG_TIMESTAMPS => false,
30
self::CONFIG_COLUMN_SCHEMA => array(
31
'context' => 'text255?',
34
'atomIndex' => 'uint32',
35
'identityHash' => 'bytes12',
36
'graphHash' => 'text64?',
38
'titleSlugHash' => 'bytes12?',
39
'groupName' => 'text255?',
41
'isDocumentable' => 'bool',
42
'nodeHash' => 'text64?',
44
self::CONFIG_KEY_SCHEMA => array(
46
'identityHash' => array(
47
'columns' => array('identityHash'),
51
'columns' => array('phid'),
55
'columns' => array('graphHash'),
59
'columns' => array('nodeHash'),
72
'columns' => array('name(64)'),
75
'columns' => array('titleSlugHash'),
78
) + parent::getConfiguration();
81
public function generatePHID() {
82
return PhabricatorPHID::generateNewPHID(DivinerAtomPHIDType::TYPECONST);
85
public function getBook() {
86
return $this->assertAttached($this->book);
89
public function attachBook(DivinerLiveBook $book) {
94
public function getAtom() {
95
return $this->assertAttached($this->atom);
98
public function attachAtom(DivinerLiveAtom $atom) {
99
$this->atom = DivinerAtom::newFromDictionary($atom->getAtomData());
103
public function getURI() {
106
$this->getBook()->getName(),
110
if ($this->getContext()) {
111
$parts[] = $this->getContext();
114
$parts[] = $this->getName();
116
if ($this->getAtomIndex()) {
117
$parts[] = $this->getAtomIndex();
120
return '/'.implode('/', $parts).'/';
123
public function getSortKey() {
124
// Sort articles before other types of content. Then, sort atoms in a
125
// case-insensitive way.
128
($this->getType() == DivinerAtom::TYPE_ARTICLE ? '0' : '1'),
129
phutil_utf8_strtolower($this->getTitle()));
132
public function save() {
134
// NOTE: The identity hash is just a sanity check because the unique tuple
135
// on this table is way way too long to fit into a normal UNIQUE KEY. We
136
// don't use it directly, but its existence prevents duplicate records.
138
if (!$this->identityHash) {
139
$this->identityHash = PhabricatorHash::digestForIndex(
142
'bookPHID' => $this->getBookPHID(),
143
'context' => $this->getContext(),
144
'type' => $this->getType(),
145
'name' => $this->getName(),
146
'index' => $this->getAtomIndex(),
150
return parent::save();
153
public function getTitle() {
154
$title = parent::getTitle();
155
if (!strlen($title)) {
156
$title = $this->getName();
161
public function setTitle($value) {
162
$this->writeField('title', $value);
163
if (strlen($value)) {
164
$slug = DivinerAtomRef::normalizeTitleString($value);
165
$hash = PhabricatorHash::digestForIndex($slug);
166
$this->titleSlugHash = $hash;
168
$this->titleSlugHash = null;
173
public function attachExtends(array $extends) {
174
assert_instances_of($extends, 'DivinerLiveSymbol');
175
$this->extends = $extends;
179
public function getExtends() {
180
return $this->assertAttached($this->extends);
183
public function attachChildren(array $children) {
184
assert_instances_of($children, 'DivinerLiveSymbol');
185
$this->children = $children;
189
public function getChildren() {
190
return $this->assertAttached($this->children);
194
/* -( PhabricatorPolicyInterface )----------------------------------------- */
196
public function getCapabilities() {
197
return $this->getBook()->getCapabilities();
201
public function getPolicy($capability) {
202
return $this->getBook()->getPolicy($capability);
206
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
207
return $this->getBook()->hasAutomaticCapability($capability, $viewer);
210
public function describeAutomaticCapability($capability) {
211
return pht('Atoms inherit the policies of the books they are part of.');
215
/* -( Markup Interface )--------------------------------------------------- */
218
public function getMarkupFieldKey($field) {
219
return $this->getPHID().':'.$field.':'.$this->getGraphHash();
223
public function newMarkupEngine($field) {
224
return PhabricatorMarkupEngine::getEngine('diviner');
228
public function getMarkupText($field) {
229
return $this->getAtom()->getDocblockText();
233
public function didMarkupText(
236
PhutilMarkupEngine $engine) {
241
public function shouldUseMarkupCache($field) {