Esempio n. 1
0
 /**
  * @param User $user
  * @param Invitation $invitation
  * @return void
  * @throws Runtime\DuplicateUsernameException
  * @throws Runtime\DuplicateEmailException
  * @throws Runtime\InvitationNotFoundException
  * @throws Runtime\InvitationExpiredException
  * @throws Runtime\InvitationTokenMatchException
  * @throws \DibiException
  */
 public function registerNewUser(User $user, Invitation $invitation)
 {
     if (!$user->isDetached()) {
         throw new InvalidArgumentException('Only detached instances of Entity ' . User::class . ' can pass.');
     }
     $this->checkInvitation($user->email, $invitation->token);
     try {
         $this->transaction->begin();
         $this->userRepository->persist($user);
         $this->removeInvitation($invitation);
         $this->transaction->commit();
     } catch (\DibiException $e) {
         if ($e->getCode() == 1062) {
             try {
                 $this->userRepository->checkUsername($user->username);
             } catch (Runtime\UserAlreadyExistsException $usernameException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateUsernameException();
             }
             try {
                 $this->userRepository->checkEmail($user->email);
             } catch (Runtime\UserAlreadyExistsException $emailException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateEmailException();
             }
         }
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
Esempio n. 2
0
 /**
  * @param ListingItem $listingItem
  * @return ListingItem
  * @throws ListingItemDayAlreadyExistsException
  * @throws \DibiException
  */
 public function saveListingItem(ListingItem $listingItem)
 {
     try {
         $this->transaction->begin();
         $this->listingItemRepository->persist($listingItem);
         $this->localityRepository->saveLocalityToUserList($listingItem->locality, $listingItem->listing->getRowData()['userID']);
         $this->transaction->commit();
         return $listingItem;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         if ($e->getCode() == 1062) {
             throw new ListingItemDayAlreadyExistsException();
         }
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
Esempio n. 3
0
 public static function begin($userId)
 {
     $trans = parent::begin();
     $dao = new BaseDao("CertifierTransactionAtom");
     $tr = $dao->getPattern();
     $tr->userFid = $userId;
     //var_dump($trans->getId());
     $tr->transFid = $trans->getId();
     //var_dump($tr);
     $tr->insert();
     return $trans;
 }
Esempio n. 4
0
 /**
  * @param array $messages Key => recipientID, Value = Message entity or array of messages
  * @throws InvalidArgumentException
  * @throws \DibiException
  * @return array
  */
 public function sendMessages(array $messages)
 {
     $ex = new InvalidArgumentException('Only non-persisted instances of ' . Message::class . ' can pas.');
     $msgs = [];
     foreach ($messages as $recipientID => $recipientMessages) {
         Validators::assert($recipientID, 'numericint');
         if (is_array($recipientMessages)) {
             foreach ($recipientMessages as $message) {
                 if (!($message instanceof Message and $message->isDetached())) {
                     throw $ex;
                 }
                 $msgs[] = $message;
             }
         } else {
             // recipientMessages contains only one message
             if (!($recipientMessages instanceof Message and $recipientMessages->isDetached())) {
                 throw $ex;
             }
             $msgs[] = $recipientMessages;
         }
     }
     try {
         $this->transaction->begin();
         $this->messageRepository->saveMessages($msgs);
         unset($msgs);
         $usersMessages = [];
         foreach ($messages as $recipientID => $recipientMessages) {
             if (is_array($recipientMessages)) {
                 foreach ($recipientMessages as $message) {
                     $recipientMessage = new UserMessage($message, $recipientID);
                     $usersMessages[] = $recipientMessage;
                 }
             } else {
                 $recipientMessage = new UserMessage($recipientMessages, $recipientID);
                 $usersMessages[] = $recipientMessage;
             }
         }
         $this->userMessageRepository->sendMessagesToRecipients($usersMessages);
         $this->transaction->commit();
         return $usersMessages;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
Esempio n. 5
0
 public function action_update(Params $param)
 {
     $this->content->bind('form', $torn);
     $project = Jelly::select('project')->link($param->id)->load();
     if (!$project->loaded()) {
         throw new Error404_Exception();
     }
     $torn = new Torn($project);
     if ($torn->check()) {
         try {
             Transaction::begin();
             $project->set($_FILES + $_POST);
             $project->save();
             Transaction::commit();
             $this->request->redirect(Route::get('protected')->uri(array('controller' => 'project')));
         } catch (Validate_Exception $e) {
             Transaction::rollback();
             $torn->catch_errors($e);
         }
     }
 }
Esempio n. 6
0
 /**
  * @param Listing $baseListing
  * @param Listing $listingToMerge
  * @param array $selectedCollisionItems
  * @param \App\Model\Entities\User|int|null $user
  * @return Listing
  * @throws NoCollisionListingItemSelectedException
  * @throws \DibiException
  */
 public function mergeListings(Listing $baseListing, Listing $listingToMerge, array $selectedCollisionItems = [], $user = null)
 {
     $this->checkListingValidity($baseListing);
     $this->checkListingValidity($listingToMerge);
     if (!$this->haveListingsSamePeriod($baseListing, $listingToMerge)) {
         throw new InvalidArgumentException('Given Listings must have same Period(Year and Month).');
     }
     $userID = $this->getIdOfSignedInUserOnNull($user);
     $items = $this->itemService->getMergedListOfItems($baseListing, $listingToMerge, $selectedCollisionItems);
     try {
         $this->transaction->begin();
         $newListing = new Listing($baseListing->year, $baseListing->month, $userID);
         $this->saveListing($newListing);
         $this->itemService->setListingForGivenItems($items, $newListing);
         $this->listingItemRepository->saveListingItems($items);
         $this->transaction->commit();
         return $newListing;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
Esempio n. 7
0
 public static function begin()
 {
     $retval = new EditorTransaction();
     $retval->transObject = Transaction::begin();
     return $retval;
 }