Beispiel #1
0
 protected function updateToVersion($version, Database $database, Tlog $logger)
 {
     if (file_exists(THELIA_ROOT . '/setup/update/' . $version . '.sql')) {
         $logger->debug(sprintf('inserting file %s', $version . '$sql'));
         $database->insertSql(null, array(THELIA_ROOT . '/setup/update/' . $version . '.sql'));
         $logger->debug(sprintf('end inserting file %s', $version . '$sql'));
     }
     ConfigQuery::write('thelia_version', $version);
 }
Beispiel #2
0
 /**
  * Returns the module-specific logger, initializing it if required.
  *
  * @return Tlog a Tlog instance
  */
 public function getLogger()
 {
     if ($this->log == null) {
         $this->log = Tlog::getNewInstance();
         $logFilePath = $this->getLogFilePath();
         $this->log->setPrefix("#LEVEL: #DATE #HOUR: ");
         $this->log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
         $this->log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, $logFilePath);
     }
     return $this->log;
 }
 public function createRuleAction()
 {
     if (null !== ($response = $this->checkAuth(array(), array('FreeShipping'), AccessManager::CREATE))) {
         return $response;
     }
     $ruleCreationForm = new FreeShippingRuleCreationForm($this->getRequest());
     $message = false;
     try {
         $form = $this->validateForm($ruleCreationForm);
         $event = $this->createEventInstance($form->getData());
         $this->areaId = $form->get('area')->getData();
         if (null === $this->getExistingObject()) {
             $this->dispatch(FreeShippingEvents::FREE_SHIPPING_RULE_CREATE, $event);
             return $this->generateSuccessRedirect($ruleCreationForm);
         } else {
             throw new \Exception("A rule with this area already exist");
         }
     } catch (FormValidationException $e) {
         $message = sprintf("Please check your input: %s", $e->getMessage());
     } catch (PropelException $e) {
         $message = $e->getMessage();
     } catch (\Exception $e) {
         $message = sprintf("Sorry, an error occured: %s", $e->getMessage() . " " . $e->getFile());
     }
     if ($message !== false) {
         \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during free shipping rule creation process : %s.", $message));
         $ruleCreationForm->setErrorMessage($message);
         $this->getParserContext()->addForm($ruleCreationForm)->setGeneralError($message);
     }
     // Redirect
     return $this->generateRedirectFromRoute('admin.module.configure', array(), array('module_code' => 'FreeShipping'));
 }
 protected function logAlertMessage($message, $failSafe = false)
 {
     Tlog::getInstance()->addAlert($message);
     if (!$failSafe && $this->debugEnabled) {
         throw new \InvalidArgumentException($message);
     }
 }
Beispiel #5
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $paidStatusId = OrderStatusQuery::create()->filterByCode(OrderStatus::CODE_PAID)->select('Id')->findOne();
     if ($order->hasVirtualProduct() && $event->getStatus() == $paidStatusId) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_virtualproduct')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'mail_virtualproduct'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Virtual product download message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Virtual product download message no contact email customer_id", $customer->getId());
         }
     }
 }
