Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / feed / storage / PhabricatorFeedStoryData.php
blob0513590023806ccfc1cc5129414e912b94afbb51
1 <?php
3 final class PhabricatorFeedStoryData
4 extends PhabricatorFeedDAO
5 implements PhabricatorDestructibleInterface {
7 protected $phid;
9 protected $storyType;
10 protected $storyData;
11 protected $authorPHID;
12 protected $chronologicalKey;
14 protected function getConfiguration() {
15 return array(
16 self::CONFIG_AUX_PHID => true,
17 self::CONFIG_SERIALIZATION => array(
18 'storyData' => self::SERIALIZATION_JSON,
20 self::CONFIG_COLUMN_SCHEMA => array(
21 'chronologicalKey' => 'uint64',
22 'storyType' => 'text64',
24 self::CONFIG_KEY_SCHEMA => array(
25 'key_phid' => null,
26 'phid' => array(
27 'columns' => array('phid'),
28 'unique' => true,
30 'chronologicalKey' => array(
31 'columns' => array('chronologicalKey'),
32 'unique' => true,
35 ) + parent::getConfiguration();
38 public function generatePHID() {
39 return PhabricatorPHID::generateNewPHID(
40 PhabricatorPHIDConstants::PHID_TYPE_STRY);
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'];
62 } else {
63 return $this->chronologicalKey >> 32;
67 public function getValue($key, $default = null) {
68 return idx($this->storyData, $key, $default);
72 /* -( PhabricatorDestructibleInterface )----------------------------------- */
75 public function destroyObjectPermanently(
76 PhabricatorDestructionEngine $engine) {
78 $this->openTransaction();
79 $conn = $this->establishConnection('w');
81 queryfx(
82 $conn,
83 'DELETE FROM %T WHERE chronologicalKey = %s',
84 id(new PhabricatorFeedStoryNotification())->getTableName(),
85 $this->getChronologicalKey());
87 queryfx(
88 $conn,
89 'DELETE FROM %T WHERE chronologicalKey = %s',
90 id(new PhabricatorFeedStoryReference())->getTableName(),
91 $this->getChronologicalKey());
93 $this->delete();
94 $this->saveTransaction();