/** * {@inheritdoc} */ protected function write(array $record) { $filtered = json_decode($record['formatted'], true); $result = $this->flatten($filtered); $entity = new Entity(); $entity->setPartitionKey($result['message'] . '-' . $_SERVER['SERVER_NAME']); $entity->setRowKey(strval(PHP_INT_MAX - (int) (microtime(true) * 10000))); foreach ($result as $k => $v) { $entity->addProperty(strval($k), null, strval($v)); } $this->client->insertOrReplaceEntity($this->table, $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."); } }
function batchInsertEntitiesSample($tableClient) { $batchOp = new BatchOperations(); for ($i = 2; $i < 10; ++$i) { $entity = new Entity(); $entity->setPartitionKey("pk"); $entity->setRowKey('' . $i); $entity->addProperty("PropertyName", EdmType::STRING, "Sample" . $i); $batchOp->addInsertEntity("mytable", $entity); } try { $tableClient->batch($batchOp); } catch (ServiceException $e) { $code = $e->getCode(); $error_message = $e->getMessage(); echo $code . ": " . $error_message . PHP_EOL; } }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity */ public function testInsertStringWithAllAsciiCharacters() { $table = TableServiceFunctionalTestData::$testTableNames[0]; $e = new Entity(); $e->setPartitionKey('foo'); $e->setRowKey(TableServiceFunctionalTestData::getNewKey()); // ASCII code points in the following ranges are valid in XML 1.0 documents // - 0x09, 0x0A, 0x0D, 0x20-0x7F // Note: 0x0D gets mapped to 0x0A by the server. $k = ''; for ($b = 0x20; $b < 0x30; $b++) { $k .= chr($b); } $k .= chr(0x9); for ($b = 0x30; $b < 0x40; $b++) { $k .= chr($b); } $k .= chr(0xa); for ($b = 0x40; $b < 0x50; $b++) { $k .= chr($b); } $k .= chr(0xa); for ($b = 0x50; $b < 0x80; $b++) { $k .= chr($b); } $e->addProperty('foo', EdmType::STRING, $k); $ret = $this->restProxy->insertEntity($table, $e); $this->assertNotNull($ret, '$ret'); $this->assertNotNull($ret->getEntity(), '$ret->getEntity'); $l = $ret->getEntity()->getPropertyValue('foo'); $this->assertEquals($k, $l, '$ret->getEntity()->getPropertyValue(\'foo\')'); $this->clearTable($table); }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::batch * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity * @covers MicrosoftAzure\Storage\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'); }
/** * @covers MicrosoftAzure\Storage\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 \MicrosoftAzure\Storage\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) ? EdmType::STRING : (string) $type, $isnull ? null : $value); } return $entity; }
/** * 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); }
public static function getExpectedTestEntity($partitionKey, $rowKey) { $entity = new Entity(); $entity->addProperty('PartitionKey', EdmType::STRING, $partitionKey); $entity->addProperty('RowKey', EdmType::STRING, $rowKey); $entity->addProperty('CustomerId', EdmType::INT32, 890); $entity->addProperty('CustomerName', EdmType::STRING, 'John'); $entity->addProperty('IsNew', EdmType::BOOLEAN, true); $entity->addProperty('JoinDate', EdmType::DATETIME, Utilities::convertToDateTime('2012-01-26T18:26:19.0000473Z')); return $entity; }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertEntity * @covers MicrosoftAzure\Storage\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); } }
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; }