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,147 @@
<?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\Parameters;
use PrestaShop\Module\AutoUpgrade\Tools14;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
/**
* Class used for management of to do files for upgrade tasks.
* Load / Save / Delete etc.
*/
class FileConfigurationStorage
{
/**
* @var string Location where all the configuration files are stored
*/
private $configPath;
/**
* @var Filesystem
*/
private $filesystem;
public function __construct($path)
{
$this->configPath = $path;
$this->filesystem = new Filesystem();
}
/**
* UpgradeConfiguration loader.
*
* @param string $fileName File name to load
*
* @return mixed or array() as default value
*/
public function load($fileName = '')
{
$configFilePath = $this->configPath . $fileName;
$config = array();
if (file_exists($configFilePath)) {
$config = @unserialize(base64_decode(Tools14::file_get_contents($configFilePath)));
}
return $config;
}
/**
* @param mixed $config
* @param string $fileName Destination name of the config file
*
* @return bool
*/
public function save($config, $fileName)
{
$configFilePath = $this->configPath . $fileName;
try {
$this->filesystem->dumpFile($configFilePath, base64_encode(serialize($config)));
return true;
} catch (IOException $e) {
// TODO: $e needs to be logged
return false;
}
}
/**
* @return array Temporary files path & name
*/
public function getFilesList()
{
$files = array();
foreach (UpgradeFileNames::$tmp_files as $file) {
$files[$file] = $this->getFilePath(constant('PrestaShop\\Module\\AutoUpgrade\\Parameters\\UpgradeFileNames::' . $file));
}
return $files;
}
/**
* Delete all temporary files in the config folder.
*/
public function cleanAll()
{
$this->filesystem->remove(self::getFilesList());
}
/**
* Delete a file from the filesystem.
*
* @param string $fileName
*/
public function clean($fileName)
{
$this->filesystem->remove($this->getFilePath($fileName));
}
/**
* Check if a file exists on the filesystem.
*
* @param string $fileName
*/
public function exists($fileName)
{
return $this->filesystem->exists($this->getFilePath($fileName));
}
/**
* Generate the complete path to a given file.
*
* @param string $file Name
*
* @return string Pgit gui&
* ath
*/
private function getFilePath($file)
{
return $this->configPath . $file;
}
}

View File

@@ -0,0 +1,165 @@
<?php
/**
* 2007-2017 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:
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\AutoUpgrade\Parameters;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Contains the module configuration (form params).
*/
class UpgradeConfiguration extends ArrayCollection
{
/**
* Performance settings, if your server has a low memory size, lower these values.
*
* @var array
*/
protected $performanceValues = array(
'loopFiles' => array(400, 800, 1600), // files
'loopTime' => array(6, 12, 25), // seconds
'maxBackupFileSize' => array(15728640, 31457280, 62914560), // bytes
'maxWrittenAllowed' => array(4194304, 8388608, 16777216), // bytes
);
/**
* Get the name of the new release archive.
*
* @return string
*/
public function getArchiveFilename()
{
return $this->get('archive.filename');
}
/**
* Get the version included in the new release.
*
* @return string
*/
public function getArchiveVersion()
{
return $this->get('archive.version_num');
}
/**
* Get channel selected on config panel (Minor, major ...).
*
* @return string
*/
public function getChannel()
{
return $this->get('channel');
}
/**
* @return int Number of files to handle in a single call to avoid timeouts
*/
public function getNumberOfFilesPerCall()
{
return $this->performanceValues['loopFiles'][$this->getPerformanceLevel()];
}
/**
* @return int Number of seconds allowed before having to make another request
*/
public function getTimePerCall()
{
return $this->performanceValues['loopTime'][$this->getPerformanceLevel()];
}
/**
* @return int Kind of reference for SQL file creation, giving a file size before another request is needed
*/
public function getMaxSizeToWritePerCall()
{
return $this->performanceValues['maxWrittenAllowed'][$this->getPerformanceLevel()];
}
/**
* @return int Max file size allowed in backup
*/
public function getMaxFileToBackup()
{
return $this->performanceValues['maxBackupFileSize'][$this->getPerformanceLevel()];
}
/**
* @return int level of performance selected (0 for low, 2 for high)
*/
public function getPerformanceLevel()
{
return $this->get('PS_AUTOUP_PERFORMANCE') - 1;
}
/**
* @return bool True if the autoupgrade module should backup the images as well
*/
public function shouldBackupImages()
{
return (bool) $this->get('PS_AUTOUP_KEEP_IMAGES');
}
/**
* @return bool True if non-native modules must be disabled during upgrade
*/
public function shouldDeactivateCustomModules()
{
return (bool) $this->get('PS_AUTOUP_CUSTOM_MOD_DESACT');
}
/**
* @return bool true if we should keep the merchant emails untouched
*/
public function shouldKeepMails()
{
return (bool) $this->get('PS_AUTOUP_KEEP_MAILS');
}
/**
* @return bool True if we have to set the native theme by default
*/
public function shouldSwitchToDefaultTheme()
{
return (bool) $this->get('PS_AUTOUP_CHANGE_DEFAULT_THEME');
}
/**
* @return bool True if we are allowed to update th default theme files
*/
public function shouldUpdateDefaultTheme()
{
return (bool) $this->get('PS_AUTOUP_UPDATE_DEFAULT_THEME');
}
public function merge(array $array = array())
{
foreach ($array as $key => $value) {
$this->set($key, $value);
}
}
}

