/** * @test */ public function changeGuidTest() { $id = time(); $database = 'testdb'; $this->fixture->setId($id); $this->fixture->_setDb($database); $this->assertEquals($database . '-' . $id, $this->fixture->getGuid()); }
/** * Adds or updates the given model in the repository for the * given API path * @param Document $model * @param string $path The API path * @return void */ public function saveModelForPath($model, $path) { $documentDatabase = $this->getDatabaseNameFromPath($path); /** @var DocumentRepository $repository */ $repository = $this->getRepositoryForPath($path); $repository->setDatabase($documentDatabase); $model->_setDb($documentDatabase); if ($repository) { if ($model->_isNew()) { $repository->add($model); } else { $repository->update($model); } $this->persistAllChanges(); } }
/** * Merges two Documents * * @param Document $oldDocument * @param Document|array|\stdClass $newDocument * @throws \Cundd\Rest\Domain\Exception\NoDatabaseSelectedException if the converted Document has no database * @return Document */ protected function mergeDocuments($oldDocument, $newDocument) { $mergeKeys = array('uid', 'pid', 'id', 'db', Document::DATA_PROPERTY_NAME); foreach ($mergeKeys as $key) { if (isset($newDocument[$key]) && $newDocument[$key]) { $oldDocument[$key] = $newDocument[$key]; } } if (!$oldDocument->_getDb()) { $currentDatabase = $this->getDatabase(); if (!$currentDatabase) { throw new NoDatabaseSelectedException('The given object and the repository have no database set', 1389257938); } $oldDocument->_setDb($currentDatabase); } return $oldDocument; }