Beispiel #6
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $Predict = new Predict();
     if ($order->isSent() && $order->getDeliveryModuleId() == $Predict->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_predict')->findOne();
             if (false === $message) {
                 throw new \Exception(Translator::getInstance()->trans("Failed to load message '%mail_tpl_name'.", ["%mail_tpl_name" => "mail_predict"], Predict::MESSAGE_DOMAIN));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $this->parser->assign('package', $order->getDeliveryRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Predict shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Predict shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
 public function addItem()
 {
     $request = $this->getRequest();
     $cartAdd = $this->getAddCartForm($request);
     $message = null;
     try {
         $form = $this->validateForm($cartAdd);
         $cartEvent = $this->getCartEvent();
         $cartEvent->bindForm($form);
         $this->getDispatcher()->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
         $this->afterModifyCart();
         if ($this->getRequest()->isXmlHttpRequest()) {
             $this->changeViewForAjax();
         } else {
             if (null !== ($response = $this->generateSuccessRedirect($cartAdd))) {
                 return $response;
             }
         }
     } catch (PropelException $e) {
         Tlog::getInstance()->error(sprintf("Failed to add item to cart with message : %s", $e->getMessage()));
         $message = $this->getTranslator()->trans("Failed to add this article to your cart, please try again", [], Front::MESSAGE_DOMAIN);
     } catch (FormValidationException $e) {
         $message = $e->getMessage();
     }
     if ($message) {
         $cartAdd->setErrorMessage($message);
         $this->getParserContext()->addForm($cartAdd);
     }
 }
Beispiel #8
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_colissimo')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'order_confirmation'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $this->parser->assign('package', $order->getDeliveryRef());
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::getStoreName());
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
Beispiel #9
0
 public function delete(ModuleDeleteEvent $event)
 {
     if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) {
         $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             if (null === $module->getFullNamespace()) {
                 throw new \LogicException(Translator::getInstance()->trans('Cannot instanciante module "%name%": the namespace is null. Maybe the model is not loaded ?', array('%name%' => $module->getCode())));
             }
             try {
                 $instance = $module->createInstance();
                 $instance->setContainer($this->container);
                 $path = $module->getAbsoluteBaseDir();
                 $instance->destroy($con, $event->getDeleteData());
                 $fs = new Filesystem();
                 $fs->remove($path);
             } catch (\ReflectionException $ex) {
                 // Happens probably because the module directory has been deleted.
                 // Log a warning, and delete the database entry.
                 Tlog::getInstance()->addWarning(Translator::getInstance()->trans('Failed to create instance of module "%name%" when trying to delete module. Module directory has probably been deleted', array('%name%' => $module->getCode())));
             }
             $module->delete($con);
             $con->commit();
             $event->setModule($module);
             $this->cacheClear($event->getDispatcher());
         } catch (\Exception $e) {
             $con->rollBack();
             throw $e;
         }
     }
 }
Beispiel #10
0
 protected function log($level, $message)
 {
     if ($this->usePropel) {
         switch ($level) {
             case 'debug':
                 $this->logger->debug($message);
                 break;
             case 'info':
                 $this->logger->info($message);
                 break;
             case 'notice':
                 $this->logger->notice($message);
                 break;
             case 'warning':
                 $this->logger->warning($message);
                 break;
             case 'error':
                 $this->logger->error($message);
                 break;
             case 'critical':
                 $this->logger->critical($message);
                 break;
         }
     } else {
         $this->logs[] = [$level, $message];
     }
 }
 public function updateOrCreateLinkAction($id)
 {
     // Check current user authorization
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, DealerTeam::getModuleCode(), AccessManager::CREATE))) {
         return $response;
     }
     $retour = [];
     $code = 200;
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         $data = ['id' => $id];
         $tempOption = $this->getRequest()->request->get("option_id");
         $dafyDealer = [];
         foreach ($tempOption as $option) {
             $data["dealer_option_id"] = $option;
             $temp = $this->getService()->createFromArray($data);
             if ($temp) {
                 $dafyDealer[] = $temp->toArray();
             }
         }
         $con->commit();
         $retour["data"] = $dafyDealer;
     } catch (\Exception $e) {
         $con->rollBack();
         // Any other error
         Tlog::getInstance()->addError($e->getMessage());
         $code = $e->getCode();
         if ($code == 0) {
             $code = 500;
         }
         $retour["message"] = $e->getMessage();
     }
     return JsonResponse::create($retour, $code);
 }
