private static function getNewEntity()
 {
     if (is_null(self::$curPartition) || self::$curPartition == count(self::$Partitions) - 1) {
         self::$curPartition = 0;
         self::$curRowKey = TableServiceFunctionalTestData::getNewKey();
     } else {
         self::$curPartition++;
     }
     $entity = new Entity();
     $entity->setPartitionKey(self::$Partitions[self::$curPartition]);
     $entity->setRowKey(self::$curRowKey);
     return $entity;
 }
 public static function setSettings($tenant, $settings)
 {
     $entity = new Entity();
     $entity->setPartitionKey($tenant);
     $entity->setRowKey("settings");
     foreach ($settings as $name => $value) {
         $entity->addProperty($name, null, $value);
     }
     try {
         self::$tableRestProxy->insertOrMergeEntity(self::$table, $entity);
     } catch (ServiceException $e) {
         $code = $e->getCode();
         $error_message = $e->getMessage();
         $app->error("Something went wrong when trying to save your configuration. Please try again later.");
     }
 }
Esempio n. 3
0
 /**
  * Store an Aggregation in DB
  *
  * @param \Agg\Entity\Aggregation $aggregation
  */
 public function storeAggregation($aggregation)
 {
     //Generate unique slug
     $slug = $this->getUniqueSlug($this->slugify($aggregation->getTitle()));
     $aggregation->setSlug($slug);
     $entity = new Entity();
     $entity->setPartitionKey("talk");
     $entity->setRowKey($slug);
     $entity->addProperty("slug", EdmType::STRING, $aggregation->getSlug());
     $entity->addProperty("title", EdmType::STRING, $aggregation->getTitle());
     $entity->addProperty("talks", EdmType::STRING, serialize($aggregation->getTalks()));
     $entity->addProperty("speakerName", EdmType::STRING, $aggregation->getSpeakerName());
     $entity->addProperty("speakerUrl", EdmType::STRING, $aggregation->getSpeakerUrl());
     try {
         $this->tableProxy->insertEntity(self::TABLE_AGGREGATION, $entity);
     } catch (ServiceException $e) {
         $code = $e->getCode();
         $error_message = $e->getMessage();
         echo $code . ": " . $error_message . "<br />";
     }
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::deleteEntity
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  */
 public function testDeleteEntityTroublesomeRowKey()
 {
     // TODO: Fails because of https://github.com/WindowsAzure/azure-sdk-for-php/issues/180
     // The service does not allow the following common characters in keys:
     // 35 '#'
     // 47 '/'
     // 63 '?'
     // 92 '\'
     // In addition, the following values are not allowed, as they make the URL bad:
     // 0-31, 127-159
     // That still leaves several options for making troublesome keys
     // spaces
     // single quotes
     // Unicode
     // These need to be properly encoded when passed on the URL, else there will be trouble
     $table = TableServiceFunctionalTestData::$TEST_TABLE_NAMES[0];
     $e = new Entity();
     $e->setRowKey('row\'Key\'');
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $e = new Entity();
     $e->setRowKey('row Key');
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $e = new Entity();
     $e->setRowKey('row ' . TableServiceFunctionalTestData::getUnicodeString());
     $e->setPartitionKey('niceKey');
     $this->restProxy->insertEntity($table, $e);
     $this->restProxy->deleteEntity($table, $e->getPartitionKey(), $e->getRowKey());
     $qopts = new QueryEntitiesOptions();
     $qopts->setFilter(Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant($e->getRowKey(), EdmType::STRING)));
     $queryres = $this->restProxy->queryEntities($table, $qopts);
     $this->assertEquals(0, count($queryres->getEntities()), 'entities returned');
     $this->clearTable($table);
 }
