Ejemplo n.º 1
0
 /**
  *
  * @param $exception \Exception
  *
  * @throws \Exception
  * @return void
  */
 private function handleException($exception)
 {
     $request = new \Enlight_Controller_Request_RequestHttp();
     $response = new \Enlight_Controller_Response_ResponseHttp();
     if ($this->isModelException($exception)) {
         $generator = $this->container->get('models')->createModelGenerator();
         $result = $generator->generateAttributeModels();
         if ($result['success'] === true) {
             $response->setRedirect($request->getRequestUri());
             setcookie(self::redirectCookieString, true, time() + 5);
             $response->sendResponse();
             exit;
         } else {
             die(sprintf("Failed to create the attribute models, please check the permissions of the '%s' directory", $generator->getPath()));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 protected function sendHeader($header, $content)
 {
     if (!$this->sendHeaders) {
         return;
     }
     if ($this->response) {
         $this->response->setHeader($header, $content, true);
     } else {
         $this->headers[$header] = $content;
     }
 }
Ejemplo n.º 3
0
 /**
  *
  * @param $exception Exception
  *
  * @throws Exception
  * @return void
  */
 public function handleException($exception)
 {
     $this->request = new Enlight_Controller_Request_RequestHttp();
     $this->response = new Enlight_Controller_Response_ResponseHttp();
     if ($this->isModelException($exception)) {
         $path = Shopware()->Models()->getConfiguration()->getAttributeDir();
         $result = $this->generateModels($path);
         if ($result['success'] === true) {
             $this->response->setRedirect($this->request->getRequestUri());
             setcookie(self::redirectCookieString, true, time() + 5);
             $this->response->sendResponse();
             exit;
         } else {
             die(sprintf("Failed to create the attribute models, please check the permissions of the '%s' directory", $path));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Refresh partner log
  *
  * @param   \Enlight_Controller_Request_Request $request
  * @param   \Enlight_Controller_Response_ResponseHttp $response
  */
 public function refreshPartner($request, $response)
 {
     $partner = $request->getParam('partner', $request->getParam('sPartner'));
     if ($partner !== null) {
         if (strpos($partner, 'sCampaign') === 0) {
             $campaignID = (int) str_replace('sCampaign', '', $partner);
             if (!empty($campaignID)) {
                 Shopware()->Session()->sPartner = 'sCampaign' . $campaignID;
                 $sql = '
                     UPDATE s_campaigns_mailings
                     SET clicked = clicked + 1
                     WHERE id = ?
                 ';
                 Shopware()->Db()->query($sql, array($campaignID));
             }
         } else {
             $sql = 'SELECT * FROM s_emarketing_partner WHERE active=1 AND idcode=?';
             $row = Shopware()->Db()->fetchRow($sql, array($partner));
             if (!empty($row)) {
                 if ($row['cookielifetime']) {
                     $valid = time() + $row['cookielifetime'];
                 } else {
                     $valid = 0;
                 }
                 $response->setCookie('partner', $row['idcode'], $valid, '/');
             }
             Shopware()->Session()->sPartner = $partner;
         }
     } elseif ($request->getCookie('partner') !== null) {
         $sql = 'SELECT idcode FROM s_emarketing_partner WHERE active=1 AND idcode=?';
         $partner = Shopware()->Db()->fetchOne($sql, array($request->getCookie('partner')));
         if (empty($partner)) {
             unset(Shopware()->Session()->sPartner);
         } else {
             Shopware()->Session()->sPartner = $partner;
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Add context cookie
  *
  * @param Request $request
  * @param Response $response
  */
 private function addContextCookie(Request $request, Response $response)
 {
     /** @var $session Enlight_Components_Session_Namespace */
     $session = $this->get('session');
     if ($session->offsetGet('sCountry')) {
         /** @var ProductContextInterface $productContext */
         $productContext = $this->get('shopware_storefront.context_service')->getProductContext();
         $userContext = sha1(json_encode($productContext->getTaxRules()) . json_encode($productContext->getCurrentCustomerGroup()));
         $response->setCookie('x-cache-context-hash', $userContext, 0, $request->getBasePath() . '/', $request->getHttpHost() == 'localhost' ? null : $request->getHttpHost());
     } else {
         if ($request->getCookie('x-cache-context-hash')) {
             $response->setCookie('x-cache-context-hash', null, strtotime('-1 Year', time()), $request->getBasePath() . '/', $request->getHttpHost() == 'localhost' ? null : $request->getHttpHost());
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @param Enlight_Controller_Request_RequestHttp $request
  * @param Enlight_Controller_Response_ResponseHttp $response
  */
 protected function upgradeShop($request, $response)
 {
     $bootstrap = $this->Application()->Bootstrap();
     $shop = $this->Application()->Shop();
     $cookieKey = null;
     $cookieValue = null;
     switch (true) {
         case $request->getPost('sLanguage') !== null:
             $cookieKey = 'shop';
             $cookieValue = $request->getPost('sLanguage');
             break;
         case $request->getPost('sCurrency') !== null:
             $cookieKey = 'currency';
             $cookieValue = $request->getPost('sCurrency');
             break;
         case $request->getPost('__shop') !== null:
             $cookieKey = 'shop';
             $cookieValue = $request->getPost('__shop');
             break;
         case $request->getQuery('__shop') !== null:
             $cookieKey = 'shop';
             $cookieValue = $request->getQuery('__shop');
             break;
         case $request->getPost('__currency') !== null:
             $cookieKey = 'currency';
             $cookieValue = $request->getPost('__currency');
             break;
         case $request->getQuery('__template') !== null:
             $cookieKey = 'template';
             $cookieValue = $request->getQuery('__template');
             break;
     }
     // Redirect on shop change
     if ($cookieKey === 'shop') {
         /** @var $repository Shopware\Models\Shop\Repository */
         $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Shop\\Shop');
         $newShop = $repository->getActiveById($cookieValue);
         if ($newShop !== null) {
             if ($newShop->getHost() !== null && $newShop->getHost() !== $shop->getHost() || $newShop->getBaseUrl() !== null && $newShop->getBaseUrl() !== $shop->getBaseUrl()) {
                 $url = sprintf('%s://%s%s%s', $request::SCHEME_HTTP, $newShop->getHost(), $newShop->getBaseUrl(), '/');
                 $path = rtrim($newShop->getBasePath(), '/') . '/';
                 $response->setCookie($cookieKey, $cookieValue, 0, $path);
                 $response->setRedirect($url);
                 return;
             }
         }
     }
     // Refresh on shop change
     if ($cookieKey !== null && $cookieKey != 'template') {
         $path = rtrim($shop->getBasePath(), '/') . '/';
         $response->setCookie($cookieKey, $cookieValue, 0, $path);
         if ($request->isPost() && $request->getQuery('__shop') === null) {
             $url = sprintf('%s://%s%s', $request->getScheme(), $request->getHttpHost(), $request->getRequestUri());
             $response->setRedirect($url);
             return;
         }
     }
     // Upgrade currency
     if ($request->getCookie('currency') !== null) {
         $currencyValue = $request->getCookie('currency');
         foreach ($shop->getCurrencies() as $currency) {
             if ($currencyValue == $currency->getId() || $currencyValue == $currency->getCurrency()) {
                 $shop->setCurrency($currency);
                 break;
             }
         }
     }
     // Start session in frontend controllers
     $session = Shopware()->Session();
     if ($cookieKey !== null) {
         $session->{$cookieKey} = $cookieValue;
     }
     // Refresh basket on currency change
     if (isset($session->sBasketCurrency) && $shop->getCurrency()->getId() != $session->sBasketCurrency) {
         Shopware()->Modules()->Basket()->sRefreshBasket();
     }
     // Upgrade template
     if (isset($session->template) && !empty($session->Admin)) {
         $repository = 'Shopware\\Models\\Shop\\Template';
         $repository = Shopware()->Models()->getRepository($repository);
         $template = $session->template;
         $template = $repository->findOneBy(array('template' => $template));
         if ($template !== null) {
             $shop->setTemplate($template);
         } else {
             unset($session->template);
         }
     } else {
         unset($session->template);
     }
     // Save upgrades
     $shop->registerResources($bootstrap);
     if ($request->isSecure()) {
         $template = $bootstrap->getResource('Template');
         $template->setCompileId($template->getCompileId() . '_secure');
     }
 }
Ejemplo n.º 7
0
 /**
  * Iterate all exceptions of the given response object and write them into internal log object.
  *
  * @param   Enlight_Controller_Response_ResponseHttp $response
  */
 public function logException($response)
 {
     $exceptions = $response->getException();
     if (empty($exceptions)) {
         return;
     }
     $rows = array(array('code', 'name', 'message', 'line', 'file', 'trace'));
     /** @var $exception Exception */
     foreach ($exceptions as $exception) {
         $rows[] = array($exception->getCode(), get_class($exception), $exception->getMessage(), $exception->getLine(), $exception->getFile(), explode("\n", $exception->getTraceAsString()));
     }
     $table = array('Exception Log (' . count($exceptions) . ')', $rows);
     $this->log->table($table);
     foreach ($exceptions as $exception) {
         $this->log->err((string) $exception);
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns not upgraded plugins, "hacked" plugins, plugins, after do some check secret and cookie
  * @param Response $response
  * @param Request $request
  * @return SubscriptionStateStruct|bool
  */
 public function getPluginsSubscription(Response $response, Request $request)
 {
     if ($this->isPluginsSubscriptionCookieValid($request) == false) {
         return false;
     }
     try {
         $secret = $this->getShopSecret();
         if (empty($secret)) {
             return false;
         }
         $pluginStates = $this->getPluginsSubscriptionState($secret);
         $response->setCookie('lastCheckSubscriptionDate', date('dmY'), time() + 60 * 60 * 24);
         return $pluginStates;
     } catch (ShopSecretException $e) {
         $this->resetShopSecret();
         return false;
     } catch (\Exception $e) {
         return false;
     }
 }
Ejemplo n.º 9
0
 /**
  * Helper function to enable the http cache for a single shopware controller.
  *
  * @param int $cacheTime
  * @param array $cacheIds
  */
 public function enableControllerCache($cacheTime = 3600, $cacheIds = array())
 {
     $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime, true);
     $this->registerEsiRenderer();
     $this->setCacheIdHeader($cacheIds);
 }
Ejemplo n.º 10
0
 /**
  * @param EnlightResponse $response
  * @return SymfonyResponse
  */
 public function transformEnlightResponseToSymfonyResponse(EnlightResponse $response)
 {
     $rawHeaders = $response->getHeaders();
     $headers = array();
     foreach ($rawHeaders as $header) {
         if (!isset($headers[$header['name']]) || !empty($header['replace'])) {
             header_remove($header['name']);
             $headers[$header['name']] = array($header['value']);
         } else {
             $headers[$header['name']][] = $header['value'];
         }
     }
     $symfonyResponse = new SymfonyResponse($response->getBody(), $response->getHttpResponseCode(), $headers);
     foreach ($response->getCookies() as $cookieName => $cookieContent) {
         $sfCookie = new Cookie($cookieName, $cookieContent['value'], $cookieContent['expire'], $cookieContent['path'], $cookieContent['domain'], (bool) $cookieContent['secure'], (bool) $cookieContent['httpOnly']);
         $symfonyResponse->headers->setCookie($sfCookie);
     }
     return $symfonyResponse;
 }
Ejemplo n.º 11
0
 /**
  * @param $noCacheTag
  * @param bool $remove
  * @return void
  */
 public function setNoCacheTag($noCacheTag, $remove = false)
 {
     static $noCacheTags, $shopId;
     if(!isset($noCacheTags)) {
         if($this->request->getCookie('nocache')) {
             $noCacheTags = $this->request->getCookie('nocache');
             $noCacheTags = explode(', ', $noCacheTags);
         } else {
             $noCacheTags = array();
         }
         $shopId = Shopware()->Shop()->getId();
     }
     if(!empty($noCacheTag)) {
         $noCacheTag .= '-' . $shopId;
     }
     if(empty($noCacheTag)) {
         $newCacheTags = array();
     } elseif($remove && in_array($noCacheTag, $noCacheTags)) {
         $newCacheTags = array_diff($noCacheTags, array($noCacheTag));
     } elseif(!$remove && !in_array($noCacheTag, $noCacheTags)) {
         $newCacheTags = $noCacheTags;
         $newCacheTags[] = $noCacheTag;
     }
     if (isset($newCacheTags)) {
         $this->response->setCookie(
             'nocache',
             implode(', ', $newCacheTags),
             0,
             $this->request->getBasePath() . '/',
             $this->request->getHttpHost()
         );
     }
 }
Ejemplo n.º 12
0
    /**
     * @param \Enlight_Controller_Response_ResponseHttp $response
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function createResponse(ControllerResponse $response)
    {
        $rawHeaders = $response->getHeaders();
        $headers = array();
        foreach($rawHeaders as $header) {
            if(!isset($headers[$header['name']]) || !empty($header['replace'])) {
                $headers[$header['name']] = array($header['value']);
            } else {
                $headers[$header['name']][] = $header['value'];
            }
        }
        //todo@hl Maybe transform to symfony
        $response->sendCookies();

        return new Response(
            $response->getBody(),
            $response->getHttpResponseCode(),
            $headers
        );
    }