Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
/*
* 2007-2018 PrestaShop
*
* 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.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\AutoUpgrade\Log;
/**
* This class reimplement the old properties of the class AdminSelfUpgrade,
* where all the mesages were stored.
*/
class LegacyLogger extends Logger
{
protected $normalMessages = array();
protected $severeMessages = array();
protected $lastInfo = '';
/**
* @var resource|false|null File descriptor of the log file
*/
protected $fd;
public function __construct($fileName = null)
{
if (null !== $fileName) {
$this->fd = fopen($fileName, 'a');
}
}
public function __destruct()
{
if (is_resource($this->fd)) {
fclose($this->fd);
}
}
/**
* {@inheritdoc}
*/
public function getErrors()
{
return $this->severeMessages;
}
/**
* {@inheritdoc}
*/
public function getInfos()
{
return $this->normalMessages;
}
/**
* {@inheritdoc}
*/
public function getLastInfo()
{
return $this->lastInfo;
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = array())
{
if (empty($message)) {
return;
}
if (is_resource($this->fd)) {
fwrite($this->fd, '[' . date('Y-m-d H:i:s') . '] ' . $message . PHP_EOL);
}
// Specific case for INFO
if ($level === self::INFO) {
// If last info is already defined, move it to the messages list
if (!empty($this->lastInfo)) {
$this->normalMessages[] = $this->lastInfo;
}
$this->lastInfo = $message;
return;
}
if ($level < self::ERROR) {
$this->normalMessages[] = $message;
} else {
$this->severeMessages[] = $message;
}
}
}

View File

@@ -0,0 +1,128 @@
<?php
/*
* 2007-2018 PrestaShop
*
* 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.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\AutoUpgrade\Log;
/**
* This class retrieves all message to display during the upgrade / rollback tasks.
*/
abstract class Logger implements LoggerInterface
{
const DEBUG = 1;
const INFO = 2;
const NOTICE = 3;
const WARNING = 4;
const ERROR = 5;
const CRITICAL = 6;
const ALERT = 7;
const EMERGENCY = 8;
protected static $levels = array(
self::DEBUG => 'DEBUG',
self::INFO => 'INFO',
self::NOTICE => 'NOTICE',
self::WARNING => 'WARNING',
self::ERROR => 'ERROR',
self::CRITICAL => 'CRITICAL',
self::ALERT => 'ALERT',
self::EMERGENCY => 'EMERGENCY',
);
public function alert($message, array $context = array())
{
$this->log(self::ALERT, $message, $context);
}
public function critical($message, array $context = array())
{
$this->log(self::CRITICAL, $message, $context);
}
public function debug($message, array $context = array())
{
$this->log(self::DEBUG, $message, $context);
}
public function emergency($message, array $context = array())
{
$this->log(self::EMERGENCY, $message, $context);
}
public function error($message, array $context = array())
{
$this->log(self::ERROR, $message, $context);
}
public function info($message, array $context = array())
{
$this->log(self::INFO, $message, $context);
}
public function notice($message, array $context = array())
{
$this->log(self::NOTICE, $message, $context);
}
public function warning($message, array $context = array())
{
$this->log(self::WARNING, $message, $context);
}
/**
* Equivalent of the old $nextErrors
* Used during upgrade. Will be displayed in the top right panel (not visible at the beginning).
*
* @var array Details of error which occured during the request. Verbose levels: ERROR
*/
public function getErrors()
{
return array();
}
/**
* Equivalent of the old $nextQuickInfo
* Used during upgrade. Will be displayed in the lower panel.
*
* @var array Details on what happened during the execution. Verbose levels: DEBUG / INFO / WARNING
*/
public function getInfos()
{
return array();
}
/**
* Return the last message stored with the INFO level.
* Equivalent of the old $next_desc
* Used during upgrade. Will be displayed on the top left panel.
*
* @var string Stores the main information about the current step
*/
public function getLastInfo()
{
return '';
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* IMPORTANT NOTE.
*
* This class is taken from the composer dependency psr/log.
* We copied it here to avoid conflicts with the same file loaded by the core
*/
namespace PrestaShop\Module\AutoUpgrade\Log;
/**
* Describes a logger instance.
*
* The message MUST be a string or object implementing __toString().
*
* The message MAY contain placeholders in the form: {foo} where foo
* will be replaced by the context data in key "foo".
*
* The context array can contain arbitrary data. The only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* for the full interface specification.
*/
interface LoggerInterface
{
/**
* System is unusable.
*
* @param string $message
* @param array $context
*/
public function emergency($message, array $context = array());
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
*/
public function alert($message, array $context = array());
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
*/
public function critical($message, array $context = array());
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
*/
public function error($message, array $context = array());
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string $message
* @param array $context
*/
public function warning($message, array $context = array());
/**
* Normal but significant events.
*
* @param string $message
* @param array $context
*/
public function notice($message, array $context = array());
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
*/
public function info($message, array $context = array());
/**
* Detailed debug information.
*
* @param string $message
* @param array $context
*/
public function debug($message, array $context = array());
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*/
public function log($level, $message, array $context = array());
}

View File

@@ -0,0 +1,116 @@
<?php
/*
* 2007-2018 PrestaShop
*
* 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.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\AutoUpgrade\Log;
/**
* Logger to use when the messages can be seen as soon as they are created.
* For instance, in a CLI context.
*/
class StreamedLogger extends Logger
{
/**
* @var int Minimum criticity of level to display
*/
protected $filter = self::INFO;
/**
* @var resource File handler of standard output
*/
protected $out;
/**
* @var resource File handler of standard error
*/
protected $err;
public function __construct()
{
$this->out = fopen('php://stdout', 'w');
$this->err = fopen('php://stderr', 'w');
}
public function __destruct()
{
fclose($this->out);
fclose($this->err);
}
/**
* Check the verbosity allows the message to be displayed.
*
* @param int $level
*
* @return bool
*/
public function isFiltered($level)
{
return $level < $this->filter;
}
/**
* {@inherit}.
*/
public function log($level, $message, array $context = array())
{
if (empty($message)) {
return;
}
$log = self::$levels[$level] . ' - ' . $message . PHP_EOL;
if ($level > self::ERROR) {
fwrite($this->err, $log);
}
if (!$this->isFiltered($level)) {
fwrite($this->out, $log);
}
}
public function getFilter()
{
return $this->filter;
}
/**
* Set the verbosity of the logger.
*
* @param int $filter
*
* @return $this
*/
public function setFilter($filter)
{
if (!array_key_exists($filter, self::$levels)) {
throw new \Exception('Unknown level ' . $filter);
}
$this->filter = $filter;
return $this;
}
}