// Merge -> revision 8952
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8957 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -828,7 +828,7 @@ abstract class AdminTabCore
|
||||
$type = (array_key_exists('filter_type', $field) ? $field['filter_type'] : (array_key_exists('type', $field) ? $field['type'] : false));
|
||||
if (($type == 'date' OR $type == 'datetime') AND is_string($value))
|
||||
$value = unserialize($value);
|
||||
$key = isset($tmpTab[1]) ? $tmpTab[0].'.'.$tmpTab[1] : $tmpTab[0];
|
||||
$key = isset($tmpTab[1]) ? $tmpTab[0].'.`'.bqSQL($tmpTab[1]).'`' : '`'.bqSQL($tmpTab[0]).'`';
|
||||
if (array_key_exists('tmpTableFilter', $field))
|
||||
$sqlFilter = & $this->_tmpTableFilter;
|
||||
elseif (array_key_exists('havingFilter', $field))
|
||||
@@ -844,7 +844,7 @@ abstract class AdminTabCore
|
||||
if (!Validate::isDate($value[0]))
|
||||
$this->_errors[] = Tools::displayError('\'from:\' date format is invalid (YYYY-MM-DD)');
|
||||
else
|
||||
$sqlFilter .= ' AND '.bqSQL($key).' >= \''.pSQL(Tools::dateFrom($value[0])).'\'';
|
||||
$sqlFilter .= ' AND '.$key.' >= \''.pSQL(Tools::dateFrom($value[0])).'\'';
|
||||
}
|
||||
|
||||
if (isset($value[1]) AND !empty($value[1]))
|
||||
@@ -852,7 +852,7 @@ abstract class AdminTabCore
|
||||
if (!Validate::isDate($value[1]))
|
||||
$this->_errors[] = Tools::displayError('\'to:\' date format is invalid (YYYY-MM-DD)');
|
||||
else
|
||||
$sqlFilter .= ' AND '.bqSQL($key).' <= \''.pSQL(Tools::dateTo($value[1])).'\'';
|
||||
$sqlFilter .= ' AND '.$key.' <= \''.pSQL(Tools::dateTo($value[1])).'\'';
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ abstract class CacheCore
|
||||
{
|
||||
/** @var Cache */
|
||||
protected static $_instance;
|
||||
protected $_keysCached;
|
||||
protected $_keysCached = array();
|
||||
protected $_tablesCached = array();
|
||||
protected $_blackList = array('cart',
|
||||
'cart_discount',
|
||||
|
||||
+7
-5
@@ -98,15 +98,17 @@ class CacheFSCore extends Cache {
|
||||
public function setQuery($query, $result)
|
||||
{
|
||||
$md5_query = md5($query);
|
||||
if (isset($this->_keysCached[$md5_query]))
|
||||
return true;
|
||||
if ($this->isBlacklist($query))
|
||||
return true;
|
||||
$this->_setKeys();
|
||||
if (isset($this->_keysCached[$md5_query]))
|
||||
return true;
|
||||
$key = $this->set($md5_query, $result);
|
||||
if (preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
||||
foreach($res[1] AS $table)
|
||||
if(!isset($this->_tablesCached[$table][$key]))
|
||||
$this->_tablesCached[$table][$key] = true;
|
||||
$this->_writeKeys();
|
||||
}
|
||||
|
||||
public function delete($key, $timeout = 0)
|
||||
@@ -126,7 +128,7 @@ class CacheFSCore extends Cache {
|
||||
|
||||
public function deleteQuery($query)
|
||||
{
|
||||
|
||||
$this->_setKeys();
|
||||
if (preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
||||
foreach ($res[1] AS $table)
|
||||
if (isset($this->_tablesCached[$table]))
|
||||
@@ -138,15 +140,15 @@ class CacheFSCore extends Cache {
|
||||
}
|
||||
unset($this->_tablesCached[$table]);
|
||||
}
|
||||
$this->_writeKeys();
|
||||
}
|
||||
|
||||
public function flush()
|
||||
{
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
private function _writeKeys()
|
||||
{
|
||||
parent::__destruct();
|
||||
|
||||
@file_put_contents($this->getPath().'keysCached', serialize($this->_keysCached));
|
||||
@file_put_contents($this->getPath().'tablesCached', serialize($this->_tablesCached));
|
||||
|
||||
+2
-2
@@ -1288,12 +1288,12 @@ class CartCore extends ObjectModel
|
||||
if (isset($configuration['PS_SHIPPING_HANDLING']) AND $carrier->shipping_handling)
|
||||
$shipping_cost += (float)($configuration['PS_SHIPPING_HANDLING']);
|
||||
|
||||
$shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int)($this->id_currency)));
|
||||
|
||||
// Additional Shipping Cost per product
|
||||
foreach($products AS $product)
|
||||
$shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
|
||||
|
||||
$shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int)($this->id_currency)));
|
||||
|
||||
//get external shipping cost from module
|
||||
if ($carrier->shipping_external)
|
||||
{
|
||||
|
||||
+50
-46
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -28,54 +28,57 @@
|
||||
class EmployeeCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
|
||||
/** @var string Determine employee profile */
|
||||
public $id_profile;
|
||||
|
||||
|
||||
/** @var string employee language */
|
||||
public $id_lang;
|
||||
|
||||
|
||||
/** @var string Lastname */
|
||||
public $lastname;
|
||||
|
||||
|
||||
/** @var string Firstname */
|
||||
public $firstname;
|
||||
|
||||
|
||||
/** @var string e-mail */
|
||||
public $email;
|
||||
|
||||
|
||||
/** @var string Password */
|
||||
public $passwd;
|
||||
|
||||
|
||||
/** @var datetime Password */
|
||||
public $last_passwd_gen;
|
||||
|
||||
|
||||
public $stats_date_from;
|
||||
public $stats_date_to;
|
||||
|
||||
|
||||
/** @var string Display back office background in the specified color */
|
||||
public $bo_color;
|
||||
|
||||
|
||||
/** @var string employee's chosen theme */
|
||||
public $bo_theme;
|
||||
|
||||
|
||||
/** @var string / enum hover or click mode */
|
||||
public $bo_uimode;
|
||||
|
||||
|
||||
/** @var bool, true */
|
||||
public $bo_show_screencast;
|
||||
|
||||
/** @var boolean Status */
|
||||
public $active = 1;
|
||||
|
||||
|
||||
/** @var boolean show screencast */
|
||||
public $show_screencast = 1;
|
||||
|
||||
|
||||
public $remote_addr;
|
||||
|
||||
|
||||
protected $fieldsRequired = array('lastname', 'firstname', 'email', 'passwd', 'id_profile', 'id_lang');
|
||||
protected $fieldsSize = array('lastname' => 32, 'firstname' => 32, 'email' => 128, 'passwd' => 32, 'bo_color' => 32, 'bo_theme' => 32);
|
||||
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
|
||||
'passwd' => 'isPasswdAdmin', 'active' => 'isBool', 'id_profile' => 'isInt', 'bo_color' => 'isColor', 'bo_theme' => 'isGenericName',
|
||||
'bo_uimode' => 'isGenericName', 'show_screencast' => 'isBool');
|
||||
|
||||
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
|
||||
'passwd' => 'isPasswdAdmin', 'active' => 'isBool', 'id_profile' => 'isInt', 'bo_color' => 'isColor', 'bo_theme' => 'isGenericName',
|
||||
'bo_uimode' => 'isGenericName', 'show_screencast' => 'isBool', 'bo_show_screencast' => 'isBool');
|
||||
|
||||
protected $table = 'employee';
|
||||
protected $identifier = 'id_employee';
|
||||
|
||||
@@ -88,12 +91,12 @@ class EmployeeCore extends ObjectModel
|
||||
'passwd' => array('setter' => 'setWsPasswd'),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
|
||||
|
||||
$fields['id_profile'] = (int)$this->id_profile;
|
||||
$fields['id_lang'] = (int)$this->id_lang;
|
||||
$fields['lastname'] = pSQL($this->lastname);
|
||||
@@ -101,21 +104,22 @@ class EmployeeCore extends ObjectModel
|
||||
$fields['email'] = pSQL($this->email);
|
||||
$fields['passwd'] = pSQL($this->passwd);
|
||||
$fields['last_passwd_gen'] = pSQL($this->last_passwd_gen);
|
||||
|
||||
|
||||
if (empty($this->stats_date_from))
|
||||
$this->stats_date_from = date('Y-m-d 00:00:00');
|
||||
$fields['stats_date_from'] = pSQL($this->stats_date_from);
|
||||
|
||||
|
||||
if (empty($this->stats_date_to))
|
||||
$this->stats_date_to = date('Y-m-d 23:59:59');
|
||||
$fields['stats_date_to'] = pSQL($this->stats_date_to);
|
||||
|
||||
|
||||
$fields['bo_color'] = pSQL($this->bo_color);
|
||||
$fields['bo_theme'] = pSQL($this->bo_theme);
|
||||
$fields['bo_uimode'] = pSQL($this->bo_uimode);
|
||||
$fields['bo_show_screencast'] = (int)$this->bo_show_screencast;
|
||||
$fields['active'] = (int)$this->active;
|
||||
$fields['show_screencast'] = (int)$this->show_screencast;
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -124,10 +128,10 @@ class EmployeeCore extends ObjectModel
|
||||
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_BACK').'minutes'));
|
||||
return parent::add($autodate, $nullValues);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return employee instance from its e-mail (optionnaly check password)
|
||||
*
|
||||
*
|
||||
* @param string $email e-mail
|
||||
* @param string $passwd Password is also checked if specified
|
||||
* @return Employee instance
|
||||
@@ -138,7 +142,7 @@ class EmployeeCore extends ObjectModel
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'employee`
|
||||
WHERE `active` = 1
|
||||
AND `email` = \''.pSQL($email).'\'
|
||||
@@ -152,12 +156,12 @@ class EmployeeCore extends ObjectModel
|
||||
$this->{$key} = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public static function employeeExists($email)
|
||||
{
|
||||
if (!Validate::isEmail($email))
|
||||
die (Tools::displayError());
|
||||
|
||||
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `id_employee`
|
||||
FROM `'._DB_PREFIX_.'employee`
|
||||
@@ -166,7 +170,7 @@ class EmployeeCore extends ObjectModel
|
||||
|
||||
/**
|
||||
* Check if employee password is the right one
|
||||
*
|
||||
*
|
||||
* @param string $passwd Password
|
||||
* @return boolean result
|
||||
*/
|
||||
@@ -174,7 +178,7 @@ class EmployeeCore extends ObjectModel
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_employee) OR !Validate::isPasswd($passwd, 8))
|
||||
die (Tools::displayError());
|
||||
|
||||
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT `id_employee`
|
||||
FROM `'._DB_PREFIX_.'employee`
|
||||
@@ -182,24 +186,24 @@ class EmployeeCore extends ObjectModel
|
||||
AND `passwd` = \''.pSQL($passwd).'\'
|
||||
AND active = 1');
|
||||
}
|
||||
|
||||
|
||||
public static function countProfile($id_profile, $activeOnly = false)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'employee`
|
||||
FROM `'._DB_PREFIX_.'employee`
|
||||
WHERE `id_profile` = '.(int)$id_profile.'
|
||||
'.($activeOnly ? ' AND `active` = 1' : ''));
|
||||
}
|
||||
|
||||
|
||||
public function isLastAdmin()
|
||||
{
|
||||
return ($this->id_profile == _PS_ADMIN_PROFILE_
|
||||
AND Employee::countProfile($this->id_profile, true) == 1
|
||||
AND $this->active
|
||||
return ($this->id_profile == _PS_ADMIN_PROFILE_
|
||||
&& Employee::countProfile($this->id_profile, true) == 1
|
||||
&& $this->active
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function setWsPasswd($passwd)
|
||||
{
|
||||
if ($this->id != 0)
|
||||
@@ -211,7 +215,7 @@ class EmployeeCore extends ObjectModel
|
||||
$this->passwd = Tools::encrypt($passwd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check employee informations saved into cookie and return employee validity
|
||||
*
|
||||
@@ -221,12 +225,12 @@ class EmployeeCore extends ObjectModel
|
||||
{
|
||||
/* Employee is valid only if it can be load and if cookie password is the same as database one */
|
||||
return ($this->id
|
||||
AND Validate::isUnsignedId($this->id)
|
||||
AND Employee::checkPassword($this->id, $this->passwd)
|
||||
AND (!isset($this->remote_addr) OR $this->remote_addr == ip2long(Tools::getRemoteAddr()) OR !Configuration::get('PS_COOKIE_CHECKIP'))
|
||||
&& Validate::isUnsignedId($this->id)
|
||||
&& Employee::checkPassword($this->id, $this->passwd)
|
||||
&& (!isset($this->remote_addr) || $this->remote_addr == ip2long(Tools::getRemoteAddr()) || !Configuration::get('PS_COOKIE_CHECKIP'))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logout
|
||||
*/
|
||||
|
||||
+5
-2
@@ -94,6 +94,7 @@ class MCachedCore extends Cache
|
||||
if ($this->isBlacklist($query))
|
||||
return true;
|
||||
$md5_query = md5($query);
|
||||
$this->_setKeys();
|
||||
if (isset($this->_keysCached[$md5_query]))
|
||||
return true;
|
||||
$key = $this->set($md5_query, $result);
|
||||
@@ -101,6 +102,7 @@ class MCachedCore extends Cache
|
||||
foreach($res[1] AS $table)
|
||||
if(!isset($this->_tablesCached[$table][$key]))
|
||||
$this->_tablesCached[$table][$key] = true;
|
||||
$this->_writeKeys();
|
||||
}
|
||||
|
||||
public function delete($key, $timeout = 0)
|
||||
@@ -115,6 +117,7 @@ class MCachedCore extends Cache
|
||||
{
|
||||
if (!$this->_isConnected)
|
||||
return false;
|
||||
$this->_setKeys();
|
||||
if (preg_match_all('/('._DB_PREFIX_.'[a-z_-]*)`?.*/i', $query, $res))
|
||||
foreach ($res[1] AS $table)
|
||||
if (isset($this->_tablesCached[$table]))
|
||||
@@ -126,6 +129,7 @@ class MCachedCore extends Cache
|
||||
}
|
||||
unset($this->_tablesCached[$table]);
|
||||
}
|
||||
$this->_writeKeys();
|
||||
}
|
||||
|
||||
protected function close()
|
||||
@@ -144,9 +148,8 @@ class MCachedCore extends Cache
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
private function _writeKeys()
|
||||
{
|
||||
parent::__destruct();
|
||||
if (!$this->_isConnected)
|
||||
return false;
|
||||
$this->_memcacheObj->set('keysCached', $this->_keysCached, 0, 0);
|
||||
|
||||
+9
-6
@@ -190,12 +190,11 @@ class MailCore
|
||||
public static function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
|
||||
{
|
||||
$swift = NULL;
|
||||
$result = NULL;
|
||||
$result = false;
|
||||
try
|
||||
{
|
||||
if($smtpChecked)
|
||||
{
|
||||
|
||||
$smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, ($smtpEncryption == "off") ? Swift_Connection_SMTP::ENC_OFF : (($smtpEncryption == "tls") ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL));
|
||||
$smtp->setUsername($smtpLogin);
|
||||
$smtp->setpassword($smtpPassword);
|
||||
@@ -209,13 +208,17 @@ class MailCore
|
||||
|
||||
if ($swift->send($message, $to, $from))
|
||||
$result = true;
|
||||
else
|
||||
$result = 999;
|
||||
|
||||
$swift->disconnect();
|
||||
}
|
||||
catch (Swift_Connection_Exception $e) { $result = $e->getCode(); }
|
||||
catch (Swift_Message_MimeException $e) { $result = $e->getCode(); }
|
||||
catch (Swift_ConnectionException $e)
|
||||
{
|
||||
$result = $e->getMessage();
|
||||
}
|
||||
catch (Swift_Message_MimeException $e)
|
||||
{
|
||||
$result = $e->getMessage();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
+15
-3
@@ -637,12 +637,24 @@ abstract class ModuleCore
|
||||
|
||||
if (!$useConfig OR !$xml_exist OR (isset($xml_module->need_instance) AND (int)$xml_module->need_instance == 1) OR $needNewConfigFile)
|
||||
{
|
||||
// If class already exists, don't include the file
|
||||
if (!class_exists($module, false))
|
||||
{
|
||||
$filepath = _PS_MODULE_DIR_.$module.'/'.$module.'.php';
|
||||
$file = trim(file_get_contents(_PS_MODULE_DIR_.$module.'/'.$module.'.php'));
|
||||
if (substr($file, 0, 5) == '<?php')
|
||||
$file = substr($file, 5);
|
||||
if (substr($file, -2) == '?>')
|
||||
$file = substr($file, 0, -2);
|
||||
if (class_exists($module, false) OR eval($file) !== false)
|
||||
// if (false) is a trick to not load the class with "eval".
|
||||
// this way require_once will works correctly
|
||||
if (eval('if (false){ '.$file.' }') !== false)
|
||||
require_once( _PS_MODULE_DIR_.$module.'/'.$module.'.php' );
|
||||
else
|
||||
$errors[] = sprintf(Tools::displayError('%1$s (parse error in %2$s)'), $module, substr($filepath, strlen(_PS_ROOT_DIR_)));
|
||||
}
|
||||
|
||||
if (class_exists($module,false))
|
||||
{
|
||||
$moduleList[$moduleListCursor++] = new $module;
|
||||
if (!$xml_exist OR $needNewConfigFile)
|
||||
@@ -654,7 +666,7 @@ abstract class ModuleCore
|
||||
}
|
||||
}
|
||||
else
|
||||
$errors[] = $module;
|
||||
$errors[] = sprintf(Tools::displayError('%1$s (class missing in %2$s)'), $module, substr($filepath, strlen(_PS_ROOT_DIR_)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,7 +691,7 @@ abstract class ModuleCore
|
||||
|
||||
if ($errors)
|
||||
{
|
||||
echo '<div class="alert error"><h3>'.Tools::displayError('Parse error(s) in module(s)').'</h3><ol>';
|
||||
echo '<div class="alert error"><h3>'.Tools::displayError('The following module(s) couldn\'t be loaded').':</h3><ol>';
|
||||
foreach ($errors AS $error)
|
||||
echo '<li>'.$error.'</li>';
|
||||
echo '</ol></div>';
|
||||
|
||||
+107
-100
@@ -173,7 +173,6 @@ class SearchCore
|
||||
{
|
||||
$word = str_replace('%', '\\%', $word);
|
||||
$word = str_replace('_', '\\_', $word);
|
||||
|
||||
$intersectArray[] = 'SELECT si.id_product
|
||||
FROM '._DB_PREFIX_.'search_word sw
|
||||
LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word
|
||||
@@ -337,6 +336,20 @@ class SearchCore
|
||||
return $features;
|
||||
}
|
||||
|
||||
protected static function getProductsToIndex($nbLanguages, $limit = 50)
|
||||
{
|
||||
// Adjust the limit to get only "whole" products, in every languages (and at least one)
|
||||
$limit = min(1, round($limit / $nbLanguages) * $nbLanguages);
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT p.id_product, pl.id_lang, pl.name pname, p.reference, p.ean13, p.upc, pl.description_short, pl.description, cl.name cname, m.name mname
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON p.id_product = pl.id_product
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default AND pl.id_lang = cl.id_lang)
|
||||
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON m.id_manufacturer = p.id_manufacturer
|
||||
WHERE p.indexed = 0
|
||||
LIMIT '.(int)$limit);
|
||||
}
|
||||
|
||||
public static function indexation($full = false, $id_product = false)
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
@@ -399,15 +412,6 @@ class SearchCore
|
||||
'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE')
|
||||
);
|
||||
|
||||
// All the product not yet indexed are retrieved
|
||||
$sql = 'SELECT p.id_product, pl.id_lang, pl.name pname, p.reference, p.ean13, p.upc, pl.description_short, pl.description, cl.name cname, m.name mname, pl.id_shop
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON p.id_product = pl.id_product
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default AND pl.id_lang = cl.id_lang AND pl.id_shop = cl.id_shop)
|
||||
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON m.id_manufacturer = p.id_manufacturer
|
||||
WHERE p.indexed = 0';
|
||||
$products = $db->ExecuteS($sql, false);
|
||||
|
||||
// Those are kind of global variables required to save the processed data in the database every X occurences, in order to avoid overloading MySQL
|
||||
$countWords = 0;
|
||||
$countProducts = 0;
|
||||
@@ -427,107 +431,110 @@ class SearchCore
|
||||
$wordIdsByWord[$wordId['id_shop']][$wordId['id_lang']]['_'.$wordId['word']] = (int)$wordId['id_word'];
|
||||
}
|
||||
|
||||
// Now each non-indexed product is processed one by one, langage by langage
|
||||
while ($product = $db->nextRow($products))
|
||||
{
|
||||
$product['tags'] = Search::getTags($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||
$product['attributes'] = Search::getAttributes($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||
$product['features'] = Search::getFeatures($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||
|
||||
// Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
|
||||
$pArray = array();
|
||||
foreach ($product AS $key => $value)
|
||||
if (strncmp($key, 'id_', 3))
|
||||
{
|
||||
$words = explode(' ', Search::sanitize($value, (int)$product['id_lang'], true));
|
||||
foreach ($words AS $word)
|
||||
if (!empty($word))
|
||||
{
|
||||
$word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
|
||||
// Remove accents
|
||||
$word = Tools::replaceAccentedChars($word);
|
||||
// Retrieve the number of languages
|
||||
$nbLanguages = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'lang');
|
||||
|
||||
if (!isset($pArray[$word]))
|
||||
$pArray[$word] = 0;
|
||||
$pArray[$word] += $weightArray[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// If we find words that need to be indexed, they're added to the word table in the database
|
||||
if (sizeof($pArray))
|
||||
// Products are processed 50 by 50 in order to avoid overloading MySQL
|
||||
while ($products = Search::getProductsToIndex($nbLanguages, 50) AND count($products) > 0)
|
||||
{
|
||||
// Now each non-indexed product is processed one by one, langage by langage
|
||||
foreach ($products as $product)
|
||||
{
|
||||
$list = '';
|
||||
foreach ($pArray AS $word => $weight)
|
||||
$list .= '\''.$word.'\',';
|
||||
$list = rtrim($list, ',');
|
||||
$product['tags'] = Search::getTags($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||
$product['attributes'] = Search::getAttributes($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||
$product['features'] = Search::getFeatures($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||
|
||||
$queryArray = array();
|
||||
$queryArray2 = array();
|
||||
foreach ($pArray AS $word => $weight)
|
||||
if ($weight AND !isset($wordIdsByWord['_'.$word]))
|
||||
// Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
|
||||
$pArray = array();
|
||||
foreach ($product AS $key => $value)
|
||||
if (strncmp($key, 'id_', 3))
|
||||
{
|
||||
$queryArray[$word] = '('.(int)$product['id_lang'].', '.(int)$product['id_shop'].', \''.pSQL($word).'\')';
|
||||
$queryArray2[] = '\''.pSQL($word).'\'';
|
||||
$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word] = 0;
|
||||
$words = explode(' ', Search::sanitize($value, (int)$product['id_lang'], true));
|
||||
foreach ($words AS $word)
|
||||
if (!empty($word))
|
||||
{
|
||||
$word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
|
||||
// Remove accents
|
||||
$word = Tools::replaceAccentedChars($word);
|
||||
|
||||
if (!isset($pArray[$word]))
|
||||
$pArray[$word] = 0;
|
||||
$pArray[$word] += $weightArray[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$existingWords = $db->ExecuteS('
|
||||
SELECT word FROM '._DB_PREFIX_.'search_word
|
||||
WHERE word IN ('.implode(',', $queryArray2).')
|
||||
AND id_lang = '.(int)$product['id_lang'].' GROUP BY word');
|
||||
|
||||
if($existingWords)
|
||||
foreach($existingWords as $data)
|
||||
unset($queryArray[Tools::replaceAccentedChars($data['word'])]);
|
||||
|
||||
if (count($queryArray))
|
||||
// If we find words that need to be indexed, they're added to the word table in the database
|
||||
if (count($pArray))
|
||||
{
|
||||
// The words are inserted...
|
||||
$db->Execute('
|
||||
INSERT IGNORE INTO '._DB_PREFIX_.'search_word (id_lang, id_shop, word)
|
||||
VALUES '.implode(',',$queryArray));
|
||||
}
|
||||
if (count($queryArray2))
|
||||
{
|
||||
// ...then their IDs are retrieved and added to the cache
|
||||
$addedWords = $db->ExecuteS('
|
||||
SELECT sw.id_word, sw.word
|
||||
FROM '._DB_PREFIX_.'search_word sw
|
||||
WHERE sw.word IN ('.implode(',', $queryArray2).')
|
||||
AND sw.id_lang = '.(int)$product['id_lang'].'
|
||||
AND sw.id_shop = '.(int)$product['id_shop'].'
|
||||
LIMIT '.count($queryArray2));
|
||||
// replace accents from the retrieved words so that words without accents or with differents accents can still be linked
|
||||
foreach ($addedWords AS $wordId)
|
||||
$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.Tools::replaceAccentedChars($wordId['word'])] = (int)$wordId['id_word'];
|
||||
$list = '';
|
||||
foreach ($pArray AS $word => $weight)
|
||||
$list .= '\''.$word.'\',';
|
||||
$list = rtrim($list, ',');
|
||||
|
||||
$queryArray = array();
|
||||
$queryArray2 = array();
|
||||
foreach ($pArray AS $word => $weight)
|
||||
if ($weight AND !isset($wordIdsByWord['_'.$word]))
|
||||
{
|
||||
$queryArray[$word] = '('.(int)$product['id_lang'].', '.(int)$product['id_shop'].', \''.pSQL($word).'\')';
|
||||
$queryArray2[] = '\''.pSQL($word).'\'';
|
||||
$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word] = 0;
|
||||
}
|
||||
|
||||
$existingWords = $db->ExecuteS('
|
||||
SELECT word FROM '._DB_PREFIX_.'search_word
|
||||
WHERE word IN ('.implode(',', $queryArray2).')
|
||||
AND id_lang = '.(int)$product['id_lang'].' GROUP BY word');
|
||||
|
||||
if($existingWords)
|
||||
foreach($existingWords as $data)
|
||||
unset($queryArray[Tools::replaceAccentedChars($data['word'])]);
|
||||
|
||||
if (count($queryArray))
|
||||
{
|
||||
// The words are inserted...
|
||||
$db->Execute('
|
||||
INSERT IGNORE INTO '._DB_PREFIX_.'search_word (id_lang, id_shop, word)
|
||||
VALUES '.implode(',',$queryArray));
|
||||
}
|
||||
if (count($queryArray2))
|
||||
{
|
||||
// ...then their IDs are retrieved and added to the cache
|
||||
$addedWords = $db->ExecuteS('
|
||||
SELECT sw.id_word, sw.word
|
||||
FROM '._DB_PREFIX_.'search_word sw
|
||||
WHERE sw.word IN ('.implode(',', $queryArray2).')
|
||||
AND sw.id_lang = '.(int)$product['id_lang'].'
|
||||
AND sw.id_shop = '.(int)$product['id_shop'].'
|
||||
LIMIT '.count($queryArray2));
|
||||
// replace accents from the retrieved words so that words without accents or with differents accents can still be linked
|
||||
foreach ($addedWords AS $wordId)
|
||||
$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.Tools::replaceAccentedChars($wordId['word'])] = (int)$wordId['id_word'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pArray AS $word => $weight)
|
||||
{
|
||||
if (!$weight)
|
||||
continue;
|
||||
if (!isset($wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word]))
|
||||
continue;
|
||||
if (!$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word])
|
||||
continue;
|
||||
$queryArray3[] = '('.(int)$product['id_product'].','.(int)$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word].','.(int)$weight.')';
|
||||
// Force save every 200 words in order to avoid overloading MySQL
|
||||
if (++$countWords % 200 == 0)
|
||||
Search::saveIndex($queryArray3);
|
||||
}
|
||||
foreach ($pArray AS $word => $weight)
|
||||
{
|
||||
if (!$weight)
|
||||
continue;
|
||||
if (!isset($wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word]))
|
||||
continue;
|
||||
if (!$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word])
|
||||
continue;
|
||||
$queryArray3[] = '('.(int)$product['id_product'].','.(int)$wordIdsByWord[$product['id_shop']][$product['id_lang']]['_'.$word].','.(int)$weight.')';
|
||||
// Force save every 200 words in order to avoid overloading MySQL
|
||||
if (++$countWords % 200 == 0)
|
||||
Search::saveIndex($queryArray3);
|
||||
}
|
||||
|
||||
if (!in_array($product['id_product'], $productsArray))
|
||||
$productsArray[] = (int)$product['id_product'];
|
||||
if (!in_array($product['id_product'], $productsArray))
|
||||
$productsArray[] = (int)$product['id_product'];
|
||||
}
|
||||
Search::setProductsAsIndexed($productsArray);
|
||||
|
||||
// Force save every 50 products in order to avoid overloading MySQL
|
||||
if (++$countProducts % 50 == 0)
|
||||
Search::setProductsAsIndexed($productsArray);
|
||||
}
|
||||
|
||||
// One last save is done at the end in order to save what's left
|
||||
Search::saveIndex($queryArray3);
|
||||
Search::setProductsAsIndexed($productsArray);
|
||||
// One last save is done at the end in order to save what's left
|
||||
Search::saveIndex($queryArray3);
|
||||
}
|
||||
|
||||
// If it has been deleted, the index is created again once the indexation is done
|
||||
if (!$dropIndex)
|
||||
|
||||
+35
-12
@@ -165,18 +165,37 @@ class UpgraderCore
|
||||
}
|
||||
return $this->changed_files;
|
||||
}
|
||||
|
||||
/** populate $this->changed_files with $path
|
||||
* in sub arrays mail, translation and core items
|
||||
* @param string $path filepath to add, relative to _PS_ROOT_DIR_
|
||||
*/
|
||||
protected function addChangedFile($path)
|
||||
{
|
||||
$this->version_is_modified = true;
|
||||
$this->changed_files[] = $path;
|
||||
//array_unique($this->changed_files);
|
||||
|
||||
if (strpos($path, 'mails/') !== false)
|
||||
$this->changed_files['mail'][] = $path;
|
||||
else if (
|
||||
strpos($path, '/en.php') !== false
|
||||
|| strpos($path, '/fr.php') !== false
|
||||
|| strpos($path, '/es.php') !== false
|
||||
|| strpos($path, '/it.php') !== false
|
||||
|| strpos($path, '/de.php') !== false
|
||||
|| strpos($path, 'translations/') !== false
|
||||
)
|
||||
$this->changed_files['translation'][] = $path;
|
||||
else
|
||||
$this->changed_files['core'][] = $path;
|
||||
}
|
||||
|
||||
/** populate $this->missing_files with $path
|
||||
* @param string $path filepath to add, relative to _PS_ROOT_DIR_
|
||||
*/
|
||||
protected function addMissingFile($path)
|
||||
{
|
||||
$this->version_is_modified = true;
|
||||
$this->missing_files[] = $path;
|
||||
//array_unique($this->missingFile);
|
||||
}
|
||||
|
||||
protected function browseXmlAndCompare($node, &$current_path = array(), $level = 1)
|
||||
@@ -190,18 +209,22 @@ class UpgraderCore
|
||||
}
|
||||
else if (is_object($child) && $child->getName() == 'md5file')
|
||||
{
|
||||
$path = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR;
|
||||
// We will store only relative path.
|
||||
// absolute path is only used for file_exists and compare
|
||||
$relative_path = '';
|
||||
for ($i = 1; $i < $level; $i++)
|
||||
$path .= $current_path[$i].'/';
|
||||
$path .= (string)$child['name'];
|
||||
$path = str_replace('ps_root_dir',_PS_ROOT_DIR_,$path);
|
||||
$relative_path .= $current_path[$i].'/';
|
||||
$relative_path .= (string)$child['name'];
|
||||
$fullpath = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR . $relative_path;
|
||||
|
||||
$fullpath = str_replace('ps_root_dir', _PS_ROOT_DIR_, $fullpath);
|
||||
|
||||
// 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))
|
||||
$this->addChangedFile($path);
|
||||
$fullpath = str_replace(_PS_ROOT_DIR_.'/admin', _PS_ADMIN_DIR_, $fullpath);
|
||||
if (!file_exists($fullpath))
|
||||
$this->addMissingFile($relative_path);
|
||||
else if (!$this->compareChecksum($fullpath, (string)$child))
|
||||
$this->addChangedFile($relative_path);
|
||||
// else, file is original (and ok)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user