Beispiel #12
0
 public function subscribeAction()
 {
     $errorMessage = false;
     $newsletterForm = new NewsletterForm($this->getRequest());
     try {
         $form = $this->validateForm($newsletterForm);
         $event = new NewsletterEvent($form->get('email')->getData(), $this->getRequest()->getSession()->getLang()->getLocale());
         if (null !== ($customer = $this->getSecurityContext()->getCustomerUser())) {
             $event->setFirstname($customer->getFirstname());
             $event->setLastname($customer->getLastname());
         } else {
             $event->setFirstname($form->get('firstname')->getData());
             $event->setLastname($form->get('lastname')->getData());
         }
         $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $errorMessage));
     }
     // If Ajax Request
     if ($this->getRequest()->isXmlHttpRequest()) {
         $response = new JsonResponse();
         if ($errorMessage) {
             $response = $response->setContent(array("success" => false, "message" => $errorMessage));
         } else {
             $response = $response->setContent(array("success" => true, "message" => $this->getTranslator()->trans("Thanks for signing up! We'll keep you posted whenever we have any new updates.")));
         }
         return $response;
     } else {
         $newsletterForm->setErrorMessage($errorMessage);
         $this->getParserContext()->addForm($newsletterForm)->setGeneralError($errorMessage);
     }
 }
 public function subscribeAction()
 {
     $errorMessage = false;
     $newsletterForm = $this->createForm(FrontForm::NEWSLETTER);
     try {
         $form = $this->validateForm($newsletterForm);
         $event = new NewsletterEvent($form->get('email')->getData(), $this->getRequest()->getSession()->getLang()->getLocale());
         /** @var Customer $customer */
         if (null !== ($customer = $this->getSecurityContext()->getCustomerUser())) {
             $event->setFirstname($customer->getFirstname())->setLastname($customer->getLastname());
         } else {
             $event->setFirstname($form->get('firstname')->getData())->setLastname($form->get('lastname')->getData());
         }
         $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
         // If a success URL is defined in the form, redirect to it, otherwise use the defaut view
         if ($newsletterForm->hasSuccessUrl() && !$this->getRequest()->isXmlHttpRequest()) {
             return $this->generateSuccessRedirect($newsletterForm);
         }
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $errorMessage));
         $newsletterForm->setErrorMessage($errorMessage);
     }
     // If Ajax Request
     if ($this->getRequest()->isXmlHttpRequest()) {
         return new JsonResponse(["success" => $errorMessage ? false : true, "message" => $errorMessage ? $errorMessage : $this->getTranslator()->trans("Thanks for signing up! We'll keep you posted whenever we have any new updates.", [], Front::MESSAGE_DOMAIN)], $errorMessage ? 500 : 200);
     }
     $this->getParserContext()->setGeneralError($errorMessage)->addForm($newsletterForm);
     // If an error URL is defined in the form, redirect to it, otherwise use the defaut view
     if ($errorMessage && $newsletterForm->hasErrorUrl()) {
         return $this->generateErrorRedirect($newsletterForm);
     }
 }
Beispiel #14
0
 public static function setUpBeforeClass()
 {
     self::$logger = Tlog::getInstance();
     self::$logger->setDestinations("Thelia\\Log\\Destination\\TlogDestinationText");
     self::$logger->setLevel(Tlog::DEBUG);
     self::$logger->setFiles("*");
 }
Beispiel #15
0
 public function parseResults(LoopResult $results)
 {
     $results = parent::parseResults($results);
     foreach ($results as $loopResultRow) {
         $accessoryProductId = $loopResultRow->get('ID');
         \Thelia\Log\Tlog::getInstance()->notice($this->accessoryId);
         $loopResultRow->set("ID", $this->accessoryId[$accessoryProductId])->set("POSITION", $this->accessoryPosition[$accessoryProductId])->set("ACCESSORY_ID", $accessoryProductId);
     }
     return $results;
 }
Beispiel #16
0
 /**
  * A simple helper to insert an entry in the admin log
  *
  * @param $resource
  * @param $action
  * @param $message
  * @param Request       $request
  * @param UserInterface $adminUser
  * @param bool          $withRequestContent
  */
 public static function append($resource, $action, $message, Request $request, UserInterface $adminUser = null, $withRequestContent = true)
 {
     $log = new AdminLog();
     $log->setAdminLogin($adminUser !== null ? $adminUser->getUsername() : '<no login>')->setAdminFirstname($adminUser !== null && $adminUser instanceof Admin ? $adminUser->getFirstname() : '<no first name>')->setAdminLastname($adminUser !== null && $adminUser instanceof Admin ? $adminUser->getLastname() : '<no last name>')->setResource($resource)->setAction($action)->setMessage($message)->setRequest($request->toString($withRequestContent));
     try {
         $log->save();
     } catch (\Exception $ex) {
         Tlog::getInstance()->err("Failed to insert new entry in AdminLog: {ex}", array('ex' => $ex));
     }
 }
