Exemplo n.º 1
0
 private function getPropertyJson(string $id) : array
 {
     // TODO: handle id exception
     // https://groups.google.com/forum/#!topic/clean-code-discussion/GcQNqWG_fuo
     $id = new PropertyId($id);
     $propertyRow = $this->propertyStore->getPropertyRowByNumericPropertyId($id->getNumericId());
     if ($propertyRow === null) {
         throw new NoNullableReturnTypesException();
     }
     return json_decode($propertyRow->getPropertyJson(), true);
 }
 /**
  * @see PropertyInfoStore::removePropertyInfo
  *
  * @param PropertyId $propertyId
  *
  * @throws InvalidArgumentException
  * @return bool
  */
 public function removePropertyInfo(PropertyId $propertyId)
 {
     $id = $propertyId->getNumericId();
     if (array_key_exists($id, $this->propertyInfo)) {
         unset($this->propertyInfo[$id]);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 /**
  * @see Serializable::serialize
  *
  * @since 0.1
  *
  * @return string
  */
 public function serialize()
 {
     return serialize($this->propertyId->getNumericId());
 }
 /**
  * @see PropertyInfoStore::removePropertyInfo
  *
  * @param PropertyId $propertyId
  *
  * @throws DBError
  * @throws InvalidArgumentException
  * @return bool
  */
 public function removePropertyInfo(PropertyId $propertyId)
 {
     if ($this->isReadonly) {
         throw new DBError('Cannot write when in readonly mode');
     }
     $dbw = $this->getConnection(DB_MASTER);
     $dbw->delete($this->tableName, array('pi_property_id' => $propertyId->getNumericId()), __METHOD__);
     $c = $dbw->affectedRows();
     $this->releaseConnection($dbw);
     return $c > 0;
 }
 private function getNumericIdFromPropertyId(PropertyId $propertyId)
 {
     return $propertyId->getNumericId();
 }
 /**
  * @see PropertyInfoStore::removePropertyInfo
  *
  * @param PropertyId $propertyId
  *
  * @return bool
  */
 public function removePropertyInfo(PropertyId $propertyId)
 {
     $id = $propertyId->getNumericId();
     // if we don't know it, don't delete it.
     if (is_array($this->propertyInfo) && !array_key_exists($id, $this->propertyInfo)) {
         return false;
     }
     // update primary store
     $ok = $this->store->removePropertyInfo($propertyId);
     if (!$ok) {
         // nothing changed, nothing to do
         return false;
     }
     // NOTE: Even if we don't have the propertyInfo locally, we still need to
     //       fully load it to update memcached.
     // Get local cached version.
     // NOTE: this may be stale at this point, if it was already loaded
     $propertyInfo = $this->getAllPropertyInfo();
     // update local cache
     unset($propertyInfo[$id]);
     $this->propertyInfo = $propertyInfo;
     // update external cache
     wfDebugLog(__CLASS__, __FUNCTION__ . ': updating cache after removing property ' . $id);
     $this->cache->set($this->cacheKey, $propertyInfo, $this->cacheDuration);
     return true;
 }
Exemplo n.º 7
0
 public function testGetNumericId()
 {
     $id = new PropertyId('P1');
     $this->assertSame(1, $id->getNumericId());
 }