Exemplo n.º 1
0
                    $delta->setChanges([$record]);
                    //@see https://tech.yandex.ru/datasync/http/doc/tasks/create-changes-docpage/
                    $dataSync->saveDelta($delta->toArray(), $database->getRevision());
                    //Получение "свежей" информации о БД
                    $database = $dataSync->getDatabase($databaseId);
                }
            }
        }
        //Получение снапшота базы данных
        //@see https://tech.yandex.ru/datasync/http/doc/tasks/get-snapshot-docpage/
        $snapshotResponse = $dataSync->getDatabaseSnapshot($database->getDatabaseId());
        $collections = [];
        /** @var Record $record */
        foreach ($snapshotResponse->getRecords()->getItems() as $record) {
            //$record - запись в Коллекции
            $collections[$record->getCollectionId()][$record->getRecordId()] = [];
            foreach ($record->getFields()->getAll() as $field) {
                //$field - поле в Записи
                $collections[$record->getCollectionId()][$record->getRecordId()][$field->getFieldId()] = $field->getValue()->getValue();
            }
        }
    } catch (ForbiddenException $ex) {
        $errorMessage = $ex->getMessage();
        $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . "/../OAuth/" . '">авторизироваться</a> и повторить.</p>';
    } catch (Exception $ex) {
        $errorMessage = $ex->getMessage();
    }
}
?>
<!doctype html>
<html lang="en-US">
Exemplo n.º 2
0
 function testFillDatabaseRecord()
 {
     $fixture = array('change_type' => 'insert', 'collection_id' => 'my_schedule', 'record_id' => 'monday', 'changes' => array(array('change_type' => 'set', 'field_id' => 'work', 'value' => array('string' => 'from 11am to 7pm', 'type' => 'string'))));
     $record = new Record($fixture);
     $this->assertEquals($fixture['change_type'], $record->getChangeType());
     $this->assertEquals($fixture['collection_id'], $record->getCollectionId());
     $this->assertEquals($fixture['record_id'], $record->getRecordId());
     $this->assertEquals($fixture['changes'][0]['change_type'], $record->getChanges()->getAll()[0]->getChangeType());
     $this->assertEquals($fixture['changes'][0]['field_id'], $record->getChanges()->getAll()[0]->getFieldId());
     $this->assertEquals($fixture['changes'][0]['value']['type'], $record->getChanges()->getAll()[0]->getValue()->getType());
     $this->assertEquals($fixture['changes'][0]['value'][$fixture['changes'][0]['value']['type']], $record->getChanges()->getAll()[0]->getValue()->getValue());
     $changedFiled = new RecordField();
     $changedFiled->setChangeType($fixture['changes'][0]['change_type'])->setFieldId($fixture['changes'][0]['field_id'])->setValue(new RecordFieldValue($fixture['changes'][0]['value']));
     $record2 = new Record();
     $record2->setChangeType($fixture['change_type'])->setCollectionId($fixture['collection_id'])->setChanges([$changedFiled])->setRecordId($fixture['record_id']);
     $this->assertTrue($record->toArray() === $record2->toArray(), 'Is Equals records');
     $record2->setFields($fixture['changes']);
     $this->assertTrue($record2->getFields() instanceof RecordFields, 'Is RecordFields');
     $this->assertTrue($record2->getChanges() instanceof RecordFields, 'Is RecordFields');
     $field = new RecordFields();
     $field->add($fixture['changes'][0]);
     $record3 = new Record();
     $record3->setChangeType($fixture['change_type'])->setCollectionId($fixture['collection_id'])->setChanges($field)->setRecordId($fixture['record_id'])->setFields($field);
     $this->assertTrue($record2->toArray() === $record3->toArray(), 'Is Equals records');
 }