[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/feed/storage/ -> PhabricatorFeedStoryData.php (source)

   1  <?php
   2  
   3  final class PhabricatorFeedStoryData extends PhabricatorFeedDAO {
   4  
   5    protected $phid;
   6  
   7    protected $storyType;
   8    protected $storyData;
   9    protected $authorPHID;
  10    protected $chronologicalKey;
  11  
  12    public function getConfiguration() {
  13      return array(
  14        self::CONFIG_AUX_PHID       => true,
  15        self::CONFIG_SERIALIZATION  => array(
  16          'storyData'  => self::SERIALIZATION_JSON,
  17        ),
  18        self::CONFIG_COLUMN_SCHEMA => array(
  19          'chronologicalKey' => 'uint64',
  20          'storyType' => 'text64',
  21        ),
  22        self::CONFIG_KEY_SCHEMA => array(
  23          'key_phid' => null,
  24          'phid' => array(
  25            'columns' => array('phid'),
  26            'unique' => true,
  27          ),
  28          'chronologicalKey' => array(
  29            'columns' => array('chronologicalKey'),
  30            'unique' => true,
  31          ),
  32        ),
  33      ) + parent::getConfiguration();
  34    }
  35  
  36    public function generatePHID() {
  37      return PhabricatorPHID::generateNewPHID(
  38        PhabricatorPHIDConstants::PHID_TYPE_STRY);
  39    }
  40  
  41    public function getEpoch() {
  42      if (PHP_INT_SIZE < 8) {
  43        // We're on a 32-bit machine.
  44        if (function_exists('bcadd')) {
  45          // Try to use the 'bc' extension.
  46          return bcdiv($this->chronologicalKey, bcpow(2, 32));
  47        } else {
  48          // Do the math in MySQL. TODO: If we formalize a bc dependency, get
  49          // rid of this.
  50          // See: PhabricatorFeedStoryPublisher::generateChronologicalKey()
  51          $conn_r = id($this->establishConnection('r'));
  52          $result = queryfx_one(
  53            $conn_r,
  54            // Insert the chronologicalKey as a string since longs don't seem to
  55            // be supported by qsprintf and ints get maxed on 32 bit machines.
  56            'SELECT (%s >> 32) as N',
  57            $this->chronologicalKey);
  58          return $result['N'];
  59        }
  60      } else {
  61        return $this->chronologicalKey >> 32;
  62      }
  63    }
  64  
  65    public function getValue($key, $default = null) {
  66      return idx($this->storyData, $key, $default);
  67    }
  68  
  69  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1