Skip to content

Commit

Permalink
Merge branch '1.6' of https://github.com/PrestaShop/PrestaShop into 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
anat committed Jul 8, 2014
2 parents 5069d3e + ee1d774 commit 7f6cf2f
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
{extends file="helpers/form/form.tpl"}

{block name="input_row"}
{if $input.name == 'caching_system'}<div id="{$input.name}_wrapper"{if isset($_PS_CACHE_ENABLED_) && !$_PS_CACHE_ENABLED_} style="display: none;"{/if}>{/if}
{if $input.name == 'caching_system'}<div id="{$input.name}_wrapper"{if isset($_PS_CACHE_ENABLED_) && !$_PS_CACHE_ENABLED_} style="display:none"{/if}>{/if}
{if $input.name == 'smarty_caching_type'}<div id="{$input.name}_wrapper"{if isset($fields_value.smarty_cache) && !$fields_value.smarty_cache} style="display:none"{/if}>{/if}
{$smarty.block.parent}
{if $input.name == 'caching_system'}</div>{/if}
{if $input.name == 'caching_system' || $input.name == 'smarty_caching_type'}</div>{/if}
{/block}

{block name="input"}
Expand Down Expand Up @@ -161,6 +162,10 @@
$('#ps_cache_fs_directory_depth').focus();
});

$('input[name="smarty_cache"]').change(function() {
$('#smarty_caching_type_wrapper').css('display', ($(this).val() == 1) ? 'block' : 'none');
});

$('#addMemcachedServer').click(function() {
$('#formMemcachedServer').show();
return false;
Expand Down Expand Up @@ -201,7 +206,7 @@
return false;
});

$('input[name="smarty_force_compile"], input[name="smarty_cache"], input[name="smarty_console"], input[name="smarty_console_key"]').change(function(){
$('input[name="smarty_force_compile"], input[name="smarty_cache"], input[name="smarty_caching_type"], input[name="smarty_console"], input[name="smarty_console_key"]').change(function(){
$('#smarty_up').val(1);
});

Expand Down
12 changes: 9 additions & 3 deletions classes/PrestaShopAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ public function load($classname)
// request a non Core Class load the associated Core class if exists
if (isset($this->index[$classname.'Core']))
require_once($this->root_dir.$this->index[$classname.'Core']['path']);

$class_dir = (isset($this->index[$classname]['override'])
&& $this->index[$classname]['override'] === true) ? _PS_ROOT_DIR_ : $this->root_dir;

if (isset($this->index[$classname]))
require_once($this->root_dir.$this->index[$classname]['path']);
require_once($class_dir.$this->index[$classname]['path']);
}
}
// Call directly ProductCore, ShopCore class
Expand Down Expand Up @@ -184,13 +188,15 @@ protected function getClassesFromDir($path, $host_mode = false)
{
$classes[$m['classname']] = array(
'path' => $path.$file,
'type' => trim($m[1])
'type' => trim($m[1]),
'override' => $host_mode
);

if (substr($m['classname'], -4) == 'Core')
$classes[substr($m['classname'], 0, -4)] = array(
'path' => '',
'type' => $classes[$m['classname']]['type']
'type' => $classes[$m['classname']]['type'],
'override' => $host_mode
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3124,7 +3124,8 @@ public static function getAttributesColorList(Array $products, $have_stock = tru
JOIN `'._DB_PREFIX_.'attribute_group` ag ON (a.id_attribute_group = ag.`id_attribute_group`)
WHERE pa.`id_product` IN ('.implode(array_map('intval', $products), ',').') AND ag.`is_color_group` = 1
GROUP BY pa.`id_product`, `group_by`
'.($check_stock ? 'HAVING qty > 0' : '')
'.($check_stock ? 'HAVING qty > 0' : '').'
ORDER BY a.`id_attribute` ASC;'
)
)
return false;
Expand Down
131 changes: 131 additions & 0 deletions classes/SmartyCacheResourceMysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/*
* 2007-2014 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 [email protected] 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 <[email protected]>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

require_once(_PS_TOOL_DIR_.'smarty/Smarty.class.php');

class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
{
/**
* fetch cached content and its modification time from data source
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param string $content cached content
* @param integer $mtime cache modification timestamp (epoch)
* @return void
*/
protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime)
{
$row = Db::getInstance()->getRow('SELECT modified, content FROM '._DB_PREFIX_.'smarty_cache WHERE id = "'.pSQL($id, true).'"');
if ($row)
{
$content = $row['content'];
$mtime = strtotime($row['modified']);
}
else
{
$content = null;
$mtime = null;
}
}