Beispiel #17
0
 protected function renderTemplate()
 {
     $destinations = array();
     $destination_directories = Tlog::getInstance()->getDestinationsDirectories();
     foreach ($destination_directories as $dir) {
         $this->loadDefinedDestinations($dir, $destinations);
     }
     $active_destinations = explode(";", ConfigQuery::read(Tlog::VAR_DESTINATIONS, Tlog::DEFAUT_DESTINATIONS));
     return $this->render('system-logs', array('ip_address' => $this->getRequest()->getClientIp(), 'destinations' => $destinations, 'active_destinations' => $active_destinations));
 }
Beispiel #18
0
 /**
  * @throws \Exception
  */
 public function receiveResponse()
 {
     $request = $this->getRequest();
     $order_id = $request->get('reference');
     if (is_numeric($order_id)) {
         $order_id = (int) $order_id;
     }
     /*
      * Configure log output
      */
     $log = Tlog::getInstance();
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
     $log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, THELIA_ROOT . "log" . DS . "log-cmcic.txt");
     $log->info("accessed");
     $order = OrderQuery::create()->findPk($order_id);
     /*
      * Retrieve HMac for CGI2
      */
     $config = Config::read(CmCIC::JSON_CONFIG_PATH);
     $hashable = sprintf(CmCIC::CMCIC_CGI2_FIELDS, $config['CMCIC_TPE'], $request->get('date'), $request->get('montant'), $request->get('reference'), $request->get('texte-libre'), $config['CMCIC_VERSION'], $request->get('code-retour'), $request->get('cvx'), $request->get('vld'), $request->get('brand'), $request->get('status3ds'), $request->get('numauto'), $request->get('motifrefus'), $request->get('originecb'), $request->get('bincb'), $request->get('hpancb'), $request->get('ipclient'), $request->get('originetr'), $request->get('veres'), $request->get('pares'));
     $mac = CmCIC::computeHmac($hashable, CmCIC::getUsableKey($config["CMCIC_KEY"]));
     $response = CmCIC::CMCIC_CGI2_MACNOTOK . $hashable;
     if ($mac === strtolower($request->get('MAC'))) {
         $code = $request->get("code-retour");
         $msg = null;
         $status = OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID);
         $event = new OrderEvent($order);
         $event->setStatus($status->getId());
         switch ($code) {
             case "payetest":
                 $msg = "The test payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "paiement":
                 $msg = "The payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "Annulation":
                 $msg = "Error during the paiement: " . $this->getRequest()->get("motifrefus");
                 break;
             default:
                 $log->error("Error while receiving response from CMCIC: code-retour not valid");
                 throw new \Exception(Translator::getInstance()->trans("An error occured, no valid code-retour"));
         }
         if (!empty($msg)) {
             $log->info($msg);
         }
         $response = CmCIC::CMCIC_CGI2_MACOK;
     }
     /*
      * Get log back to previous state
      */
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
     return Response::create(sprintf(CmCIC::CMCIC_CGI2_RECEIPT, $response), 200, array("Content-type" => "text/plain", "Pragma" => "nocache"));
 }
Beispiel #19
0
 /**
  *
  * @return \Thelia\Log\Tlog
  */
 public static function getInstance()
 {
     if (self::$instance == false) {
         self::$instance = new Tlog();
         // On doit placer les initialisations à ce level pour pouvoir
         // utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.)
         // Les placer dans le constructeur provoquerait une boucle
         self::$instance->init();
     }
     return self::$instance;
 }
 /**
  * Initialize a module-specific logger.
  *
  * @return Tlog a Tlog instance
  */
 protected function getLog()
 {
     if ($this->log == null) {
         $this->log = Tlog::getNewInstance();
         $logFilePath = sprintf(THELIA_ROOT . "log" . DS . "%s.log", strtolower($this->getModuleCode()));
         $this->log->setPrefix("#LEVEL: #DATE #HOUR: ");
         $this->log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
         $this->log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, $logFilePath);
     }
     return $this->log;
 }
Beispiel #21
0
 /**
  * Send email to notify customer that files for virtual products are available
  *
  * @param OrderEvent $event
  * @throws \Exception
  */
 public function sendEmail(OrderEvent $event)
 {
     $order = $event->getOrder();
     // Be sure that we have a document to download
     $virtualProductCount = OrderProductQuery::create()->filterByOrderId($order->getId())->filterByVirtual(true)->filterByVirtualDocument(null, Criteria::NOT_EQUAL)->count();
     if ($virtualProductCount > 0) {
         $customer = $order->getCustomer();
         $this->mailer->sendEmailToCustomer('mail_virtualproduct', $customer, ['customer_id' => $customer->getId(), 'order_id' => $order->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt()]);
     } else {
         Tlog::getInstance()->warning("Virtual product download message not sent to customer: there's nothing to downnload");
     }
 }
Beispiel #22
0
 public function initDebugBar()
 {
     $alternativelogger = null;
     if ($this->debugMode) {
         $alternativelogger = \Thelia\Log\Tlog::getInstance();
     }
     $this->debugBar->addCollector(new PhpInfoCollector());
     //$this->debugBar->addCollector(new MessagesCollector());
     //$this->debugBar->addCollector(new RequestDataCollector());
     $this->debugBar->addCollector(new TimeDataCollector());
     $this->debugBar->addCollector(new MemoryCollector());
     $this->debugBar->addCollector(new PropelCollector($alternativelogger));
 }
Beispiel #23
0
 public static function exec($url, $status = 302, $cookies = array())
 {
     trigger_error('deprecated since version 2.1 and will be removed in 2.3. A response can not be send before the end of the script. Please use RedirectResponse directly', E_USER_DEPRECATED);
     if (false == Tlog::getInstance()->showRedirect($url)) {
         $response = new RedirectResponse($url, $status);
         foreach ($cookies as $cookie) {
             if (!$cookie instanceof Cookie) {
                 throw new \InvalidArgumentException(sprintf('Third parameter is not a valid Cookie object.'));
             }
             $response->headers->setCookie($cookie);
         }
         $response->send();
     }
 }
 public function setUp()
 {
     new Translator(new Container());
     Tlog::getNewInstance();
     $cacheDir = THELIA_CACHE_DIR . "test";
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir);
     }
     $this->tar = $this->getArchiveBuilder();
     if (!$this->tar->isAvailable()) {
         $this->markTestSkipped("The " . $this->tar->getExtension() . " archiver can't be tested as its dependencies are not installed/configured in this context");
     }
     $this->tar->setEnvironment("test");
 }
Beispiel #25
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     if ($order->isPaid() && $order->getPaymentModuleId() == Atos::getModuleId()) {
         if (Atos::getConfigValue('send_payment_confirmation_message')) {
             $this->mailer->sendEmailToCustomer(Atos::CONFIRMATION_MESSAGE_NAME, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
         }
         // Send confirmation email if required.
         if (Atos::getConfigValue('send_confirmation_message_only_if_paid')) {
             $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
         }
         Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
     }
 }
