Beispiel #1
0
 public function addToSet(LiskDAO $dao)
 {
     if ($this->relatives) {
         throw new Exception(pht("Don't call %s after loading data!", __FUNCTION__ . '()'));
     }
     $this->daos[] = $dao;
     $dao->putInSet($this);
     return $this;
 }
Beispiel #2
0
 public function addToSet(LiskDAO $dao)
 {
     if ($this->relatives) {
         throw new Exception("Don't call addToSet() after loading data!");
     }
     $this->daos[] = $dao;
     $dao->putInSet($this);
     return $this;
 }
 protected function didRunTests()
 {
     $config = $this->getComputedConfiguration();
     if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
         LiskDAO::endIsolateAllLiskEffectsToCurrentProcess();
     }
 }
 public function save()
 {
     $conn_w = $this->establishConnection('w');
     $this->openTransaction();
     $next_version = LiskDAO::loadNextCounterValue($conn_w, PhabricatorTriggerDaemon::COUNTER_VERSION);
     $this->setTriggerVersion($next_version);
     $result = parent::save();
     $this->saveTransaction();
     return $this;
 }
 protected function didRunTests()
 {
     $config = $this->getComputedConfiguration();
     if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
         LiskDAO::endIsolateAllLiskEffectsToCurrentProcess();
     }
     try {
         unset($this->env);
     } catch (Exception $ex) {
         throw new Exception("Some test called PhabricatorEnv::beginScopedEnv(), but is still " . "holding a reference to the scoped environment!");
     }
 }
 public function testReadableTransactions()
 {
     // TODO: When we have semi-durable fixtures, use those instead. This is
     // extremely hacky.
     LiskDAO::endIsolateAllLiskEffectsToTransactions();
     try {
         $data = Filesystem::readRandomCharacters(32);
         $obj = new HarbormasterScratchTable();
         $obj->openTransaction();
         $obj->setData($data);
         $obj->save();
         $loaded = id(new HarbormasterScratchTable())->loadOneWhere('data = %s', $data);
         $obj->killTransaction();
         $this->assertEqual(true, $loaded !== null, "Reads inside transactions should have transaction visibility.");
         LiskDAO::beginIsolateAllLiskEffectsToTransactions();
     } catch (Exception $ex) {
         LiskDAO::beginIsolateAllLiskEffectsToTransactions();
         throw $ex;
     }
 }
 public function testCounters()
 {
     $obj = new HarbormasterObject();
     $conn_w = $obj->establishConnection('w');
     // Test that the counter bascially behaves as expected.
     $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'a'));
     $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'a'));
     $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_w, 'a'));
     // This first insert is primarily a test that the previous LAST_INSERT_ID()
     // value does not bleed into the creation of a new counter.
     $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'b'));
     $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'b'));
     // These inserts alternate database connections. Since unit tests are
     // transactional by default, we need to break out of them or we'll deadlock
     // since the transactions don't normally close until we exit the test.
     LiskDAO::endIsolateAllLiskEffectsToTransactions();
     try {
         $conn_1 = $obj->establishConnection('w', $force_new = true);
         $conn_2 = $obj->establishConnection('w', $force_new = true);
         $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_1, 'z'));
         $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_2, 'z'));
         $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_1, 'z'));
         $this->assertEqual(4, LiskDAO::loadNextCounterID($conn_2, 'z'));
         $this->assertEqual(5, LiskDAO::loadNextCounterID($conn_1, 'z'));
         LiskDAO::beginIsolateAllLiskEffectsToTransactions();
     } catch (Exception $ex) {
         LiskDAO::beginIsolateAllLiskEffectsToTransactions();
         throw $ex;
     }
 }
 private function loadCurrentCounter($counter_name)
 {
     return (int) LiskDAO::loadCurrentCounterValue(id(new PhabricatorWorkerTrigger())->establishConnection('w'), $counter_name);
 }
 public function getConfiguration()
 {
     return array(self::CONFIG_AUX_PHID => true) + parent::getConfiguration();
 }
 public function delete()
 {
     // TODO: We should make some reasonable effort to destroy related
     // infrastructure objects here, like edges, transactions, custom field
     // storage, flags, Phrequent tracking, tokens, etc. This doesn't need to
     // be exhaustive, but we can get a lot of it pretty easily.
     return parent::delete();
 }
Beispiel #11
0
 /**
  *  Build an empty object.
  *
  *  @return obj Empty object.
  */
 public function __construct()
 {
     $id_key = $this->getIDKey();
     if ($id_key) {
         $this->{$id_key} = null;
     }
     if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) {
         $this->resetDirtyFields();
         $this_class = get_class($this);
         if (empty(self::$__checkedClasses[$this_class])) {
             self::$__checkedClasses = true;
             if (PhabricatorEnv::getEnvConfig('lisk.check_property_methods')) {
                 $class = new ReflectionClass(get_class($this));
                 $methods = $class->getMethods();
                 $properties = $this->getProperties();
                 foreach ($methods as $method) {
                     $name = strtolower($method->getName());
                     if (!(strncmp($name, 'get', 3) && strncmp($name, 'set', 3))) {
                         $name = substr($name, 3);
                         $declaring_class_name = $method->getDeclaringClass()->getName();
                         if (isset($properties[$name]) && $declaring_class_name !== 'LiskDAO') {
                             throw new Exception("Cannot implement method {$method->getName()} in " . "{$declaring_class_name}.");
                         }
                     }
                 }
             }
         }
     }
 }
 protected function willWriteData(array &$data)
 {
     static $custom;
     if ($custom === null) {
         $custom = $this->getConfigOption(self::CONFIG_APPLICATION_SERIALIZERS);
     }
     if ($custom) {
         foreach ($custom as $key => $serializer) {
             $data[$key] = $serializer->willWriteValue($data[$key]);
         }
     }
     parent::willWriteData($data);
 }
 protected function willSleep($duration)
 {
     LiskDAO::closeInactiveConnections(60);
     return;
 }
 protected function willSleep($duration)
 {
     LiskDAO::closeAllConnections();
     return;
 }
Beispiel #15
0
 public static function closeAllConnections()
 {
     self::$connections = array();
 }
 public function __construct(LiskDAO $object)
 {
     $this->set = new LiskDAOSet();
     $this->object = $object->putInSet($this->set);
 }
 protected function didRunOneTest($test)
 {
     $config = $this->getComputedConfiguration();
     if ($config[self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES]) {
         LiskDAO::endIsolateAllLiskEffectsToTransactions();
     }
 }
Beispiel #18
0
 public function addToSet(LiskDAO $dao)
 {
     $this->daos[] = $dao;
     $dao->putInSet($this);
     return $this;
 }