public function processBackup(Form $form, $values) { $this->onBeforeManualBackup(); try { $removeBackupAtTheEnd = true; $results = $this->databaseBackup->backup('manual', $removeBackupAtTheEnd); $errorOccurred = false; /** @var ResultObject $result */ foreach ($results as $result) { if (!$result->hasNoErrors()) { foreach ($result->getAllErrors() as $error) { $this->presenter->flashMessage($error['message'], $error['type']); } $errorOccurred = true; } } if ($removeBackupAtTheEnd === false or $errorOccurred === false) { $this->presenter->flashMessage('Při zálohování nenastala žádná chyba.', 'success'); } } catch (\Exception $e) { $this->logger->addError(sprintf('Manual database backup failure. %s', $e)); $this->presenter->flashMessage('Databázi se nepodařilo zazálohovat. Zkontrolujte logy.', 'error'); } $this->redirect('this'); }
/** * @param FileUpload $file * @return Image * @throws NotImageUploadedException * @throws FileSizeException * @throws DBALException * @throws InvalidStateException */ public function processImage(FileUpload $file) { if (!$file->isImage()) { throw new NotImageUploadedException(); } if (\filesize($file->getTemporaryFile()) > Image::MAX_FILE_SIZE) { throw new FileSizeException(); } try { $this->em->beginTransaction(); $image = new Image($file); $this->em->persist($image)->flush(); $file->move($this->composeImageLocation($image)); $this->em->commit(); } catch (InvalidStateException $is) { $this->em->rollback(); $this->em->close(); $this->logger->addError('Error occurs while moving temp. image file to new location.'); throw $is; } catch (DBALException $e) { $this->em->rollback(); $this->em->close(); $this->logger->addError('Image error'); // todo err message throw $e; } return $image; }
/** * @param Page $page * @throws DBALException * @throws \Exception */ public function remove(Page $page) { try { $this->em->beginTransaction(); $this->removePageUrl($page); $this->em->remove($page); $this->em->flush(); $this->em->commit(); } catch (DBALException $e) { $this->closeEntityManager(); $this->logger->addError(sprintf('Article Removal Error: %s | article ID: %d | url ID: %s | exception: %s', date('Y-m-d H:i:s'), $page->getId(), isset($url) ? $url->getId() : 'NO URL', $e->getMessage())); throw $e; } }
/** * onCreate event handler * @param SeasonApplication $app */ public function onCreate(SeasonApplication $app) { $id = $this->defaultRoleName; try { if (!is_string($id)) { $role = $this->roleService->getRole($id); } else { $role = $this->roleService->getRoleName($id); } } catch (Exceptions\DataErrorException $ex) { $this->logger->addError("Application listener - onCreate - role load failed with - " . $ex->getMessage()); return; } $pos = new Position(); $pos->setGroup($app->getSportGroup()); $pos->setRole($role); $pos->setOwner($app->getOwner()); $pos->setPublishContact(false); $pos->setComment($this->defaultComment); try { $this->positionService->createPosition($pos); if ($this->deleteOldPosition) { $this->positionService->deletePositionsWithRole($pos->getOwner(), $pos->getRole()); } } catch (Exceptions\DataErrorException $ex) { $this->logger->addError("Application listener - onCreate - savingData failed with - " . $ex->getMessage()); return; } }
public function save(array $values) { $options = $this->prepareOptions($this->findOptions()); foreach ((array) $values as $key => $value) { $options[$key]->setValue($value == '' ? null : $value); $this->em->persist($options[$key]); } try { $this->em->flush(); $this->cache->remove(Option::getCacheKey()); $this->onSuccessOptionsSaving(); } catch (\Exception $e) { $this->em->rollback(); $this->em->close(); $this->logger->addError(sprintf('Save Options error: %s | error message: %s', date('Y-m-d H:i:s'), $e->getMessage())); throw $e; } }
/** * @throws TerminateException */ protected function restartJob(array $request, \Exception $exception = null, $message = null) : int { $this->logger->addError(sprintf('job requeue(%s) for order %d because of %s: %s', $request['retryCounter'], $request['orderId'], get_class($exception), $message ?: $exception->getMessage())); $this->append($this->em->getReference(Order::class, $request['orderId']), $request['retryCounter'] + 1, $request['options']); if (!$this->em->isOpen()) { sleep(self::DELAY_ON_RESTART); throw TerminateException::withResponse(self::MSG_REJECT); } return self::MSG_REJECT; }
/** * @param array $receivers * @param string $subject * @param string $messageText * @param string $attachedFile * @return ResultObject */ private function sendMail(array $receivers, $subject, $messageText, $attachedFile = null) { $result = new ResultObject(); $message = new Message(); $message->setFrom('Výčetkový systém <' . $this->systemEmail . '>')->setSubject($subject)->setBody($messageText); foreach ($receivers as $receiverEmail) { $message->addTo($receiverEmail); } if ($attachedFile !== null and file_exists($attachedFile)) { $message->addAttachment($attachedFile); } try { $this->mailer->send($message); } catch (SendException $s) { $this->logger->addError(sprintf('Backup file sending\'s failed. %s', $s)); $result->addError('Zálohu se nepodařilo odeslat', 'error'); } return $result; }
public function handleBackup($pass) { if ($this->backupPassword !== null) { if ($this->backupPassword != $pass) { $this->logger->addWarning('Unauthorized try to backup database (auto)'); return; } } if ($this->cache->load('databaseBackup') !== null) { $this->logger->addNotice('Another try to backup database (auto)'); return; } try { $this->databaseBackup->backup('auto', true); $this->cache->save('databaseBackup', 'done', [Cache::EXPIRE => '23 hours']); } catch (\Exception $e) { $this->logger->addError(sprintf('Database backup failure (auto). %s', $e)); } }
/** * Method for handling single onCreate event * @param SeasonApplication $app * @return void * @throws Exceptions\InvalidStateException */ public function onCreate(SeasonApplication $app) { $amount = null; $season = $app->getSeason(); $group = $app->getSportGroup(); try { $tax = $this->seasonTaxService->getSeasonTaxSG($season, $group); if ($tax !== null) { $amount = $tax->getMemberShip(); if (empty($amount) || $amount == 0) { return; } } else { throw new Exceptions\InvalidStateException("Season tax for season {$season} and group {$group} does not exist"); } } catch (Exceptions\DataErrorException $ex) { $this->logger->addError("Application listener - onCreate - getSeasonTaxSG failed with - " . $ex->getMessage()); return; } $subject = "Application for " . $app->getSportGroup()->getName() . " (" . $app->getSportGroup()->getSportType()->getName() . ") within " . $app->getSeason()->getLabel() . " season"; $payment = new Payment(); $payment->setOwner($app->getOwner()); $payment->setSeason($app->getSeason()); $payment->setSubject($subject); $payment->setAmount($amount); $payment->setDueDate($this->paymentService->getDefaultDueDate()); $payment->setOrderedDate(new DateTime()); $payment->setEditor($app->getEditor()); $payment->setStatus(PaymentStatus::NOT_YET); $payment->setVs($this->paymentService->generateVs($payment)); $payment->setPublicNote(""); $payment->setProtectedNote(""); try { $this->paymentService->createPayment($payment); $app->setPayment($payment); $this->seasonApplicationService->updateSeasonApplication($app); } catch (Exceptions\DataErrorException $ex) { $this->logger->addError("Application listener - onCreate - savingData failed with - " . $ex->getMessage()); return; } }
/** * @param Url $url * @return Url * @throws UrlAlreadyExistsException * @throws \Exception */ public function save(Url $url) { try { $this->em->beginTransaction(); if ($url->getId() !== null) { $url = $this->update($url); } else { $url = $this->create($url); } $this->em->commit(); } catch (UrlAlreadyExistsException $uae) { $this->closeEntityManager(); $this->logger->addError(sprintf('Url path already exists: %s', $uae)); throw $uae; } catch (\Exception $e) { $this->closeEntityManager(); $this->logger->addError(sprintf('Url Entity saving failure: %s', $e)); throw $e; } return $url; }
private function send(Message $n) { $mailerType = $this->getDesiredMailerType(); $mailer = null; if ($mailerType == self::MAILER_TYPE_SEND) { $mailer = new SendmailMailer(); } else { $mailer = new SmtpMailer($this->getSmtpOptions()); } try { $mailer->send($n); } catch (Exceptions\InvalidStateException $ex) { $this->logger->addError($ex); } }
/** * @param $path * @return null|Url */ private function loadUrlEntity($path) { /** @var Url $urlEntity */ $urlEntity = $this->cache->load($path, function (&$dependencies) use($path) { /** @var Url $urlEntity */ $urlEntity = $this->em->createQuery('SELECT u, rt FROM ' . Url::class . ' u LEFT JOIN u.actualUrlToRedirect rt WHERE u.urlPath = :urlPath')->setParameter('urlPath', $path)->getOneOrNullResult(); if ($urlEntity === null) { $this->logger->addError(sprintf('Page not found. URL_PATH: %s', $path)); return null; } $dependencies = [Nette\Caching\Cache::TAGS => $urlEntity->getCacheKey()]; return $urlEntity; }); return $urlEntity; }
protected function logError($message, array $context = []) { $this->logger->addError($this->prefixMessage($message, "ERROR"), $context); }
/** * {@inheritdoc} * @return Boolean Whether the record has been processed */ public function addError($message, array $context = []) { return $this->parentLogger->addError($message, ['channel' => $this->name] + $context); }