Beispiel #26
0
 public function redimlive($type, $id, $offset, $width, $height, $resizeMode = 'none')
 {
     $object = ucfirst($type);
     $queryClass = sprintf("Thelia\\Model\\%sImageQuery", $object);
     $filterMethod = sprintf("filterBy%sId", $object);
     // xxxImageQuery::create()
     $method = new \ReflectionMethod($queryClass, 'create');
     /** @var ModelCriteria $search */
     $search = $method->invoke(null);
     // Static !
     // $query->filterByXXX(id)
     $method = new \ReflectionMethod($queryClass, $filterMethod);
     $method->invoke($search, $id);
     $search->orderByPosition(Criteria::ASC)->offset(max(0, $offset - 1))->limit(1);
     if (null !== ($image = $search->findOne())) {
         switch ($resizeMode) {
             case 'crop':
                 $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
                 break;
             case 'borders':
                 $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
                 break;
             case 'none':
             default:
                 $resizeMode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
         }
         $baseSourceFilePath = ConfigQuery::read('images_library_path');
         if ($baseSourceFilePath === null) {
             $baseSourceFilePath = THELIA_LOCAL_DIR . 'media' . DS . 'images';
         } else {
             $baseSourceFilePath = THELIA_ROOT . $baseSourceFilePath;
         }
         // Put source image file path
         $sourceFilePath = sprintf('%s/%s/%s', $baseSourceFilePath, $object, $image->getFile());
         // Create image processing event
         $event = new ImageEvent($this->getRequest());
         $event->setSourceFilepath($sourceFilePath)->setCacheSubdirectory($object)->setWidth($width)->setHeight($height)->setResizeMode($resizeMode);
         try {
             // Dispatch image processing event
             $this->getDispatcher()->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
             return Response::create(file_get_contents($event->getCacheFilepath()), 200, array('Content-type' => image_type_to_mime_type(exif_imagetype($event->getCacheFilepath()))));
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError(sprintf("Failed to process image: %s", $ex->getMessage()));
             return new Response("", 500);
         }
     } else {
         $this->pageNotFound();
     }
 }
 /**
  * @param $pathToFile
  * @param $destination
  * @param $isOnline
  * @return $this
  * @throws \ErrorException
  */
 public function copyFile($pathToFile, $destination, $isOnline)
 {
     if ($isOnline) {
         /**
          * It's an online file
          */
         $this->getFileDownloader()->download($pathToFile, $destination);
     } else {
         /**
          * It's a local file
          */
         if (!is_file($pathToFile)) {
             $this->throwFileNotFound($pathToFile);
         } elseif (!is_readable($pathToFile)) {
             throw new FileNotReadableException($this->translator->trans("The file %file is not readable", ["%file" => $pathToFile]));
         }
         if (!copy($pathToFile, $destination)) {
             $translatedErrorMessage = $this->translator->trans("An error happend while copying %prev to %dest", ["%prev" => $pathToFile, "%dest" => $destination]);
             $this->logger->error($translatedErrorMessage);
             throw new \ErrorException($translatedErrorMessage);
         }
     }
     return $this;
 }
 public function setUp()
 {
     new Translator(new Container());
     Tlog::getNewInstance();
     $cacheDir = THELIA_CACHE_DIR . "test";
     if (!is_dir($cacheDir)) {
         mkdir($cacheDir);
     }
     $this->zip = new ZipArchiveBuilder();
     if (!$this->zip->isAvailable()) {
         $this->markTestSkipped("The " . $this->zip->getExtension() . " archiver can't be tested as its dependencies are not installed/configured in this context");
     }
     $this->zip->setEnvironment("test");
     $this->loadedZip = $this->zip->loadArchive(__DIR__ . DS . "TestResources/well_formatted.zip");
 }
 public function addWatermark(ImageEvent $event)
 {
     $image = $event->getImageObject();
     $size = $image->getSize();
     Tlog::getInstance()->debug("Category: " . $event->getCacheSubdirectory());
     if ($event->getCacheSubdirectory() == 'product' && $size->getHeight() > 200) {
         $imagine = $this->createImagineInstance();
         $watermark = $imagine->open(__DIR__ . DS . '..' . DS . '/Config/watermark.png');
         $watermark->resize($watermark->getSize()->heighten(round(0.1 * $size->getHeight())));
         $wSize = $watermark->getSize();
         $delta = round(0.02 * $size->getHeight());
         $bottomRight = new Point($size->getWidth() - $wSize->getWidth() - $delta, $size->getHeight() - $wSize->getHeight() - $delta);
         $image->paste($watermark, $bottomRight);
     }
 }
Beispiel #30
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->mailer->sendEmailToCustomer('mail_colissimo', $customer, ['customer_id' => $customer->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }