Example #1
0
 protected function populateArray($rawItems)
 {
     $marshaler = new Marshaler();
     $items = array();
     foreach ($rawItems as $rawItem) {
         array_push($items, $this->createObject($marshaler->unmarshalItem($rawItem)));
     }
     return $items;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function write(array $record)
 {
     $filtered = $this->filterEmptyFields($record['formatted']);
     if ($this->version === 3) {
         $formatted = $this->marshaler->marshalItem($filtered);
     } else {
         $formatted = $this->client->formatAttributes($filtered);
     }
     $this->client->putItem(['TableName' => $this->table, 'Item' => $formatted]);
 }
 public function saved($model)
 {
     $attrs = $model->attributesToArray();
     // $this->attributeFilter->filter($attrs);
     try {
         $this->dynamoDbClient->putItem(['TableName' => $model->getDynamoDbTableName(), 'Item' => $this->marshaler->marshalItem($attrs)]);
     } catch (Exception $e) {
         Log::info($e);
     }
 }
Example #4
0
 public function storeReferralCode($code, $user_id, $timestamp)
 {
     $data = ['code' => $code, 'user_id' => $user_id, 'timestamp' => $timestamp];
     // TODO error handling
     $response = $this->client->GetItem(['TableName' => 'tr_referralcodes', 'Key' => ['code' => ['S' => $code]]]);
     if (!empty($response['Item'])) {
         throw new \Exception('Code already exists');
     }
     $this->client->PutItem(['TableName' => 'tr_referralcodes', 'Item' => $this->marshaler->marshalItem($data)]);
 }
Example #5
0
 /**
  * Fill the table with data
  */
 protected static function fillTable()
 {
     $data = ['key' => 'dev', 'settings' => self::getTestData()];
     $marshaler = new Marshaler();
     $item = $marshaler->marshalItem($data);
     self::$dynamodb->putItem(['TableName' => self::TABLE_NAME, 'Item' => $item]);
 }
Example #6
0
 protected function formatResults(\Aws\Result $result)
 {
     $items = new \ArrayIterator();
     if ($result['Count'] === 0) {
         return $items;
     }
     foreach ($result['Items'] as $item) {
         $items[] = $this->marshaler->unmarshalItem($item);
     }
     return $items;
 }
 public function unmarshalItem($item)
 {
     return $this->marshaler->unmarshalItem($item);
 }
    /**
     * Scans table for specific items we want to update
     * @return array
     */
    private function getJobsToFetchStatsFor()
    {
        $params = ['TableName' => $this->tableName, 'FilterExpression' => <<<EXPR
attribute_exists(sapiProjectId)
and attribute_not_exists(componentName)
and not begins_with(runId, :notBeginsWith)
and (
  attribute_not_exists(syrupJobId)
  or
  (attribute_exists(syrupJobId) and syrupJobId <> :syrupJobIdSyncAction)
)
and attribute_not_exists(hasSyrupJob)
EXPR
, 'Limit' => self::MAX_DOCUMENTS_TO_PROCESS, 'ExpressionAttributeValues' => [':notBeginsWith' => ['S' => 'p'], ':syrupJobIdSyncAction' => ['S' => '0']]];
        $ids = [];
        $marshaler = new Marshaler();
        do {
            if (isset($response) && isset($response['LastEvaluatedKey'])) {
                $params['ExclusiveStartKey'] = $response['LastEvaluatedKey'];
            }
            $response = $this->dynamoDbClient->scan($params);
            foreach ($response['Items'] as $item) {
                $ids[] = $marshaler->unmarshalValue($item['runId']);
            }
        } while (isset($response['LastEvaluatedKey']) && count($ids) <= 5000);
        return $ids;
    }
Example #9
0
 protected static function unformatValue($value)
 {
     $marshaler = new Marshaler();
     return $marshaler->unmarshalValue($value);
     // represented as arrays, though there is only ever one item present
     //        foreach ($value as $type => $actual) {
     //            switch ($type) {
     //                case Type::S:
     //                case Type::B:
     //                    return $actual;
     //                case Type::N:
     //                    if (intval($actual) == $actual) {
     //                        return intval($actual);
     //                    } else {
     //                        return floatval($actual);
     //                    }
     //                case Type::SS:
     //                case Type::BS:
     //                    return $actual;
     //                case Type::NS:
     //                    $out = [];
     //                    foreach ($actual as $item) {
     //                        if (intval($item) == $item) {
     //                            $out[] = intval($item);
     //                        } else {
     //                            $out[] = floatval($item);
     //                        }
     //                    }
     //
     //                    return $out;
     //            }
     //        }
     //
     //        return $value;
 }
Example #10
0
 public function deleteItem($tableName, array $key)
 {
     $marshaler = new Marshaler();
     $this->client->deleteItem(array('TableName' => $this->getRealEnvName($tableName), 'Key' => $marshaler->marshalItem($key)));
 }
 /**
  * Session destroy handler.
  * Do not call this method directly.
  * @param string $id session ID
  * @return boolean whether session is destroyed successfully
  */
 public function destroySession($id)
 {
     $marshaler = new Marshaler();
     $keys = [];
     $keys[$this->idColumn] = $id;
     try {
         $this->getClient()->deleteItem(['TableName' => $this->tableName, 'Key' => $marshaler->marshalItem($keys)]);
         return true;
     } catch (\Exception $ex) {
         Yii::error(__CLASS__ . '::' . __METHOD__ . ': ' . $ex->getMessage(), 'yii2dynamodbsession');
         return false;
     }
 }
Example #12
0
 /**
  * Gets raw stats for specified run
  * @param $runId
  * @return array|null|\stdClass
  */
 private function getDocumentForRunIdFromDynamoDb($runId)
 {
     $tableName = $this->container->getParameter('container_stats_dynamodb.table_name');
     $params = ['TableName' => $tableName, 'KeyConditionExpression' => 'runId = :runId', 'ExpressionAttributeValues' => [':runId' => ['S' => strval($runId)]], 'ConsistentRead' => true, 'Limit' => 1];
     /** @var DynamoDbClient $dynamoDbClient */
     $dynamoDbClient = $this->container->get('queue.dynamodb_client');
     $marshaler = new Marshaler();
     $response = $dynamoDbClient->query($params);
     if (!empty($response['Items'])) {
         return $marshaler->unmarshalItem(reset($response['Items']));
     } else {
         return null;
     }
 }
Example #13
0
 /**
  * Marshal data for json
  *
  * @param $data
  * @return array
  */
 public function marshallData($data)
 {
     $marshaler = new Marshaler();
     $data = $this->array_remove_empty($data);
     $json = $marshaler->marshalJson(SafeJson::encode($data));
     return $json;
 }
    /**
     * Gets raw stats for specified project and date range
     * @param $projectId
     * @param $dateFrom
     * @param $dateTo
     * @return array
     */
    private function getRawMetricsByProjectIdAndDateRange($projectId, $dateFrom, $dateTo)
    {
        $tableName = $this->container->getParameter('container_stats_dynamodb.table_name');
        $params = ['TableName' => $tableName, 'IndexName' => 'sapiProjectId-sapiCreatedTime-index', 'KeyConditionExpression' => <<<EXPR
sapiProjectId = :sapiProjectId
and (sapiCreatedTime between :dateFrom and :dateTo)
EXPR
, 'ExpressionAttributeValues' => [':sapiProjectId' => ['S' => strval($projectId)], ':dateFrom' => ['S' => date('c', strtotime($dateFrom . ' 00:00:00'))], ':dateTo' => ['S' => date('c', strtotime($dateTo . ' 23:59:59'))]], 'Limit' => 100];
        /** @var DynamoDbClient $dynamoDbClient */
        $dynamoDbClient = $this->container->get('queue.dynamodb_client');
        $documents = [];
        $marshaler = new Marshaler();
        do {
            if (isset($response) && isset($response['LastEvaluatedKey'])) {
                $params['ExclusiveStartKey'] = $response['LastEvaluatedKey'];
            }
            $response = $dynamoDbClient->query($params);
            foreach ($response['Items'] as $item) {
                $documents[] = $marshaler->unmarshalItem($item);
            }
        } while (isset($response['LastEvaluatedKey']));
        return $documents;
    }