//rowkey를 위해 guid 생성
function getGUID()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((double) microtime() * 10000);
        //optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);
        // "-"
        $uuid = chr(123) . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12) . chr(125);
        // "}"
        return $uuid;
    }
}
$dwguid = getGUID();
//guid 처리
$entity = new Entity();
$entity->setPartitionKey("KCD");
$entity->setRowKey($dwguid);
$entity->addProperty("Description", null, "질문을 하시면 선물이!!!");
$entity->addProperty("DueDate", EdmType::DATETIME, new DateTime("2016-01-23T08:15:00-08:00"));
$entity->addProperty("Location", EdmType::STRING, "광화문");
try {
    $tableRestProxy->insertEntity("phptable", $entity);
    //테이블명
} catch (ServiceException $e) {
    $code = $e->getCode();
    $error_message = $e->getMessage();
}
//rowkey를 위해 guid 생성
function getGUID()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((double) microtime() * 10000);
        //optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);
        // "-"
        $uuid = chr(123) . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12) . chr(125);
        // "}"
        return $uuid;
    }
}
$dwguid = getGUID();
//guid 처리
$entity = new Entity();
$entity->setPartitionKey("XECON");
$entity->setRowKey($dwguid);
$entity->addProperty("Description", null, "경품을 원해");
$entity->addProperty("DueDate", EdmType::DATETIME, new DateTime("2015-11-14T08:15:00-08:00"));
$entity->addProperty("Location", EdmType::STRING, "누리꿈스퀘어");
try {
    $tableRestProxy->insertEntity("xecondev01", $entity);
    //테이블명
} catch (ServiceException $e) {
    $code = $e->getCode();
    $error_message = $e->getMessage();
}
Esempio n. 7
0
 /**
  * Callback function for session handler. It's invoked while the session data is being written.
  *
  * @param $sessionId The session ID.
  * @param $sessionData The data to be written in session.
  *
  * @return boolean If the write operation success.
  */
 public function write($sessionId, $sessionData)
 {
     // serialize and encode the session data.
     $serializedData = base64_encode(serialize($sessionData));
     try {
         // try to retrive the stored session entity and update it.
         $result = $this->_tableRestProxy->getEntity($this->_sessionContainer, $this->_sessionContainerPartition, $sessionId);
         $entity = $result->getEntity();
         // update data and expiry time
         $entity->setPropertyValue('data', $serializedData);
         $entity->setPropertyValue('expires', time());
         // update entity
         $this->_tableRestProxy->updateEntity($this->_sessionContainer, $entity);
     } catch (ServiceException $e) {
         // otherwise, create a new session entity to store the data.
         $entity = new Entity();
         // set partition key and use session id as the row key.
         $entity->setPartitionKey($this->_sessionContainerPartition);
         $entity->setRowKey($sessionId);
         // set data and expiry time
         $entity->addProperty('data', EdmType::STRING, $serializedData);
         $entity->addProperty('expires', EdmType::INT32, time());
         // insert the entity
         $this->_tableRestProxy->insertEntity($this->_sessionContainer, $entity);
     }
     return TRUE;
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  * @covers WindowsAzure\Table\TableRestProxy::queryEntities
  */
 public function testInsertEntityString()
 {
     foreach (TableServiceFunctionalTestData::getInterestingGoodStrings() as $o) {
         $ent = new Entity();
         $ent->setPartitionKey(TableServiceFunctionalTestData::getNewKey());
         $ent->setRowKey(TableServiceFunctionalTestData::getNewKey());
         $ent->addProperty('STRING', EdmType::STRING, $o);
         $this->insertEntityWorker($ent, true, null, $o);
     }
 }
 /**
  * Create entity object with key and data values.
  *
  * @param array $key
  * @param array $data
  * @return \WindowsAzure\Table\Model\Entity
  */
 private function createEntity(array $key, array $data)
 {
     list($partitonKey, $rowKey) = array_values($key);
     $entity = new Entity();
     $entity->setPartitionKey((string) $partitonKey);
     $entity->setRowKey((string) $rowKey);
     foreach ($data as $variable => $value) {
         $type = $this->getPropertyType($value);
         $entity->addProperty($variable, $type, $value);
     }
     return $entity;
 }
 static function getSimpleEntities($count)
 {
     $ret = array();
     $e = new Entity();
     $e->setPartitionKey('singlePartition');
     $e->setRowKey(self::getNewKey());
     $e->addProperty('INT32', EdmType::INT32, 23);
     array_push($ret, $e);
     $booleans = self::getInterestingGoodBooleans();
     $dates = self::getInterestingGoodDates();
     $doubles = self::getInterestingGoodDoubles();
     $guids = self::getInterestingGoodGuids();
     $ints = self::getInterestingGoodInts();
     $longs = self::getInterestingGoodLongs();
     $binaries = self::getInterestingGoodBinaries();
     $strings = self::getInterestingGoodStrings();
     // The random here is not to generate random values, but to
     // get a good mix of values in the table entities.
     mt_srand(123);
     for ($i = 0; $i < $count - 1; $i++) {
         $e = new Entity();
         $e->setPartitionKey('singlePartition');
         $e->setRowKey(self::getNewKey());
         self::addProperty($e, 'BINARY', EdmType::BINARY, $binaries);
         self::addProperty($e, 'BOOLEAN', EdmType::BOOLEAN, $booleans);
         self::addProperty($e, 'DATETIME', EdmType::DATETIME, $dates);
         self::addProperty($e, 'DOUBLE', EdmType::DOUBLE, $doubles);
         self::addProperty($e, 'GUID', EdmType::GUID, $guids);
         self::addProperty($e, 'INT32', EdmType::INT32, $ints);
         self::addProperty($e, 'INT64', EdmType::INT64, $longs);
         self::addProperty($e, 'STRING', EdmType::STRING, $strings);
         array_push($ret, $e);
     }
     return $ret;
 }
 public function testGc()
 {
     $client = $this->getMockClient();
     $client->shouldReceive('queryEntities')->andThrow(new ServiceException('404'));
     $sessionHandler = new SessionHandler($client);
     $this->assertFalse($sessionHandler->gc(0));
     $client = $this->getMockClient();
     $queryEntitiesResult = new QueryEntitiesResult();
     $entity = new Entity();
     $entity->setRowKey('id');
     $entity->addProperty('data', null, base64_encode('data'));
     $queryEntitiesResult->setEntities(array($entity));
     $client->shouldReceive('queryEntities')->andReturn($queryEntitiesResult);
     $client->shouldReceive('deleteEntity');
     $sessionHandler = new SessionHandler($client);
     $this->assertTrue($sessionHandler->gc(0));
 }
Esempio n. 12
0
 /**
  * @param null|Entity  $entity
  * @param string|array $include List of keys to include in the output record
  * @param array        $record
  *
  * @return array
  */
 protected static function parseEntityToRecord($entity, $include = ApiOptions::FIELDS_ALL, $record = [])
 {
     if (!empty($entity)) {
         if (empty($include)) {
             $record[static::PARTITION_KEY] = $entity->getPartitionKey();
             $record[static::ROW_KEY] = $entity->getRowKey();
         } elseif (ApiOptions::FIELDS_ALL == $include) {
             // return all properties
             /** @var Property[] $properties */
             $properties = $entity->getProperties();
             foreach ($properties as $key => $property) {
                 $record[$key] = $property->getValue();
             }
         } else {
             if (!is_array($include)) {
                 $include = array_map('trim', explode(',', trim($include, ',')));
             }
             foreach ($include as $key) {
                 $record[$key] = $entity->getPropertyValue($key);
             }
         }
     }
     return $record;
 }
 /**
  * @covers WindowsAzure\Table\Models\Entity::isValid
  */
 public function testIsValidWithEmptyPartitionKey()
 {
     // Setup
     $entity = new Entity();
     $entity->addProperty('name', EdmType::STRING, 'string');
     // Assert
     $actual = $entity->isValid();
     // Assert
     $this->assertFalse($actual);
 }
 /**
  * Parses an entity entry from given SimpleXML object.
  * 
  * @param \SimpleXML $result The SimpleXML object representing the entity.
  * 
  * @return \WindowsAzure\Table\Models\Entity
  */
 private function _parseOneEntity($result)
 {
     $prefix = $this->_dataServicesMetadataPrefix;
     $prop = $result->content->xpath(".//{$prefix}:properties");
     $prop = $prop[0]->children($this->_dataServicesNamespaceName);
     $entity = new Entity();
     // Set ETag
     $etag = $result->attributes($this->_dataServicesMetadataNamespaceName);
     $etag = $etag[Resources::ETAG];
     $entity->setETag((string) $etag);
     foreach ($prop as $key => $value) {
         $attributes = $value->attributes($this->_dataServicesMetadataNamespaceName);
         $type = $attributes['type'];
         $isnull = $attributes['null'];
         $value = EdmType::unserializeQueryValue((string) $type, $value);
         $entity->addProperty((string) $key, is_null($type) ? null : (string) $type, $isnull ? null : $value);
     }
     return $entity;
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::batch
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  * @covers WindowsAzure\Table\TableRestProxy::updateEntity
  */
 public function testBatchNegativeWorks()
 {
     // Arrange
     $table = self::$testTable8;
     $partitionKey = '001';
     // Insert an entity the modify it outside of the batch
     $entity1 = new Entity();
     $entity1->setPartitionKey($partitionKey);
     $entity1->setRowKey('batchNegativeWorks1');
     $entity1->addProperty('test', EdmType::INT32, 1);
     $entity2 = new Entity();
     $entity2->setPartitionKey($partitionKey);
     $entity2->setRowKey('batchNegativeWorks2');
     $entity2->addProperty('test', EdmType::INT32, 2);
     $entity3 = new Entity();
     $entity3->setPartitionKey($partitionKey);
     $entity3->setRowKey('batchNegativeWorks3');
     $entity3->addProperty('test', EdmType::INT32, 3);
     $entity1 = $this->restProxy->insertEntity($table, $entity1)->getEntity();
     $entity2 = $this->restProxy->insertEntity($table, $entity2)->getEntity();
     $entity2->addProperty('test', EdmType::INT32, -2);
     $this->restProxy->updateEntity($table, $entity2);
     // Act
     $batchOperations = new BatchOperations();
     // The $entity1 still has the original etag from the first submit,
     // so this update should fail, because another update was already made.
     $entity1->addProperty('test', EdmType::INT32, 3);
     $batchOperations->addDeleteEntity($table, $entity1->getPartitionKey(), $entity1->getRowKey(), $entity1->getETag());
     $batchOperations->addUpdateEntity($table, $entity2);
     $batchOperations->addInsertEntity($table, $entity3);
     $result = $this->restProxy->batch($batchOperations);
     // Assert
     $this->assertNotNull($result, '$result');
     $entries = $result->getEntries();
     $this->assertEquals(1, count($entries), 'count($result->getEntries())');
     $this->assertNotNull($entries[0], 'First $result should not be null');
     $this->assertTrue($entries[0] instanceof BatchError, 'First $result type');
     $error = $entries[0];
     $this->assertEquals(412, $error->getError()->getCode(), 'First $result status code');
 }
//rowkey를 위해 guid 생성
function getGUID()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((double) microtime() * 10000);
        //optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);
        // "-"
        $uuid = chr(123) . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12) . chr(125);
        // "}"
        return $uuid;
    }
}
$dwguid = getGUID();
//guid 처리
$entity = new Entity();
$entity->setPartitionKey("VSTechUp");
$entity->setRowKey($dwguid);
$entity->addProperty("Description", null, "VS가 쵝오에요~");
$entity->addProperty("DueDate", EdmType::DATETIME, new DateTime("2015-11-14T08:15:00-08:00"));
$entity->addProperty("Location", EdmType::STRING, "광화문");
try {
    $tableRestProxy->insertEntity("phptable", $entity);
    //테이블명
} catch (ServiceException $e) {
    $code = $e->getCode();
    $error_message = $e->getMessage();
}
Esempio n. 17
0
 public static function getTestEntity($partitionKey, $rowKey)
 {
     $entity = new Entity();
     $entity->setPartitionKey($partitionKey);
     $entity->setRowKey($rowKey);
     $entity->addProperty('CustomerId', EdmType::INT32, 890);
     $entity->addProperty('CustomerName', null, 'John');
     $entity->addProperty('IsNew', EdmType::BOOLEAN, true);
     $entity->addProperty('JoinDate', EdmType::DATETIME, Utilities::convertToDateTime('2012-01-26T18:26:19.0000473Z'));
     return $entity;
 }
 static function cloneEntity($initialEnt)
 {
     $ret = new Entity();
     $initialProps = $initialEnt->getProperties();
     $retProps = array();
     foreach ($initialProps as $propName => $initialProp) {
         // Don't mess with the timestamp.
         if ($propName == 'Timestamp') {
             continue;
         }
         $retProp = new Property();
         $retProp->setEdmType($initialProp->getEdmType());
         $retProp->setValue($initialProp->getValue());
         $retProps[$propName] = $retProp;
     }
     $ret->setProperties($retProps);
     $ret->setETag($initialEnt->getETag());
     return $ret;
 }
Esempio n. 19
0
 /**
  * Inserts new entity to the table.
  * 
  * @param string                     $entries The entries values.
  * @param Models\TableServiceOptions $options The optional parameters.
  * 
  * @return none
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179433.aspx
  */
 public function insertTypelessEntity($entries, $options = null)
 {
     $entity = new Entity();
     $entity->setPartitionKey($this->_defaultParitionKey);
     $entity->setRowKey(uniqid());
     foreach ($entries as $columnName => $value) {
         $entity->addProperty($columnName, null, $value);
     }
     $this->_proxy->insertEntity($this->_name, $entity, $options);
 }
 /**
  * Create or update a session by ID.
  *
  * @param string $sessionId
  * @param string $sessionData
  */
 public function write($sessionId, $sessionData)
 {
     $entity = new Entity();
     $entity->setPartitionKey($this->partitionKey);
     $entity->setRowKey($sessionId);
     $entity->addProperty('last_accessed', EdmType::INT32, time());
     $entity->addProperty('data', EdmType::STRING, base64_encode($sessionData));
     try {
         $this->client->insertOrReplaceEntity($this->table, $entity);
     } catch (Exception $e) {
         return;
     }
 }