public function update(ConfigCollection $collection) { $this->pdo->beginTransaction(); try { $this->updateItems($collection); $this->objectRepository->update(ConfigCollection::TYPE, $collection->getUuid()); $collection->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function it_can_update_a_collection(ConfigCollection $collection, \PDOStatement $itemStatement1, \PDOStatement $itemStatement2) { $uuid = Uuid::uuid4(); $items = ['k1' => 'v1', 'k2' => 'v2']; $collection->getUuid()->willReturn($uuid); $collection->getItems()->willReturn($items); $collection->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->willReturn($collection); $this->pdo->beginTransaction()->shouldBeCalled(); $this->objectRepository->update(ConfigCollection::TYPE, $uuid)->shouldBeCalled(); $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE config_items'))->willReturn($itemStatement1, $itemStatement2, false); $itemStatement1->execute(['config_collection_uuid' => $uuid->getBytes(), 'name' => 'k1', 'value' => json_encode('v1')])->shouldBeCalled(); $itemStatement2->execute(['config_collection_uuid' => $uuid->getBytes(), 'name' => 'k2', 'value' => json_encode('v2')])->shouldBeCalled(); $this->pdo->commit()->shouldBeCalled(); $this->update($collection); }
public function it_can_update_a_user(User $user, \PDOStatement $statement) { $user->getUuid()->willReturn($uuid = Uuid::uuid4()); $user->getEmailAddress()->willReturn(EmailAddress::get($email = '*****@*****.**')); $user->getPassword()->willReturn($password = password_hash('no.jedi.please', PASSWORD_BCRYPT)); $user->getDisplayName()->willReturn($displayName = 'Nute Gunray'); $user->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled(); $this->pdo->beginTransaction()->shouldBeCalled(); $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE users'))->willReturn($statement); $statement->execute(['user_uuid' => $uuid->getBytes(), 'email_address' => $email, 'password' => $password, 'display_name' => $displayName])->shouldBeCalled(); $statement->rowCount()->willReturn(1); $this->objectRepository->update(User::TYPE, $uuid)->shouldBeCalled(); $this->pdo->commit()->shouldBeCalled(); $this->update($user); }
public function deleteBlockFromPage(PageBlock $block, Page $page) { if (!$page->getUuid()->equals($block->getPage()->getUuid())) { throw new \OutOfBoundsException('PageBlock must belong to page to be added to it.'); } // The database constraint should cascade the delete to the page $this->objectRepository->delete(PageBlock::TYPE, $block->getUuid()); $page->removeBlock($block); $this->objectRepository->update(Page::TYPE, $page->getUuid()); $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); $block->setStatus(PageStatusValue::get(PageStatusValue::DELETED)); }
public function update(User $user) { $this->pdo->beginTransaction(); try { $query = $this->executeSql(' UPDATE users SET email_address = :email_address, password = :password, display_name = :display_name WHERE user_uuid = :user_uuid ', ['user_uuid' => $user->getUuid()->getBytes(), 'email_address' => $user->getEmailAddress()->toString(), 'password' => $user->getPassword(), 'display_name' => $user->getDisplayName()]); // When at least one of the fields changes, the rowCount will be 1 and an update occurred if ($query->rowCount() === 1) { $this->objectRepository->update(User::TYPE, $user->getUuid()); $user->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); } $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function updateMetaData(File $file) { $this->pdo->beginTransaction(); try { $query = $this->executeSql(' UPDATE files SET name = :name, path = :path, mime_type = :mime_type WHERE file_uuid = :file_uuid ', ['file_uuid' => $file->getUuid()->getBytes(), 'name' => $file->getName()->toString(), 'path' => $file->getPath()->toString(), 'mime_type' => $file->getMimeType()->toString()]); // When at least one of the fields changes, the rowCount will be 1 and an update occurred if ($query->rowCount() === 1) { $this->objectRepository->update(File::TYPE, $file->getUuid()); $file->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); } $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function it_can_delete_a_block_from_a_page(Page $page, PageBlock $block) { $uuid = Uuid::uuid4(); $page->getUuid()->willReturn($uuid); $page->removeBlock($block)->shouldBeCalled(); $page->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->shouldBeCalled(); $blockUuid = Uuid::uuid4(); $block->getUuid()->willReturn($blockUuid); $block->getPage()->willReturn($page); $block->setStatus(PageStatusValue::get('deleted'))->shouldBeCalled(); $this->objectRepository->delete(PageBlock::TYPE, $blockUuid)->shouldBeCalled(); $this->objectRepository->update(Page::TYPE, $uuid)->shouldBeCalled(); $this->deleteBlockFromPage($block, $page); }
public function it_will_roll_back_after_failed_update_file_meta_data(File $file) { $uuid = Uuid::uuid4(); $name = FileNameValue::get('file.name'); $path = FilePathValue::get('/uploads'); $mime = MimeTypeValue::get('text/xml'); $file->getUuid()->willReturn($uuid); $file->getName()->willReturn($name); $file->setName($name)->willReturn($file); $file->getPath()->willReturn($path); $file->getMimeType()->willReturn($mime); $this->pdo->beginTransaction()->shouldBeCalled(); $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE files'))->willThrow(new \RuntimeException()); $this->objectRepository->update(File::TYPE, $uuid)->shouldNotBeCalled(); $this->pdo->rollBack()->shouldBeCalled(); $file->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->shouldNotBeCalled(); $this->shouldThrow(\RuntimeException::class)->duringUpdateMetaData($file); }