View File

@@ -0,0 +1,80 @@
<?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\Parameters;
use PrestaShop\Module\AutoUpgrade\Upgrader;
class UpgradeConfigurationStorage extends FileConfigurationStorage
{
/**
* UpgradeConfiguration loader.
*
* @param string $configFileName
*
* @return \PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration
*/
public function load($configFileName = '')
{
$data = array_merge(
$this->getDefaultData(),
parent::load($configFileName)
);
return new UpgradeConfiguration($data);
}
/**
* @param \PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration $config
* @param string $configFileName Destination path of the config file
*
* @return bool
*/
public function save($config, $configFileName)
{
if (!$config instanceof UpgradeConfiguration) {
throw new \InvalidArgumentException('Config is not a instance of UpgradeConfiguration');
}
return parent::save($config->toArray(), $configFileName);
}
public function getDefaultData()
{
return array(
'PS_AUTOUP_PERFORMANCE' => 1,
'PS_AUTOUP_CUSTOM_MOD_DESACT' => 1,
'PS_AUTOUP_UPDATE_DEFAULT_THEME' => 1,
'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 0,
'PS_AUTOUP_KEEP_MAILS' => 0,
'PS_AUTOUP_BACKUP' => 1,
'PS_AUTOUP_KEEP_IMAGES' => 1,
'channel' => Upgrader::DEFAULT_CHANNEL,
'archive.filename' => Upgrader::DEFAULT_FILENAME,
);
}
}

View File

@@ -0,0 +1,158 @@
<?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\Parameters;
/**
* File names where upgrade temporary content is stored.
*/
class UpgradeFileNames
{
/**
* configFilename contains all configuration specific to the autoupgrade module.
*
* @var string
*/
const CONFIG_FILENAME = 'config.var';
/**
* during upgradeFiles process,
* this files contains the list of queries left to upgrade in a serialized array.
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const QUERIES_TO_UPGRADE_LIST = 'queriesToUpgrade.list';
/**
* during upgradeFiles process,
* this files contains the list of files left to upgrade in a serialized array.
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const FILES_TO_UPGRADE_LIST = 'filesToUpgrade.list';
/**
* during upgradeModules process,
* this files contains the list of modules left to upgrade in a serialized array.
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const MODULES_TO_UPGRADE_LIST = 'modulesToUpgrade.list';
/**
* during upgradeFiles process,
* this files contains the list of files left to upgrade in a serialized array.
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const FILES_DIFF_LIST = 'filesDiff.list';
/**
* during backupFiles process,
* this files contains the list of files left to save in a serialized array.
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const FILES_TO_BACKUP_LIST = 'filesToBackup.list';
/**
* during backupDb process,
* this files contains the list of tables left to save in a serialized array.
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const DB_TABLES_TO_BACKUP_LIST = 'tablesToBackup.list';
/**
* during restoreDb process,
* this file contains a serialized array of queries which left to execute for restoring database
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const QUERIES_TO_RESTORE_LIST = 'queryToRestore.list';
const DB_TABLES_TO_CLEAN_LIST = 'tableToClean.list';
/**
* during restoreFiles process,
* this file contains difference between queryToRestore and queries present in a backupFiles archive
* (this file is deleted in init() method if you reload the page).
*
* @var string
*/
const FILES_TO_REMOVE_LIST = 'filesToRemove.list';
/**
* during restoreFiles process,
* contains list of files present in backupFiles archive.
*
* @var string
*/
const FILES_FROM_ARCHIVE_LIST = 'filesFromArchive.list';
/**
* mailCustomList contains list of mails files which are customized,
* relative to original files for the current PrestaShop version.
*
* @var string
*/
const MAILS_CUSTOM_LIST = 'mails-custom.list';
/**
* tradCustomList contains list of translation files which are customized,
* relative to original files for the current PrestaShop version.
*
* @var string
*/
const TRANSLATION_FILES_CUSTOM_LIST = 'translations-custom.list';
/**
* tmp_files contains an array of filename which will be removed
* at the beginning of the upgrade process.
*
* @var array
*/
public static $tmp_files = array(
'QUERIES_TO_UPGRADE_LIST', // used ?
'FILES_TO_UPGRADE_LIST',
'FILES_DIFF_LIST',
'FILES_TO_BACKUP_LIST',
'DB_TABLES_TO_BACKUP_LIST',
'QUERIES_TO_RESTORE_LIST',
'DB_TABLES_TO_CLEAN_LIST',
'FILES_TO_REMOVE_LIST',
'FILES_FROM_ARCHIVE_LIST',
'MAILS_CUSTOM_LIST',
'TRANSLATION_FILES_CUSTOM_LIST',
);
}