繁体   English   中英

symfony - Prestashop 1.7 - 我无法访问后台(管理面板)

[英]symfony - Prestashop 1.7 - I can not access to the back office (admin panel)

我会感谢你的帮助。 我可以在我的 web 页面中访问 BackOffice。 web 页面工作正常,但是当我访问 BO 时收到一个错误,我认为这与 symfony 配置有关。 我收到与 YAML 文件相关的错误:未定义常量 (CLOSED_ALLOWED_FAILURES)。 我已经复制了错误和以下文件:/src/PrestaShopBundle/Resources/config/services/core/currency.yml src/Core/Currency/ExchangeRateProvider.php -> 在此文件中定义了常量 CLOSED_ALLOWED_FAILURES

PS:-奇怪的是,如果我恢复几天前 web 运行时的备份,我会得到同样的错误!

  • 我已经手动删除了缓存 /var/cache

我将非常感谢任何帮助

谢谢

(3/3) FileLoaderLoadException

文件“/home/customer/www/...com/public_html/src/PrestaShopBundle/Resources/config/services/core/currency.yml”不包含有效的 YAML:常量“\PrestaShop\PrestaShop\Core\Currency \ExchangeRateProvider::CLOSED_ALLOWED_FAILURES" 未在 /home/customer/www/..com/public_html 中的第 16 行(“-:php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider:.CLOSED_ALLOWED_FAILURES”附近)定义/src/PrestaShopBundle/Resources/config/services/core/currency.yml(正在从“/home/customer/www/...com/public_html/src/PrestaShopBundle/Resources/config/services.yml”导入) .

Te copio el fichero aquí y también más abajo el archivo src/Core/Currency/ExchangeRateProvider.php

服务:_defaults:公共:true

prestashop.core.currency.grid_data_factory:
    class: 'PrestaShop\PrestaShop\Core\Currency\CurrencyGridDataFactory'
    arguments:
        - '@prestashop.core.grid.data_provider.currency'
        - '@translator'

prestashop.core.currency.exchange_rate.settings:
  class: PrestaShop\CircuitBreaker\FactorySettings
  arguments:
    - !php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider::CLOSED_ALLOWED_FAILURES
    - !php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider::CLOSED_TIMEOUT_SECONDS
    - !php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider::OPEN_THRESHOLD_SECONDS
  calls:
    - ['setStrippedFailures', [!php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider::OPEN_ALLOWED_FAILURES]]
    - ['setStrippedTimeout', [!php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider::OPEN_TIMEOUT_SECONDS]]
    - ['setStorage', ['@prestashop.core.circuit_breaker.storage']]
    - ['setClientOptions', [{'method': 'GET', 'subscribers': ['@prestashop.core.circuit_breaker.guzzle.cache_subscriber']}]]
    # create a factory for cache_subscriber so that we can easily adapt the cache duration

prestashop.core.currency.exchange_rate.circuit_breaker:
  class: 'PrestaShop\CircuitBreaker\Contract\CircuitBreakerInterface'
  factory: ["@prestashop.core.circuit_breaker.advanced_factory", create]
  arguments:
    - "@prestashop.core.currency.exchange_rate.settings"

prestashop.core.exchange_rate.provider:
  class: PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider
  arguments:
    - !php/const \PrestaShop\PrestaShop\Core\Currency\ExchangeRateProvider::CURRENCY_FEED_URL
    - '@=service("prestashop.adapter.data_provider.currency").getDefaultCurrencyIsoCode()'
    - '@prestashop.core.currency.exchange_rate.circuit_breaker'
    - '@cache.app'












<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */

namespace PrestaShop\PrestaShop\Core\Currency;

use PrestaShop\CircuitBreaker\Contract\CircuitBreakerInterface;
use PrestaShop\Decimal\Number;
use PrestaShop\PrestaShop\Core\Currency\Exception\CurrencyFeedException;
use PrestaShop\PrestaShop\Core\Domain\Currency\ValueObject\ExchangeRate;
use SimpleXMLElement;
use Symfony\Component\Cache\Adapter\AdapterInterface as CacheInterface;

/**
 * Retrieves the exchange rate of a currency (based on the default currency). It uses a circuit breaker
 * to avoid being blocked in case of network problems and it saves each of its request in a cache to be
 * able to have a fallback response.
 */
class ExchangeRateProvider
{
    /**
     * This url was set in the _PS_CURRENCY_FEED_URL_ const but it is not accessible in every
     * context because it is weirdly defined in defines_uri.inc.php So it is safer to define
     * it properly here.
     */
    const CURRENCY_FEED_URL = 'http://api.prestashop.com/xml/currencies.xml';

    const CLOSED_ALLOWED_FAILURES = 3;
    const CLOSED_TIMEOUT_SECONDS = 1;

    const OPEN_ALLOWED_FAILURES = 3;
    const OPEN_TIMEOUT_SECONDS = 2;
    const OPEN_THRESHOLD_SECONDS = 3600; // 1 hour

    const CACHE_KEY_XML = 'currency_feed.xml';

    /** @var string */
    private $currencyFeedUrl;

    /** @var string */
    private $defaultCurrencyIsoCode;

    /** @var CircuitBreakerInterface */
    private $remoteServiceProvider;

    /** @var CacheInterface */
    private $cache;

    /** @var string */
    private $sourceIsoCode;

    /** @var array */
    private $currencies = [];

