Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/feed/storage/PhabricatorFeedStoryData.php
12241 views
1
<?php
2
3
final class PhabricatorFeedStoryData
4
extends PhabricatorFeedDAO
5
implements PhabricatorDestructibleInterface {
6
7
protected $phid;
8
9
protected $storyType;
10
protected $storyData;
11
protected $authorPHID;
12
protected $chronologicalKey;
13
14
protected function getConfiguration() {
15
return array(
16
self::CONFIG_AUX_PHID => true,
17
self::CONFIG_SERIALIZATION => array(
18
'storyData' => self::SERIALIZATION_JSON,
19
),
20
self::CONFIG_COLUMN_SCHEMA => array(
21
'chronologicalKey' => 'uint64',
22
'storyType' => 'text64',
23
),
24
self::CONFIG_KEY_SCHEMA => array(
25
'key_phid' => null,
26
'phid' => array(
27
'columns' => array('phid'),
28
'unique' => true,
29
),
30
'chronologicalKey' => array(
31
'columns' => array('chronologicalKey'),
32
'unique' => true,
33
),
34
),
35
) + parent::getConfiguration();
36
}
37
38
public function generatePHID() {
39
return PhabricatorPHID::generateNewPHID(
40
PhabricatorPHIDConstants::PHID_TYPE_STRY);
41
}
42
43
public function getEpoch() {
44
if (PHP_INT_SIZE < 8) {
45
// We're on a 32-bit machine.
46
if (function_exists('bcadd')) {
47
// Try to use the 'bc' extension.
48
return bcdiv($this->chronologicalKey, bcpow(2, 32));
49
} else {
50
// Do the math in MySQL. TODO: If we formalize a bc dependency, get
51
// rid of this.
52
// See: PhabricatorFeedStoryPublisher::generateChronologicalKey()
53
$conn_r = id($this->establishConnection('r'));
54
$result = queryfx_one(
55
$conn_r,
56
// Insert the chronologicalKey as a string since longs don't seem to
57
// be supported by qsprintf and ints get maxed on 32 bit machines.
58
'SELECT (%s >> 32) as N',
59
$this->chronologicalKey);
60
return $result['N'];
61
}
62
} else {
63
return $this->chronologicalKey >> 32;
64
}
65
}
66
67
public function getValue($key, $default = null) {
68
return idx($this->storyData, $key, $default);
69
}
70
71
72
/* -( PhabricatorDestructibleInterface )----------------------------------- */
73
74
75
public function destroyObjectPermanently(
76
PhabricatorDestructionEngine $engine) {
77
78
$this->openTransaction();
79
$conn = $this->establishConnection('w');
80
81
queryfx(
82
$conn,
83
'DELETE FROM %T WHERE chronologicalKey = %s',
84
id(new PhabricatorFeedStoryNotification())->getTableName(),
85
$this->getChronologicalKey());
86
87
queryfx(
88
$conn,
89
'DELETE FROM %T WHERE chronologicalKey = %s',
90
id(new PhabricatorFeedStoryReference())->getTableName(),
91
$this->getChronologicalKey());
92
93
$this->delete();
94
$this->saveTransaction();
95
}
96
97
}
98
99