public function it_will_roll_back_on_error_during_create(ConfigCollection $collection)
 {
     $uuid = Uuid::uuid4();
     $collection->getUuid()->willReturn($uuid);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(ConfigCollection::TYPE, $uuid)->willThrow(new \RuntimeException());
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringCreate($collection);
 }
Esempio n. 2
0
 public function it_can_rollBack_on_error_during_insert_user(User $user)
 {
     $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');
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(User::TYPE, $uuid);
     $exception = new \RuntimeException();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO users'))->willThrow($exception);
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow($exception)->duringCreate($user);
 }
Esempio n. 3
0
 public function create(User $user)
 {
     $this->pdo->beginTransaction();
     try {
         $this->objectRepository->create(User::TYPE, $user->getUuid());
         $this->executeSql('
             INSERT INTO users (user_uuid, email_address, password, display_name)
                  VALUES (:user_uuid, :email_address, :password, :display_name)
         ', ['user_uuid' => $user->getUuid()->getBytes(), 'email_address' => $user->getEmailAddress()->toString(), 'password' => $user->getPassword(), 'display_name' => $user->getDisplayName()]);
         $this->pdo->commit();
         $user->metaDataSetInsertTimestamp(new \DateTimeImmutable());
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
Esempio n. 4
0
 public function create(ConfigCollection $collection)
 {
     $this->pdo->beginTransaction();
     try {
         $this->objectRepository->create(ConfigCollection::TYPE, $collection->getUuid());
         $this->executeSql('
             INSERT INTO config_collections (config_collection_uuid, type, name)
                  VALUES (:config_collection_uuid, :type, :name)
         ', ['config_collection_uuid' => $collection->getUuid()->getBytes(), 'type' => $collection->getType()->getTypeName(), 'name' => $collection->getName()]);
         $this->createItems($collection);
         $this->pdo->commit();
         $collection->metaDataSetInsertTimestamp(new \DateTimeImmutable());
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
Esempio n. 5
0
 public function createFromUpload(File $file)
 {
     $this->pdo->beginTransaction();
     try {
         $this->objectRepository->create(File::TYPE, $file->getUuid());
         $this->uploadFile($file);
         $this->executeSql('
             INSERT INTO files (file_uuid, name, path, mime_type)
                  VALUES (:file_uuid, :name, :path, :mime_type)
         ', ['file_uuid' => $file->getUuid()->getBytes(), 'name' => $file->getName()->toString(), 'path' => $file->getPath()->toString(), 'mime_type' => $file->getMimeType()->toString()]);
         $file->metaDataSetInsertTimestamp(new \DateTimeImmutable());
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         if ($this->fileSystem->has($file->getUuid()->toString())) {
             $this->fileSystem->delete($file->getUuid()->toString());
         }
         throw $exception;
     }
 }
Esempio n. 6
0
 public function it_can_also_delete_after_exception(File $file)
 {
     $uuid = Uuid::uuid4();
     $file->getUuid()->willReturn($uuid);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(File::TYPE, $uuid)->willThrow(new \RuntimeException());
     $this->pdo->rollBack()->shouldBeCalled();
     $this->fileSystem->has($uuid->toString())->willReturn(true);
     $this->fileSystem->delete($uuid->toString())->willReturn(true);
     $this->shouldThrow(\RuntimeException::class)->duringCreateFromUpload($file);
 }
Esempio n. 7
0
 public function it_will_roll_back_when_adding_block_to_a_page_fails(Page $page, PageBlock $block)
 {
     $uuid = Uuid::uuid4();
     $page->getUuid()->willReturn($uuid);
     $blockUuid = Uuid::uuid4();
     $block->getUuid()->willReturn($blockUuid);
     $block->getPage()->willReturn($page);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(PageBlock::TYPE, $blockUuid)->willThrow(new \RuntimeException());
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringAddBlockToPage($block, $page);
 }
Esempio n. 8
0
 public function addBlockToPage(PageBlock $block, Page $page)
 {
     if (!$page->getUuid()->equals($block->getPage()->getUuid())) {
         throw new \OutOfBoundsException('PageBlock must belong to page to be added to it.');
     }
     $this->pdo->beginTransaction();
     try {
         $this->objectRepository->create(PageBlock::TYPE, $block->getUuid());
         $this->executeSql('
             INSERT INTO page_blocks (page_block_uuid, page_uuid, type, parameters, location, sort_order, status)
                  VALUES (:page_block_uuid, :page_uuid, :type, :parameters, :location, :sort_order, :status)
         ', ['page_block_uuid' => $block->getUuid()->getBytes(), 'page_uuid' => $block->getPage()->getUuid()->getBytes(), 'type' => $block->getType(), 'parameters' => json_encode($block->getParameters()), 'location' => $block->getLocation(), 'sort_order' => $block->getSortOrder(), 'status' => $block->getStatus()->toString()]);
         $this->objectRepository->update(Page::TYPE, $page->getUuid());
         $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
         $this->pdo->commit();
         $block->metaDataSetInsertTimestamp(new \DateTimeImmutable());
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }