// install-new renamed to install-dev
This commit is contained in:
@@ -0,0 +1,414 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
abstract class InstallControllerHttp
|
||||
{
|
||||
/**
|
||||
* @var array List of installer steps
|
||||
*/
|
||||
protected static $steps = array('welcome', 'system', 'database', 'configure', 'process');
|
||||
|
||||
protected static $instances = array();
|
||||
|
||||
/**
|
||||
* @var string Current step
|
||||
*/
|
||||
public $step;
|
||||
|
||||
/**
|
||||
* @var array List of errors
|
||||
*/
|
||||
public $errors = array();
|
||||
|
||||
/**
|
||||
* @var InstallController
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
/**
|
||||
* @var InstallSession
|
||||
*/
|
||||
public $session;
|
||||
|
||||
/**
|
||||
* @var InstallLanguages
|
||||
*/
|
||||
public $language;
|
||||
|
||||
/**
|
||||
* @var bool If false, disable next button access
|
||||
*/
|
||||
public $next_button = true;
|
||||
|
||||
/**
|
||||
* @var InstallAbstractModel
|
||||
*/
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* @var array Magic vars
|
||||
*/
|
||||
protected $__vars = array();
|
||||
|
||||
/**
|
||||
* Process form to go to next step
|
||||
*/
|
||||
abstract public function processNextStep();
|
||||
|
||||
/**
|
||||
* Validate current step
|
||||
*/
|
||||
abstract public function validate();
|
||||
|
||||
/**
|
||||
* Display current step view
|
||||
*/
|
||||
abstract public function display();
|
||||
|
||||
final public static function execute()
|
||||
{
|
||||
// Include all controllers
|
||||
foreach (self::$steps as $step)
|
||||
{
|
||||
if (!file_exists(_PS_INSTALL_CONTROLLERS_PATH_.'http/'.$step.'.php'))
|
||||
throw new PrestashopInstallerException("Controller file 'http/{$step}.php' not found");
|
||||
|
||||
require_once _PS_INSTALL_CONTROLLERS_PATH_.'http/'.$step.'.php';
|
||||
$classname = 'InstallControllerHttp'.$step;
|
||||
self::$instances[$step] = new $classname($step);
|
||||
}
|
||||
|
||||
$session = InstallSession::getInstance();
|
||||
if (!$session->last_step || !in_array($session->last_step, self::$steps))
|
||||
$session->last_step = self::$steps[0];
|
||||
|
||||
// Set timezone
|
||||
@date_default_timezone_set($session->shop_timezone ? $session->shop_timezone : 'UTC');
|
||||
|
||||
// Get current step (check first if step is changed, then take it from session)
|
||||
if (Tools::getValue('step'))
|
||||
{
|
||||
$current_step = Tools::getValue('step');
|
||||
$session->step = $current_step;
|
||||
}
|
||||
else
|
||||
$current_step = (isset($session->step)) ? $session->step : self::$steps[0];
|
||||
|
||||
if (!in_array($current_step, self::$steps))
|
||||
$current_step = self::$steps[0];
|
||||
|
||||
// Validate all steps until current step. If a step is not valid, use it as current step.
|
||||
foreach (self::$steps as $check_step)
|
||||
{
|
||||
// Do not validate current step
|
||||
if ($check_step == $current_step)
|
||||
break;
|
||||
|
||||
if (!self::$instances[$check_step]->validate())
|
||||
{
|
||||
$current_step = $check_step;
|
||||
$session->step = $current_step;
|
||||
$session->last_step = $current_step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Submit form to go to next step
|
||||
if (Tools::getValue('submitNext'))
|
||||
{
|
||||
self::$instances[$current_step]->processNextStep();
|
||||
|
||||
// If current step is validated, let's go to next step
|
||||
if (self::$instances[$current_step]->validate())
|
||||
$current_step = self::$instances[$current_step]->findNextStep();
|
||||
$session->step = $current_step;
|
||||
|
||||
// Change last step
|
||||
if (self::getStepOffset($current_step) > self::getStepOffset($session->last_step))
|
||||
$session->last_step = $current_step;
|
||||
}
|
||||
// Go to previous step
|
||||
else if (Tools::getValue('submitPrevious') && $current_step != self::$steps[0])
|
||||
{
|
||||
$current_step = self::$instances[$current_step]->findPreviousStep($current_step);
|
||||
$session->step = $current_step;
|
||||
}
|
||||
|
||||
self::$instances[$current_step]->process();
|
||||
self::$instances[$current_step]->display();
|
||||
}
|
||||
|
||||
final public function __construct($step)
|
||||
{
|
||||
$this->step = $step;
|
||||
$this->session = InstallSession::getInstance();
|
||||
|
||||
// Set current language
|
||||
$this->language = InstallLanguages::getInstance();
|
||||
$lang = (isset($this->session->lang)) ? $this->session->lang : 'en';
|
||||
if (!in_array($lang, $this->language->getIsoList()))
|
||||
$lang = 'en';
|
||||
$this->language->setLanguage($lang);
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize model
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get steps list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSteps()
|
||||
{
|
||||
return self::$steps;
|
||||
}
|
||||
|
||||
public function getLastStep()
|
||||
{
|
||||
return $this->session->last_step;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find offset of a step by name
|
||||
*
|
||||
* @param string $step Step name
|
||||
* @return int
|
||||
*/
|
||||
static public function getStepOffset($step)
|
||||
{
|
||||
static $flip = null;
|
||||
|
||||
if (is_null($flip))
|
||||
$flip = array_flip(self::$steps);
|
||||
return $flip[$step];
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a HTTP redirection to a step
|
||||
*
|
||||
* @param string $step
|
||||
*/
|
||||
public function redirect($step)
|
||||
{
|
||||
header('location: index.php?step='.$step);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translated string
|
||||
*
|
||||
* @param string $str String to translate
|
||||
* @param ... All other params will be used with sprintf
|
||||
* @return string
|
||||
*/
|
||||
public function l($str)
|
||||
{
|
||||
$args = func_get_args();
|
||||
return call_user_func_array(array($this->language, 'l'), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find previous step
|
||||
*
|
||||
* @param string $step
|
||||
*/
|
||||
public function findPreviousStep()
|
||||
{
|
||||
return (isset(self::$steps[$this->getStepOffset($this->step) - 1])) ? self::$steps[$this->getStepOffset($this->step) - 1] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find next step
|
||||
*
|
||||
* @param string $step
|
||||
*/
|
||||
public function findNextStep()
|
||||
{
|
||||
return (isset(self::$steps[$this->getStepOffset($this->step) + 1])) ? self::$steps[$this->getStepOffset($this->step) + 1] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current step is first step in list of steps
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFirstStep()
|
||||
{
|
||||
return self::getStepOffset($this->step) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current step is last step in list of steps
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLastStep()
|
||||
{
|
||||
return self::getStepOffset($this->step) == (count(self::$steps) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is given step is already finished
|
||||
*
|
||||
* @param string $step
|
||||
* @return bool
|
||||
*/
|
||||
public function isStepFinished($step)
|
||||
{
|
||||
return self::getStepOffset($step) < self::getStepOffset($this->getLastStep());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get telephone used for this language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPhone()
|
||||
{
|
||||
return $this->language->getInformation('phone', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to documentation for this language
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function getDocumentationLink()
|
||||
{
|
||||
return $this->language->getInformation('documentation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to forum for this language
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function getForumLink()
|
||||
{
|
||||
return $this->language->getInformation('forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to blog for this language
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function getBlogLink()
|
||||
{
|
||||
return $this->language->getInformation('blog');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to support for this language
|
||||
*
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function getSupportLink()
|
||||
{
|
||||
return $this->language->getInformation('support');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send AJAX response in JSON format {success: bool, message: string}
|
||||
*
|
||||
* @param bool $success
|
||||
* @param string $message
|
||||
*/
|
||||
public function ajaxJsonAnswer($success, $message = '')
|
||||
{
|
||||
die(Tools::jsonEncode(array(
|
||||
'success' => (bool)$success,
|
||||
'message' => $message,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a template
|
||||
*
|
||||
* @param string $template Template name
|
||||
* @param bool $get_output Is true, return template html
|
||||
* @return string
|
||||
*/
|
||||
public function displayTemplate($template, $get_output = false, $path = null)
|
||||
{
|
||||
if (!$path)
|
||||
$path = _PS_INSTALL_PATH_.'theme/views/';
|
||||
|
||||
if (!file_exists($path.$template.'.phtml'))
|
||||
throw new PrestashopInstallerException("Template '{$template}.phtml' not found");
|
||||
|
||||
if ($get_output)
|
||||
ob_start();
|
||||
|
||||
include($path.$template.'.phtml');
|
||||
|
||||
if ($get_output)
|
||||
{
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
public function &__get($varname)
|
||||
{
|
||||
if (isset($this->__vars[$varname]))
|
||||
$ref = &$this->__vars[$varname];
|
||||
else
|
||||
{
|
||||
$null = null;
|
||||
$ref = &$null;
|
||||
}
|
||||
return $ref;
|
||||
}
|
||||
|
||||
public function __set($varname, $value)
|
||||
{
|
||||
$this->__vars[$varname] = $value;
|
||||
}
|
||||
|
||||
public function __isset($varname)
|
||||
{
|
||||
return isset($this->__vars[$varname]);
|
||||
}
|
||||
|
||||
public function __unset($varname)
|
||||
{
|
||||
unset($this->__vars[$varname]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class PrestashopInstallerException extends PrestaShopException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class InstallLanguage
|
||||
{
|
||||
/**
|
||||
* @var string Current language folder
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var string Current language iso
|
||||
*/
|
||||
protected $iso;
|
||||
|
||||
/**
|
||||
* @var array Cache list of installer translations for this language
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
protected $fixtures_data;
|
||||
|
||||
/**
|
||||
* @var array Cache list of informations in language.xml file
|
||||
*/
|
||||
protected $meta;
|
||||
|
||||
/**
|
||||
* @var array Cache list of countries for this language
|
||||
*/
|
||||
protected $countries;
|
||||
|
||||
public function __construct($iso)
|
||||
{
|
||||
$this->path = _PS_INSTALL_LANGS_PATH_.$iso.'/';
|
||||
$this->iso = $iso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get iso for current language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIso()
|
||||
{
|
||||
return $this->iso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an information from language.xml file (E.g. $this->getMetaInformation('name'))
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public function getMetaInformation($key)
|
||||
{
|
||||
if (!is_array($this->meta))
|
||||
{
|
||||
$this->meta = array();
|
||||
$xml = simplexml_load_file($this->path.'language.xml');
|
||||
foreach ($xml->children() as $node)
|
||||
$this->meta[$node->getName()] = (string)$node;
|
||||
}
|
||||
|
||||
return isset($this->meta[$key]) ? $this->meta[$key] : null;
|
||||
}
|
||||
|
||||
public function getTranslation($key, $type = 'translations')
|
||||
{
|
||||
if (!is_array($this->data))
|
||||
$this->data = file_exists($this->path.'install.php') ? include($this->path.'install.php') : array();
|
||||
|
||||
return isset($this->data[$type][$key]) ? $this->data[$type][$key] : null;
|
||||
}
|
||||
|
||||
public function getFixtureTranslation($key)
|
||||
{
|
||||
if (!is_array($this->fixtures_data))
|
||||
$this->fixtures_data = file_exists(_PS_INSTALL_FIXTURES_PATH_.'apple/langs/'.$this->iso.'/fixtures.php') ? include(_PS_INSTALL_FIXTURES_PATH_.'apple/langs/'.$this->iso.'/fixtures.php') : array();
|
||||
|
||||
return isset($this->fixtures_data[$key]) ? $this->fixtures_data[$key] : null;
|
||||
}
|
||||
|
||||
public function getCountries()
|
||||
{
|
||||
if (!is_array($this->countries))
|
||||
{
|
||||
$this->countries = array();
|
||||
if (file_exists($this->path.'data/country.xml'))
|
||||
{
|
||||
if ($xml = simplexml_load_file($this->path.'data/country.xml'))
|
||||
foreach ($xml->country as $country)
|
||||
$this->countries[strtolower((string)$country['id'])] = (string)$country->name;
|
||||
}
|
||||
}
|
||||
return $this->countries;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class InstallLanguages
|
||||
{
|
||||
const DEFAULT_ISO = 'en';
|
||||
/**
|
||||
* @var array List of available languages
|
||||
*/
|
||||
protected $languages;
|
||||
|
||||
/**
|
||||
* @var string Current language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* @var InstallLanguage Default language (english)
|
||||
*/
|
||||
protected $default;
|
||||
|
||||
protected static $_instance;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!self::$_instance)
|
||||
self::$_instance = new self();
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// English language is required
|
||||
if (!file_exists(_PS_INSTALL_LANGS_PATH_.'en/language.xml'))
|
||||
throw new PrestashopInstallerException('English language is missing');
|
||||
|
||||
$this->languages = array(
|
||||
self::DEFAULT_ISO => new InstallLanguage(self::DEFAULT_ISO),
|
||||
);
|
||||
|
||||
// Load other languages
|
||||
foreach (scandir(_PS_INSTALL_LANGS_PATH_) as $lang)
|
||||
if ($lang[0] != '.' && is_dir(_PS_INSTALL_LANGS_PATH_.$lang) && $lang != self::DEFAULT_ISO)
|
||||
$this->languages[$lang] = new InstallLanguage($lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current language
|
||||
*
|
||||
* @param string $iso Language iso
|
||||
*/
|
||||
public function setLanguage($iso)
|
||||
{
|
||||
if (!in_array($iso, $this->getIsoList()))
|
||||
throw new PrestashopInstallerException('Language '.$iso.' not found');
|
||||
|
||||
$this->language = $iso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguageIso()
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current language
|
||||
*
|
||||
* @return InstallLanguage
|
||||
*/
|
||||
public function getLanguage($iso = null)
|
||||
{
|
||||
if (!$iso)
|
||||
$iso = $this->language;
|
||||
return $this->languages[$iso];
|
||||
}
|
||||
|
||||
public function getIsoList()
|
||||
{
|
||||
return array_keys($this->languages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of languages iso supported by installer
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguages()
|
||||
{
|
||||
return $this->languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translated string
|
||||
*
|
||||
* @param string $str String to translate
|
||||
* @param ... All other params will be used with sprintf
|
||||
* @return string
|
||||
*/
|
||||
public function l($str)
|
||||
{
|
||||
$args = func_get_args();
|
||||
$translation = $this->getLanguage()->getTranslation($args[0]);
|
||||
if (is_null($translation))
|
||||
{
|
||||
$translation = $this->getLanguage(self::DEFAULT_ISO)->getTranslation($args[0]);
|
||||
if (is_null($translation))
|
||||
$translation = $args[0];
|
||||
}
|
||||
|
||||
$args[0] = $translation;
|
||||
return call_user_func_array('sprintf', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an information from language (phone, links, etc.)
|
||||
*
|
||||
* @param string $key Information identifier
|
||||
*/
|
||||
public function getInformation($key, $with_default = true)
|
||||
{
|
||||
$information = $this->getLanguage()->getTranslation($key, 'informations');
|
||||
if (is_null($information) && $with_default)
|
||||
return $this->getLanguage(self::DEFAULT_ISO)->getTranslation($key, 'informations');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of countries for current language
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountries()
|
||||
{
|
||||
static $countries = null;
|
||||
|
||||
if (is_null($countries))
|
||||
{
|
||||
$countries = array();
|
||||
$countries_lang = $this->getLanguage()->getCountries();
|
||||
$countries_default = $this->getLanguage(self::DEFAULT_ISO)->getCountries();
|
||||
$xml = simplexml_load_file(_PS_INSTALL_DATA_PATH_.'xml/country.xml');
|
||||
foreach ($xml->entities->country as $country)
|
||||
{
|
||||
$iso = strtolower((string)$country['iso_code']);
|
||||
$countries[$iso] = isset($countries_lang[$iso]) ? $countries_lang[$iso] : $countries_default[$iso];
|
||||
}
|
||||
asort($countries);
|
||||
}
|
||||
|
||||
return $countries;
|
||||
}
|
||||
|
||||
public function getFixtureTranslation($iso, $key)
|
||||
{
|
||||
$translation = $this->getLanguage($iso)->getFixtureTranslation($key);
|
||||
if (is_null($translation))
|
||||
$translation = $this->getLanguage(self::DEFAULT_ISO)->getFixtureTranslation($key);
|
||||
return $translation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
abstract class InstallAbstractModel
|
||||
{
|
||||
/**
|
||||
* @var InstallLanguages
|
||||
*/
|
||||
public $language;
|
||||
|
||||
/**
|
||||
* @var FileLogger
|
||||
*/
|
||||
public $logger;
|
||||
|
||||
/**
|
||||
* @var array List of errors
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->language = InstallLanguages::getInstance();
|
||||
|
||||
$this->logger = new FileLogger();
|
||||
$this->logger->setFilename(_PS_ROOT_DIR_.'/log/'.@date('Ymd').'_installation.log');
|
||||
}
|
||||
|
||||
public function setError($errors)
|
||||
{
|
||||
if (!is_array($errors))
|
||||
$errors = array($errors);
|
||||
|
||||
foreach ($errors as $error)
|
||||
{
|
||||
$this->errors[] = $error;
|
||||
$this->logger->logError($error);
|
||||
}
|
||||
}
|
||||
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Manage session for install script
|
||||
*/
|
||||
class InstallSession
|
||||
{
|
||||
protected static $_instance;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!self::$_instance)
|
||||
self::$_instance = new self();
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
session_name('install_'.md5(__PS_BASE_URI__));
|
||||
session_start();
|
||||
}
|
||||
|
||||
public function __get($varname)
|
||||
{
|
||||
return isset($_SESSION[$varname]) ? $_SESSION[$varname] : null;
|
||||
}
|
||||
|
||||
public function __set($varname, $value)
|
||||
{
|
||||
$_SESSION[$varname] = $value;
|
||||
}
|
||||
|
||||
public function __isset($varname)
|
||||
{
|
||||
return isset($_SESSION[$varname]);
|
||||
}
|
||||
|
||||
public function __unset($varname)
|
||||
{
|
||||
unset($_SESSION[$varname]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class InstallSimplexmlElement extends SimpleXMLElement
|
||||
{
|
||||
/**
|
||||
* Can add SimpleXMLElement values in XML tree
|
||||
*
|
||||
* @see SimpleXMLElement::addChild()
|
||||
*/
|
||||
public function addChild($name, $value = null, $namespace = null)
|
||||
{
|
||||
if ($value instanceof SimplexmlElement)
|
||||
{
|
||||
$content = trim((string)$value);
|
||||
if (strlen($content) > 0)
|
||||
$new_element = parent::addChild($name, str_replace('&', '&', $content), $namespace);
|
||||
else
|
||||
{
|
||||
$new_element = parent::addChild($name);
|
||||
foreach ($value->attributes() as $k => $v)
|
||||
$new_element->addAttribute($k, $v);
|
||||
}
|
||||
|
||||
foreach ($value->children() as $child)
|
||||
$new_element->addChild($child->getName(), $child);
|
||||
}
|
||||
else
|
||||
return parent::addChild($name, str_replace('&', '&', $value), $namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate nice and sweet XML
|
||||
*
|
||||
* @see SimpleXMLElement::asXML()
|
||||
*/
|
||||
public function asXML($filename = null)
|
||||
{
|
||||
$dom = new DOMDocument('1.0');
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
$dom->loadXML(parent::asXML());
|
||||
|
||||
if ($filename)
|
||||
return file_put_contents($filename, $dom->saveXML());
|
||||
return $dom->saveXML();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 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-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class InstallSqlLoader
|
||||
{
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var array List of keywords which will be replaced in queries
|
||||
*/
|
||||
protected $metadata = array();
|
||||
|
||||
/**
|
||||
* @var array List of errors during last parsing
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
/**
|
||||
* @param Db $db
|
||||
*/
|
||||
public function __construct(Db $db = null)
|
||||
{
|
||||
if (is_null($db))
|
||||
$db = Db::getInstance();
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a list of keywords which will be replaced in queries
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function setMetaData(array $data)
|
||||
{
|
||||
foreach ($data as $k => $v)
|
||||
$this->metadata[$k] = $v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a SQL file and execute queries
|
||||
*
|
||||
* @param string $filename
|
||||
* @param bool $stop_when_fail
|
||||
*/
|
||||
public function parse_file($filename, $stop_when_fail = true)
|
||||
{
|
||||
if (!file_exists($filename))
|
||||
throw new PrestashopInstallerException("File $filename not found");
|
||||
|
||||
return $this->parse(file_get_contents($filename), $stop_when_fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and execute a list of SQL queries
|
||||
*
|
||||
* @param string $content
|
||||
* @param bool $stop_when_fail
|
||||
*/
|
||||
public function parse($content, $stop_when_fail = true)
|
||||
{
|
||||
$this->errors = array();
|
||||
|
||||
$content = str_replace(array_keys($this->metadata), array_values($this->metadata), $content);
|
||||
$queries = preg_split('#;\s*[\r\n]+#', $content);
|
||||
foreach ($queries as $query)
|
||||
{
|
||||
$query = trim($query);
|
||||
if (!$query)
|
||||
continue;
|
||||
|
||||
if (!$this->db->execute($query))
|
||||
{
|
||||
$this->errors[] = array(
|
||||
'errno' => $this->db->getNumberError(),
|
||||
'error' => $this->db->getMsgError(),
|
||||
'query' => $query,
|
||||
);
|
||||
|
||||
if ($stop_when_fail)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return count($this->errors) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of errors from last parsing
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user