    /**
     * @param string $currencyFeedUrl
     * @param string $defaultCurrencyIsoCode
     * @param CircuitBreakerInterface $remoteServiceProvider
     * @param CacheInterface $cache
     */
    public function __construct(
        $currencyFeedUrl,
        $defaultCurrencyIsoCode,
        CircuitBreakerInterface $remoteServiceProvider,
        CacheInterface $cache
    ) {
        $this->currencyFeedUrl = $currencyFeedUrl;
        $this->defaultCurrencyIsoCode = $defaultCurrencyIsoCode;
        $this->remoteServiceProvider = $remoteServiceProvider;
        $this->cache = $cache;
    }

    /**
     * @param string $currencyIsoCode
     *
     * @return Number
     *
     * @throws CurrencyFeedException
     */
    public function getExchangeRate($currencyIsoCode)
    {
        $this->fetchCurrencyFeed();

        // Default feed currency (usually EUR)
        if ($this->defaultCurrencyIsoCode == $currencyIsoCode) {
            return ExchangeRate::getDefaultExchangeRate();
        }

        /*
         * Search for the currency rate in the source feed, this represents the rate
         * relative to the source feed (compared to the feed default currency)
         */
        $sourceRate = $this->getExchangeRateFromFeed($currencyIsoCode);

        /*
         * Fetch the exchange rate of the default currency (compared to the source currency)
         * and finally compute the asked currency rate compared to the shop default currency rate
         */
        $defaultExchangeRate = $this->getExchangeRateFromFeed($this->defaultCurrencyIsoCode);

        return $sourceRate->dividedBy($defaultExchangeRate);
    }

    /**
     * @param string $currencyIsoCode
     *
     * @return Number
     *
     * @throws CurrencyFeedException
     */
    private function getExchangeRateFromFeed(string $currencyIsoCode)
    {
        if ($this->sourceIsoCode == $currencyIsoCode) {
            return new Number('1.0');
        }

        if (!isset($this->currencies[$currencyIsoCode])) {
            throw new CurrencyFeedException(sprintf('Exchange rate for currency with ISO code %s was not found', $currencyIsoCode));
        }

        return $this->currencies[$currencyIsoCode];
    }

    /**
     * Fetch the currency from its url using circuit breaker, if no content was fetched
     * fallback on the cache file. This is only performed once per process, if the currencies
     * are already present then there is nothing to do.
     *
     * @throws CurrencyFeedException
     */
    private function fetchCurrencyFeed()
    {
        if (!empty($this->currencies)) {
            return;
        }

        $remoteFeedData = $this->remoteServiceProvider->call($this->currencyFeedUrl);
        $cachedFeedData = $this->getCachedCurrencyFeed();
        if (empty($remoteFeedData) && empty($cachedFeedData)) {
            throw new CurrencyFeedException('Currency feed could not be fetched');
        }

        $xmlFeed = $this->parseAndSaveXMLFeed($remoteFeedData);
        if (null === $xmlFeed) {
            $xmlFeed = $this->parseAndSaveXMLFeed($cachedFeedData);
        }

        if (null === $xmlFeed) {
            throw new CurrencyFeedException('Invalid currency XML feed');
        }

        $this->parseXmlFeed($xmlFeed);
    }

    /**
     * @param string $feedContent
     *
     * @return SimpleXMLElement|null
     */
    private function parseAndSaveXMLFeed($feedContent)
    {
        $xmlFeed = @simplexml_load_string($feedContent);
        if (!$xmlFeed || !$this->isValidXMLFeed($xmlFeed)) {
            return null;
        }

        //Cache the feed
        $cacheItem = $this->cache->getItem(self::CACHE_KEY_XML);
        $cacheItem->set($feedContent);
        $this->cache->save($cacheItem);

        return $xmlFeed;
    }

    /**
     * @param SimpleXMLElement $xmlFeed
     */
    private function parseXmlFeed($xmlFeed)
    {
        $xmlCurrencies = $xmlFeed->list->currency;

        $this->sourceIsoCode = (string) ($xmlFeed->source['iso_code']);
        foreach ($xmlCurrencies as $currency) {
            $this->currencies[(string) $currency['iso_code']] = new Number((string) $currency['rate']);
        }
    }

    /**
     * @return string
     */
    private function getCachedCurrencyFeed()
    {
        $cacheItem = $this->cache->getItem(self::CACHE_KEY_XML);
        if (!$cacheItem->isHit()) {
            return '';
        }

        $feedContent = $cacheItem->get();

        return !empty($feedContent) ? $feedContent : '';
    }

    /**
     * @param SimpleXMLElement $xmlFeed
     *
     * @return bool
     */
    private function isValidXMLFeed(SimpleXMLElement $xmlFeed)
    {
        return $xmlFeed && $xmlFeed->list && count($xmlFeed->list->currency) && $xmlFeed->source;
    }
}

我也有完全一样的问题。 我尝试更新一键式模块,之后病房在后台出现白屏:启用错误日志后,我收到了关于 CLOSED_ALLOWED_FAILURES 的相同消息:

The constant "\PrestaShop\PrestaShop\Adapter\News\NewsDataProvider::CLOSED_ALLOWED_FAILURES" is not defined at line 10 (near "- !php/const \PrestaShop\PrestaShop\Adapter\News\NewsDataProvider::CLOSED_ALLOWED_FAILURES").

白屏似乎是 PrestaShop 的一个主要问题,我同时考虑迁移到更稳定的系统,因为这会花费我太多时间和失去业务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM