// Merge -> revision 8720
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8722 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -2267,22 +2267,26 @@ abstract class AdminTabCore
|
||||
* Display flags in forms for translations
|
||||
*
|
||||
* @param array $languages All languages available
|
||||
* @param integer $defaultLanguage Default language id
|
||||
* @param integer $default_language Default language id
|
||||
* @param string $ids Multilingual div ids in form
|
||||
* @param string $id Current div id]
|
||||
* #param boolean $return define the return way : false for a display, true for a return
|
||||
* @param boolean $return define the return way : false for a display, true for a return
|
||||
* @param boolean $use_vars_instead_of_ids use an js vars instead of ids seperate by "¤"
|
||||
*/
|
||||
public function displayFlags($languages, $defaultLanguage, $ids, $id, $return = false)
|
||||
public function displayFlags($languages, $default_language, $ids, $id, $return = false, $use_vars_instead_of_ids = false)
|
||||
{
|
||||
if (sizeof($languages) == 1)
|
||||
return false;
|
||||
$output = '
|
||||
<div class="displayed_flag">
|
||||
<img src="../img/l/'.$defaultLanguage.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
|
||||
<img src="../img/l/'.$default_language.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
|
||||
</div>
|
||||
<div id="languages_'.$id.'" class="language_flags">
|
||||
'.$this->l('Choose language:').'<br /><br />';
|
||||
foreach ($languages as $language)
|
||||
if($use_vars_instead_of_ids)
|
||||
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
else
|
||||
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
$output .= '</div>';
|
||||
|
||||
|
||||
+40
-20
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -26,25 +26,25 @@
|
||||
*/
|
||||
|
||||
class AttributeCore extends ObjectModel
|
||||
{
|
||||
{
|
||||
/** @var integer Group id which attribute belongs */
|
||||
public $id_attribute_group;
|
||||
|
||||
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
public $color;
|
||||
public $position;
|
||||
public $default;
|
||||
|
||||
|
||||
protected $fieldsRequired = array('id_attribute_group');
|
||||
protected $fieldsValidate = array('id_attribute_group' => 'isUnsignedId', 'color' => 'isColor', 'position' => 'isInt');
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
protected $fieldsSizeLang = array('name' => 64);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
|
||||
|
||||
protected $table = 'attribute';
|
||||
protected $identifier = 'id_attribute';
|
||||
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'objectsNodeName' => 'product_option_values',
|
||||
'objectNodeName' => 'product_option_value',
|
||||
@@ -52,14 +52,14 @@ class AttributeCore extends ObjectModel
|
||||
'id_attribute_group' => array('xlink_resource'=> 'product_options'),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->image_dir = _PS_COL_IMG_DIR_;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
@@ -70,7 +70,7 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check then return multilingual fields for database interaction
|
||||
*
|
||||
@@ -96,10 +96,30 @@ class AttributeCore extends ObjectModel
|
||||
if (Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(', ', $combinationIds).')') === false)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Reinitializing position */
|
||||
$this->cleanPositions((int)$this->id_attribute_group);
|
||||
|
||||
return parent::delete();
|
||||
$return = parent::delete();
|
||||
if ($return)
|
||||
Module::hookExec('afterDeleteAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
{
|
||||
$return = parent::update($nullValues);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
$return = parent::add($autodate, $nullValues);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +142,7 @@ class AttributeCore extends ObjectModel
|
||||
'.($notNull ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').'
|
||||
ORDER BY agl.`name` ASC, a.`position` ASC');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get quantity for a given attribute combinaison
|
||||
* Check if quantity is enough to deserve customer
|
||||
@@ -158,9 +178,9 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT SUM(quantity) as quantity
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
|
||||
|
||||
if ($row['quantity'] !== NULL)
|
||||
return (int)$row['quantity'];
|
||||
return false;
|
||||
@@ -179,7 +199,7 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
$id_product = (int)$arr['id_product'];
|
||||
$qty = self::getAttributeQty($id_product);
|
||||
|
||||
|
||||
if ($qty !== false)
|
||||
{
|
||||
$arr['quantity'] = (int)$qty;
|
||||
@@ -215,9 +235,9 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
$minimal_quantity = Db::getInstance()->getValue('
|
||||
SELECT `minimal_quantity`
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` = '.(int)$id_product_attribute);
|
||||
|
||||
|
||||
if ($minimal_quantity > 1)
|
||||
return (int)$minimal_quantity;
|
||||
return false;
|
||||
@@ -262,7 +282,7 @@ class AttributeCore extends ObjectModel
|
||||
WHERE `id_attribute` = '.(int)$movedAttribute['id_attribute'].'
|
||||
AND `id_attribute_group`='.(int)$movedAttribute['id_attribute_group']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reorder attribute position in group $id_attribute_group.
|
||||
* Call it after deleting an attribute from a group.
|
||||
@@ -299,9 +319,9 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
/**
|
||||
* getHigherPosition
|
||||
*
|
||||
*
|
||||
* Get the higher attribute position from a group attribute
|
||||
*
|
||||
*
|
||||
* @param integer $id_attribute_group
|
||||
* @return integer $position
|
||||
*/
|
||||
@@ -309,7 +329,7 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
$sql = 'SELECT `position`
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE id_attribute_group = '.(int)$id_attribute_group.'
|
||||
WHERE id_attribute_group = '.(int)$id_attribute_group.'
|
||||
ORDER BY position DESC';
|
||||
return ((DB::getInstance()->getValue($sql)!==false)) ? DB::getInstance()->getValue($sql) : -1;
|
||||
}
|
||||
|
||||
+10
-23
@@ -1206,33 +1206,20 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
|
||||
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT)
|
||||
{
|
||||
$shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight(), $id_zone);
|
||||
|
||||
if (!isset($tmp))
|
||||
$tmp = $shipping;
|
||||
|
||||
if ($shipping <= $tmp)
|
||||
{
|
||||
$id_carrier = (int)($row['id_carrier']);
|
||||
$tmp = $shipping;
|
||||
}
|
||||
}
|
||||
else // by price
|
||||
{
|
||||
else
|
||||
$shipping = $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int)($this->id_currency));
|
||||
|
||||
if (!isset($tmp))
|
||||
$tmp = $shipping;
|
||||
if (!isset($minShippingPrice))
|
||||
$minShippingPrice = $shipping;
|
||||
|
||||
if ($shipping <= $tmp)
|
||||
if ($shipping <= $minShippingPrice)
|
||||
{
|
||||
$id_carrier = (int)($row['id_carrier']);
|
||||
$tmp = $shipping;
|
||||
$minShippingPrice = $shipping;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($id_carrier))
|
||||
$id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
|
||||
@@ -1701,13 +1688,13 @@ class CartCore extends ObjectModel
|
||||
LEFT JOIN '._DB_PREFIX_.'customized_data cd ON cd.id_customization = c.id_customization
|
||||
WHERE c.id_cart = '.(int)$this->id);
|
||||
|
||||
// Group line by id_customization
|
||||
// Get datas from customization table
|
||||
$customsById = array();
|
||||
foreach ($customs AS $custom)
|
||||
{
|
||||
if(!isset($customsById[$custom['id_customization']]))
|
||||
$customsById[$custom['id_customization']] = array();
|
||||
$customsById[$custom['id_customization']][] = $custom;
|
||||
$customsById[$custom['id_customization']] = array('id_product_attribute' => $custom['id_product_attribute'],
|
||||
'id_product' => $custom['id_product'], 'quantity' => $custom['quantity']);
|
||||
}
|
||||
|
||||
// Insert new customizations
|
||||
@@ -1716,8 +1703,8 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'customization` (id_cart, id_product_attribute, id_product, quantity)
|
||||
VALUES('.(int)$cart->id.', '.(int)$custom['id_product_attribute'].', '.(int)$custom['id_product'].', '.(int)$custom['quantity'].')');
|
||||
$custom_ids[$custom['id_customization']] = Db::getInstance(_PS_USE_SQL_SLAVE_)->Insert_ID();
|
||||
VALUES('.(int)$cart->id.', '.(int)$val['id_product_attribute'].', '.(int)$val['id_product'].', '.(int)$val['quantity'].')');
|
||||
$custom_ids[$customizationId] = Db::getInstance(_PS_USE_SQL_SLAVE_)->Insert_ID();
|
||||
}
|
||||
|
||||
// Insert customized_data
|
||||
|
||||
+16
-8
@@ -399,19 +399,27 @@ class CategoryCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-calculate the levels of all childs
|
||||
* Updates level_depth for all children of the given id_category
|
||||
*
|
||||
* @param integer $id_category parent category
|
||||
*/
|
||||
public function recalculateLevelDepth($id_category)
|
||||
{
|
||||
/* Gets all childs */
|
||||
$categories = Db::getInstance()->ExecuteS('SELECT id_category, id_parent, level_depth FROM '._DB_PREFIX_.'category
|
||||
WHERE id_parent = '.$id_category);
|
||||
$level = Db::getInstance()->getRow('SELECT level_depth FROM '._DB_PREFIX_.'category
|
||||
WHERE id_category = '.$id_category);
|
||||
/* Update level of depth for all childs */
|
||||
/* Gets all children */
|
||||
$categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT id_category, id_parent, level_depth
|
||||
FROM '._DB_PREFIX_.'category
|
||||
WHERE id_parent = '.(int)$id_category);
|
||||
/* Gets level_depth */
|
||||
$level = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT level_depth
|
||||
FROM '._DB_PREFIX_.'category
|
||||
WHERE id_category = '.(int)$id_category);
|
||||
/* Updates level_depth for all children */
|
||||
foreach ($categories as $sub_category)
|
||||
{
|
||||
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'category
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
|
||||
UPDATE '._DB_PREFIX_.'category
|
||||
SET level_depth = '.($level['level_depth'] + 1).'
|
||||
WHERE id_category = '.$sub_category['id_category']);
|
||||
/* Recursive call */
|
||||
|
||||
@@ -279,7 +279,7 @@ class CustomerCore extends ObjectModel
|
||||
*
|
||||
* @param string $email e-mail
|
||||
* @param $return_id boolean
|
||||
* @param $ignoreGuest boolean, for exclure guest customer
|
||||
* @param $ignoreGuest boolean, to exclude guest customer
|
||||
* @return Customer ID if found, false otherwise
|
||||
*/
|
||||
static public function customerExists($email, $return_id = false, $ignoreGuest = true, Shop $shop = null)
|
||||
|
||||
@@ -167,10 +167,30 @@ class FeatureValueCore extends ObjectModel
|
||||
return (int)$id_feature_value;
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
$return = parent::add($autodate, $nullValues);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
/* Also delete related products */
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'feature_product` WHERE `id_feature_value` = '.(int)$this->id);
|
||||
return parent::delete();
|
||||
$return = parent::delete();
|
||||
|
||||
if ($return)
|
||||
Module::hookExec('afterDeleteFeatureValue', array('id_feature_value' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
{
|
||||
$return = parent::update($nullValues);
|
||||
if ($return)
|
||||
Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -599,6 +599,11 @@ class FrontControllerCore extends ControllerCore
|
||||
asort($nArray);
|
||||
$this->n = abs((int)(Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) AND $this->context->cookie->nb_item_per_page >= 10) ? $this->context->cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE'))))));
|
||||
$this->p = abs((int)(Tools::getValue('p', 1)));
|
||||
|
||||
$current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
|
||||
//delete parameter page
|
||||
$current_url = preg_replace('/(\?)?(&)?p=\d+/', '$1', $current_url);
|
||||
|
||||
$range = 2; /* how many pages around page selected */
|
||||
|
||||
if ($this->p < 0)
|
||||
@@ -625,7 +630,8 @@ class FrontControllerCore extends ControllerCore
|
||||
'nArray' => $nArray,
|
||||
'range' => (int)($range),
|
||||
'start' => (int)($start),
|
||||
'stop' => (int)($stop)
|
||||
'stop' => (int)($stop),
|
||||
'current_url' => $current_url
|
||||
);
|
||||
$this->context->smarty->assign($pagination_infos);
|
||||
}
|
||||
|
||||
@@ -56,11 +56,7 @@ class HelpAccessCore
|
||||
$tooltip = '';
|
||||
$url = HelpAccess::URL.'/documentation/renderIcon?label='.$label.'&iso_lang='.$iso_lang.'&country='.$country.'&version='.$version;
|
||||
|
||||
$ctx = stream_context_create(array(
|
||||
'http' => array(
|
||||
'timeout' => 10
|
||||
)
|
||||
));
|
||||
$ctx = @stream_context_create(array('http' => array('timeout' => 10)));
|
||||
|
||||
$res = @file_get_contents($url, 0, $ctx);
|
||||
|
||||
|
||||
+9
-5
@@ -66,7 +66,7 @@ abstract class ModuleCore
|
||||
/** @var string Message display before uninstall a module */
|
||||
public $beforeUninstall = NULL;
|
||||
|
||||
public $_errors = false;
|
||||
protected $_errors = false;
|
||||
|
||||
protected $table = 'module';
|
||||
|
||||
@@ -296,22 +296,26 @@ abstract class ModuleCore
|
||||
* Display flags in forms for translations
|
||||
*
|
||||
* @param array $languages All languages available
|
||||
* @param integer $defaultLanguage Default language id
|
||||
* @param integer $default_language Default language id
|
||||
* @param string $ids Multilingual div ids in form
|
||||
* @param string $id Current div id]
|
||||
* #param boolean $return define the return way : false for a display, true for a return
|
||||
* @param boolean $return define the return way : false for a display, true for a return
|
||||
* @param boolean $use_vars_instead_of_ids use an js vars instead of ids seperate by "¤"
|
||||
*/
|
||||
public function displayFlags($languages, $defaultLanguage, $ids, $id, $return = false)
|
||||
public function displayFlags($languages, $default_language, $ids, $id, $return = false, $use_vars_instead_of_ids = false)
|
||||
{
|
||||
if (sizeof($languages) == 1)
|
||||
return false;
|
||||
$output = '
|
||||
<div class="displayed_flag">
|
||||
<img src="../img/l/'.$defaultLanguage.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
|
||||
<img src="../img/l/'.$default_language.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
|
||||
</div>
|
||||
<div id="languages_'.$id.'" class="language_flags">
|
||||
'.$this->l('Choose language:').'<br /><br />';
|
||||
foreach ($languages as $language)
|
||||
if($use_vars_instead_of_ids)
|
||||
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
else
|
||||
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
$output .= '</div>';
|
||||
|
||||
|
||||
+7
-4
@@ -556,7 +556,8 @@ class ToolsCore
|
||||
/**
|
||||
* Display an error according to an error code
|
||||
*
|
||||
* @param integer $code Error code
|
||||
* @param string $string Error message
|
||||
* @param boolean $htmlentities By default at true for parsing error message with htmlentities
|
||||
*/
|
||||
public static function displayError($string = 'Fatal error', $htmlentities = true, Context $context = null)
|
||||
{
|
||||
@@ -656,7 +657,7 @@ class ToolsCore
|
||||
/* Categories specifics meta tags */
|
||||
elseif ($id_category = self::getValue('id_category'))
|
||||
{
|
||||
$page_number = self::getValue('p');
|
||||
$page_number = (int)self::getValue('p');
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`, `description`
|
||||
FROM `'._DB_PREFIX_.'category_lang` cl
|
||||
@@ -665,6 +666,8 @@ class ToolsCore
|
||||
{
|
||||
if (empty($row['meta_description']))
|
||||
$row['meta_description'] = strip_tags($row['description']);
|
||||
|
||||
// Paginate title
|
||||
if (!empty($row['meta_title']))
|
||||
$row['meta_title'] = $row['meta_title'].(!empty($page_number) ? ' ('.$page_number.')' : '').' - '.Configuration::get('PS_SHOP_NAME');
|
||||
else
|
||||
@@ -677,7 +680,7 @@ class ToolsCore
|
||||
/* Manufacturers specifics meta tags */
|
||||
elseif ($id_manufacturer = self::getValue('id_manufacturer'))
|
||||
{
|
||||
$page_number = self::getValue('p');
|
||||
$page_number = (int)self::getValue('p');
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `name`, `meta_title`, `meta_description`, `meta_keywords`
|
||||
FROM `'._DB_PREFIX_.'manufacturer_lang` ml
|
||||
@@ -1178,7 +1181,7 @@ class ToolsCore
|
||||
public static function file_get_contents($url, $useIncludePath = false, $streamContext = NULL, $curlTimeOut = 5)
|
||||
{
|
||||
if ($streamContext == NULL)
|
||||
$streamContext = stream_context_create(array('http' => array('timeout' => 5)));
|
||||
$streamContext = @stream_context_create(array('http' => array('timeout' => 5)));
|
||||
|
||||
if (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')))
|
||||
return @file_get_contents($url, $useIncludePath, $streamContext);
|
||||
|
||||
+61
-59
@@ -25,20 +25,19 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class UpgraderCore{
|
||||
class UpgraderCore
|
||||
{
|
||||
const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24;
|
||||
public $rss_version_link = 'http://www.prestashop.com/xml/version.xml';
|
||||
public $rss_version_link = 'http://www.prestashop.com/xml/upgrader.xml';
|
||||
public $rss_md5file_link_dir = 'http://www.prestashop.com/xml/md5/';
|
||||
/**
|
||||
* link contains hte url where to download the file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $needUpgrade = false;
|
||||
private $noRefresh = false;
|
||||
private $changedFiles = array();
|
||||
private $missingFiles = array();
|
||||
private $versionIsModified = false;
|
||||
private $need_upgrade = false;
|
||||
private $changed_files = array();
|
||||
private $missing_files = array();
|
||||
|
||||
public $version_name;
|
||||
public $version_num;
|
||||
@@ -50,18 +49,9 @@ class UpgraderCore{
|
||||
|
||||
public function __get($var)
|
||||
{
|
||||
if($var == 'needUpgrade')
|
||||
if ($var == 'need_upgrade')
|
||||
return $this->isLastVersion();
|
||||
}
|
||||
/**
|
||||
* we need to checkPSVersion when we use that class
|
||||
* @param boolean noRefresh if true, checkPSVersion will not refresh its information
|
||||
* @return object Upgrader
|
||||
*/
|
||||
public function __construct($noRefresh = false)
|
||||
{
|
||||
$this->noRefresh = (bool)$noRefresh;
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadLast download the last version of PrestaShop and save it in $dest/$filename
|
||||
@@ -87,7 +77,7 @@ class UpgraderCore{
|
||||
if (empty($this->link))
|
||||
$this->checkPSVersion();
|
||||
|
||||
return $this->needUpgrade;
|
||||
return $this->need_upgrade;
|
||||
|
||||
}
|
||||
|
||||
@@ -100,13 +90,15 @@ class UpgraderCore{
|
||||
{
|
||||
if (empty($this->link))
|
||||
{
|
||||
|
||||
$lastCheck = Configuration::get('PS_LAST_VERSION_CHECK');
|
||||
if (class_exists('Configuration'))
|
||||
$last_check = Configuration::get('PS_LAST_VERSION_CHECK');
|
||||
else
|
||||
$last_check = 0;
|
||||
// if we use the autoupgrade process, we will never refresh it
|
||||
// except if no check has been done before
|
||||
if ($force OR ($lastCheck < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS)) )
|
||||
if ($force || ($last_check < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS)))
|
||||
{
|
||||
libxml_set_streams_context(stream_context_create(array('http' => array('timeout' => 3))));
|
||||
libxml_set_streams_context(@stream_context_create(array('http' => array('timeout' => 3))));
|
||||
if ($feed = @simplexml_load_file($this->rss_version_link))
|
||||
{
|
||||
|
||||
@@ -118,7 +110,7 @@ class UpgraderCore{
|
||||
$this->autoupgrade = (int)$feed->autoupgrade;
|
||||
$this->autoupgrade_module = (int)$feed->autoupgrade_module;
|
||||
$this->desc = (string)$feed->desc ;
|
||||
$configLastVersion = array(
|
||||
$config_last_version = array(
|
||||
'name' => $this->version_name,
|
||||
'num' => $this->version_num,
|
||||
'link' => $this->link,
|
||||
@@ -128,22 +120,24 @@ class UpgraderCore{
|
||||
'changelog' => $this->changelog,
|
||||
'desc' => $this->desc
|
||||
);
|
||||
|
||||
Configuration::updateValue('PS_LAST_VERSION',serialize($configLastVersion));
|
||||
if (class_exists('Configuration'))
|
||||
{
|
||||
Configuration::updateValue('PS_LAST_VERSION', serialize($config_last_version));
|
||||
Configuration::updateValue('PS_LAST_VERSION_CHECK',time());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$lastVersionCheck = @unserialize(Configuration::get('PS_LAST_VERSION'));
|
||||
$this->version_name = $lastVersionCheck['name'];
|
||||
$this->version_num = $lastVersionCheck['num'];
|
||||
$this->link = $lastVersionCheck['link'];
|
||||
$this->autoupgrade = $lastVersionCheck['autoupgrade'];
|
||||
$this->autoupgrade_module = $lastVersionCheck['autoupgrade_module'];
|
||||
$this->md5 = $lastVersionCheck['md5'];
|
||||
$this->desc = $lastVersionCheck['desc'];
|
||||
$this->changelog = $lastVersionCheck['changelog'];
|
||||
$last_version_check = @unserialize(Configuration::get('PS_LAST_VERSION'));
|
||||
$this->version_name = $last_version_check['name'];
|
||||
$this->version_num = $last_version_check['num'];
|
||||
$this->link = $last_version_check['link'];
|
||||
$this->autoupgrade = $last_version_check['autoupgrade'];
|
||||
$this->autoupgrade_module = $last_version_check['autoupgrade_module'];
|
||||
$this->md5 = $last_version_check['md5'];
|
||||
$this->desc = $last_version_check['desc'];
|
||||
$this->changelog = $last_version_check['changelog'];
|
||||
}
|
||||
}
|
||||
// retro-compatibility :
|
||||
@@ -151,7 +145,7 @@ class UpgraderCore{
|
||||
// false otherwise
|
||||
if (version_compare(_PS_VERSION_, $this->version_num, '<'))
|
||||
{
|
||||
$this->needUpgrade = true;
|
||||
$this->need_upgrade = true;
|
||||
return array('name' => $this->version_name, 'link' => $this->link);
|
||||
}
|
||||
else
|
||||
@@ -160,61 +154,69 @@ class UpgraderCore{
|
||||
|
||||
public function getChangedFilesList()
|
||||
{
|
||||
$checksum = simplexml_load_file($this->rss_md5file_link_dir._PS_VERSION_.'.xml');
|
||||
if (count($this->changed_files) == 0)
|
||||
{
|
||||
$checksum = @simplexml_load_file($this->rss_md5file_link_dir._PS_VERSION_.'.xml');
|
||||
if ($checksum === false)
|
||||
throw new Exception('No checksum xml file for your Prestashop version');
|
||||
$this->browseXmlAndCompare($checksum);
|
||||
|
||||
return $this->changedFiles;
|
||||
return false;
|
||||
else
|
||||
$this->browseXmlAndCompare($checksum->ps_root_dir[0]);
|
||||
}
|
||||
return $this->changed_files;
|
||||
}
|
||||
protected function addChangedFile($path)
|
||||
{
|
||||
$this->versionIsModified = true;
|
||||
$this->changedFiles[] = $path;
|
||||
$this->version_is_modified = true;
|
||||
$this->changed_files[] = $path;
|
||||
//array_unique($this->changed_files);
|
||||
}
|
||||
|
||||
protected function addMissingFile($path)
|
||||
{
|
||||
$this->versionIsModified = true;
|
||||
$this->missingFiles[] = $path;
|
||||
$this->version_is_modified = true;
|
||||
$this->missing_files[] = $path;
|
||||
//array_unique($this->missingFile);
|
||||
}
|
||||
|
||||
protected function browseXmlAndCompare($node, &$currentPath = array(), $level = 0)
|
||||
protected function browseXmlAndCompare($node, &$current_path = array(), $level = 1)
|
||||
{
|
||||
foreach ($node as $key => $child)
|
||||
{
|
||||
if (is_object($child) && $child->getName() != 'md5file')
|
||||
if (is_object($child) && $child->getName() == 'dir')
|
||||
{
|
||||
$level += 1;
|
||||
$currentPath[$level] = $child->getName();
|
||||
$this->browseXmlAndCompare($child, $currentPath, $level);
|
||||
$level -= 1;
|
||||
$current_path[$level] = (string)$child['name'];
|
||||
$this->browseXmlAndCompare($child, $current_path, $level + 1);
|
||||
}
|
||||
else
|
||||
else if (is_object($child) && $child->getName() == 'md5file')
|
||||
{
|
||||
$path = '';
|
||||
for ($i=1;$i<=$level;$i++)
|
||||
$path .= $currentPath[$i].'/';
|
||||
$path .= (string)$child->attributes()->name;
|
||||
$path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR;
|
||||
for ($i = 1; $i < $level; $i++)
|
||||
$path .= $current_path[$i].'/';
|
||||
$path .= (string)$child['name'];
|
||||
$path = str_replace('ps_root_dir',_PS_ROOT_DIR_,$path);
|
||||
|
||||
// replace default admin dir by current one
|
||||
$path = str_replace(_PS_ROOT_DIR_.'/admin', _PS_ADMIN_DIR_, $path);
|
||||
if(!file_exists($path))
|
||||
$this->addMissingFile($path);
|
||||
else if (!$this->compareChecksum($path, (string)$child->attributes()->sum))
|
||||
else if (!$this->compareChecksum($path, (string)$child))
|
||||
$this->addChangedFile($path);
|
||||
// else, file is original (and ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function compareChecksum($path, $originalSum)
|
||||
protected function compareChecksum($path, $original_sum)
|
||||
{
|
||||
if (md5_file($path) == $originalSum)
|
||||
if (md5_file($path) == $original_sum)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isAuthenticPrestashopVersion()
|
||||
{
|
||||
return !$this->versionIsModified;
|
||||
$this->getChangedFilesList();
|
||||
return !$this->version_is_modified;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user