/**
* Fetch cached content's modification timestamp from data source
*
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content.
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
{
$value = Db::getInstance()->getValue('SELECT modified FROM '._DB_PREFIX_.'smarty_cache WHERE id = "'.pSQL($id, true).'"');
$mtime = strtotime($value);
return $mtime;
}

/**
* Save content to cache
*
* @param string $id unique cache content identifier
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
* @param string $content content to cache
* @return boolean success
*/
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
{
Db::getInstance()->execute('
REPLACE INTO '._DB_PREFIX_.'smarty_cache (id, name, cache_id, compile_id, content)
VALUES (
"'.pSQL($id, true).'",
"'.pSQL($name, true).'",
"'.pSQL($cache_id, true).'",
"'.pSQL($compile_id, true).'",
"'.pSQL($content, true).'"
)');

return (bool)Db::getInstance()->Affected_Rows();
}

/**
* Delete content from cache
*
* @param string $name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @param integer|null $exp_time seconds till expiration or null
* @return integer number of deleted caches
*/
protected function delete($name, $cache_id, $compile_id, $exp_time)
{
// delete the whole cache
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
// returning the number of deleted caches would require a second query to count them
Db::getInstance()->execute('TRUNCATE TABLE '._DB_PREFIX_.'smarty_cache');
return -1;
}

$where = array();
if ($name !== null)
$where[] = 'name = "'.pSQL($name, true).'"';
if ($compile_id !== null)
$where[] = 'compile_id = "'.pSQL($compile_id, true).'"';
if ($exp_time !== null)
$where[] = 'modified < DATE_SUB(NOW(), INTERVAL '.(int)$exp_time.' SECOND)';
if ($cache_id !== null)
$where[] = '(cache_id = "'.pSQL($cache_id, true).'" OR cache_id LIKE "'.pSQL($cache_id .'|%', true).'")';

Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'smarty_cache WHERE ' . implode(' AND ', $where));
return Db::getInstance()->Affected_Rows();
}
}
5 changes: 5 additions & 0 deletions config/smarty.config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
$smarty->use_sub_dirs = true;
$smarty->setConfigDir(_PS_SMARTY_DIR_.'configs');
$smarty->caching = false;
if (Configuration::get('PS_SMARTY_CACHING_TYPE') == 'mysql')
{
include(_PS_CLASS_DIR_.'/SmartyCacheResourceMysql.php');
$smarty->caching_type = 'mysql';
}
$smarty->force_compile = (Configuration::get('PS_SMARTY_FORCE_COMPILE') == _PS_SMARTY_FORCE_COMPILE_) ? true : false;
$smarty->compile_check = (Configuration::get('PS_SMARTY_FORCE_COMPILE') >= _PS_SMARTY_CHECK_COMPILE_) ? true : false;

Expand Down
20 changes: 20 additions & 0 deletions controllers/admin/AdminPerformanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ public function initFieldsetSmarty()
),
'hint' => $this->l('Should be enabled except for debugging.')
),
array(
'type' => 'radio',
'label' => $this->l('Caching type'),
'name' => 'smarty_caching_type',
'values' => array(
array(
'id' => 'filesystem',
'value' => 'filesystem',
'label' => $this->l('File System').(is_writable(_PS_CACHE_DIR_.'smarty/cache') ? '' : ' '.sprintf($this->l('(the directory %s must be writable)'), realpath(_PS_CACHE_DIR_.'smarty/cache')))
),
array(
'id' => 'mysql',
'value' => 'mysql',
'label' => $this->l('MySQL')
),

)
),
),
'submit' => array(
'title' => $this->l('Save')
Expand All @@ -98,6 +116,7 @@ public function initFieldsetSmarty()

$this->fields_value['smarty_force_compile'] = Configuration::get('PS_SMARTY_FORCE_COMPILE');
$this->fields_value['smarty_cache'] = Configuration::get('PS_SMARTY_CACHE');
$this->fields_value['smarty_caching_type'] = Configuration::get('PS_SMARTY_CACHING_TYPE');
$this->fields_value['smarty_console'] = Configuration::get('PS_SMARTY_CONSOLE');
$this->fields_value['smarty_console_key'] = Configuration::get('PS_SMARTY_CONSOLE_KEY');
}
Expand Down Expand Up @@ -671,6 +690,7 @@ public function postProcess()
{
Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
Configuration::updateValue('PS_SMARTY_CACHING_TYPE', Tools::getValue('smarty_caching_type', 0));
$redirectAdmin = true;
}
else
Expand Down
15 changes: 13 additions & 2 deletions install-dev/data/db_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,6 @@ CREATE TABLE `PREFIX_tab_module_preference` (
PRIMARY KEY (`id_carrier`, `id_tax_rules_group`, `id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;


CREATE TABLE `PREFIX_order_invoice_payment` (
`id_order_invoice` int(11) unsigned NOT NULL,
`id_order_payment` int(11) unsigned NOT NULL,
Expand All @@ -2513,4 +2512,16 @@ CREATE TABLE `PREFIX_order_invoice_payment` (
KEY `id_order` (`id_order`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;


CREATE TABLE `PREFIX_smarty_cache` (
`id_smarty_cache` char(40) NOT NULL,
`name` varchar(250) NOT NULL,
`cache_id` varchar(250) DEFAULT NULL,
`compile_id` varchar(250) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`content` longtext NOT NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `cache_id` (`cache_id`),
KEY `compile_id` (`compile_id`),
KEY `modified` (`modified`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
18 changes: 18 additions & 0 deletions install-dev/upgrade/sql/1.6.0.10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SET NAMES 'utf8';

CREATE TABLE `PREFIX_smarty_cache` (
`id_smarty_cache` char(40) NOT NULL,
`name` varchar(250) NOT NULL,
`cache_id` varchar(250) DEFAULT NULL,
`compile_id` varchar(250) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`content` longtext NOT NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `cache_id` (`cache_id`),
KEY `compile_id` (`compile_id`),
KEY `modified` (`modified`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;

INSERT INTO `PREFIX_configuration` (`name` , `value` , `date_add` , `date_upd`)
VALUES ('PS_SMARTY_CACHING_TYPE', 'filesystem', NOW(), NOW());

0 comments on commit 7f6cf2f

Please sign in to comment.