mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- optimization clear compiled and cached folder completely on detected version change
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
===== 3.1.31-dev ===== (xx.xx.xx)
|
||||
19.09.2016
|
||||
- optimization clear compiled and cached folder completely on detected version change
|
||||
|
||||
15.09.2016
|
||||
- bugfix assigning a variable in if condition by function like {if $value = array_shift($array)} the function got called twice https://github.com/smarty-php/smarty/issues/291
|
||||
- bugfix function plugins called with assign attribute like {foo assign='bar'} did not output returned content because
|
||||
|
@@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.31-dev/23';
|
||||
const SMARTY_VERSION = '3.1.31-dev/24';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
@@ -1005,6 +1005,9 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
if (!$this->_compileDirNormalized) {
|
||||
$this->_normalizeDir('compile_dir', $this->compile_dir);
|
||||
$this->_compileDirNormalized = true;
|
||||
if ($this->_isNewRelease($this->compile_dir)) {
|
||||
$this->clearCompiledTemplate();
|
||||
}
|
||||
}
|
||||
return $this->compile_dir;
|
||||
}
|
||||
@@ -1033,6 +1036,9 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
if (!$this->_cacheDirNormalized) {
|
||||
$this->_normalizeDir('cache_dir', $this->cache_dir);
|
||||
$this->_cacheDirNormalized = true;
|
||||
if ($this->_isNewRelease($this->cache_dir)) {
|
||||
$this->clearAllCache();
|
||||
}
|
||||
}
|
||||
return $this->cache_dir;
|
||||
}
|
||||
@@ -1246,6 +1252,22 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
$this->_cache[ 'tplObjects' ] = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if new release was installed
|
||||
*
|
||||
* @param string $dir compiled oder cache dir path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function _isNewRelease ($dir) {
|
||||
if (!is_file($file = $dir. 'version.txt') || file_get_contents($file) !== Smarty::SMARTY_VERSION) {
|
||||
file_put_contents($file, Smarty::SMARTY_VERSION);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Smarty object
|
||||
*
|
||||
|
@@ -63,9 +63,10 @@ class Smarty_Internal_Extension_Clear
|
||||
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_cache as $_file) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.') {
|
||||
continue;
|
||||
}
|
||||
$_filepath = (string) $_file;
|
||||
// directory ?
|
||||
if ($_file->isDir()) {
|
||||
if (!$_cache->isDot()) {
|
||||
@@ -73,7 +74,11 @@ class Smarty_Internal_Extension_Clear
|
||||
@rmdir($_file->getPathname());
|
||||
}
|
||||
} else {
|
||||
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length)));
|
||||
// delete only php files
|
||||
if (substr($_filepath, -4) !== '.php') {
|
||||
continue;
|
||||
}
|
||||
$_parts = explode($_dir_sep, str_replace('\\', '/', substr($_filepath, $_dir_length)));
|
||||
$_parts_count = count($_parts);
|
||||
// check name
|
||||
if (isset($resource_name)) {
|
||||
@@ -114,9 +119,9 @@ class Smarty_Internal_Extension_Clear
|
||||
}
|
||||
}
|
||||
}
|
||||
$_count += @unlink((string) $_file) ? 1 : 0;
|
||||
$_count += @unlink($_filepath) ? 1 : 0;
|
||||
if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) {
|
||||
opcache_invalidate((string) $_file, true);
|
||||
opcache_invalidate($_filepath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -75,18 +75,20 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
}
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_compile as $_file) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$_filepath = (string) $_file;
|
||||
|
||||
if ($_file->isDir()) {
|
||||
if (!$_compile->isDot()) {
|
||||
// delete folder if empty
|
||||
@rmdir($_file->getPathname());
|
||||
}
|
||||
} else {
|
||||
// delete only php files
|
||||
if (substr($_filepath, -4) !== '.php') {
|
||||
continue;
|
||||
}
|
||||
$unlink = false;
|
||||
if ((!isset($_compile_id) || (isset($_filepath[ $_compile_id_part_length ]) && $a =
|
||||
!strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) &&
|
||||
|
@@ -419,11 +419,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public function _decodeProperties(Smarty_Internal_Template $tpl, $properties, $cache = false)
|
||||
{
|
||||
// on cache resources other than file check version stored in cache code
|
||||
if ($cache && $tpl->smarty->caching_type !== 'file' && Smarty::SMARTY_VERSION !== $properties[ 'version' ]) {
|
||||
$tpl->smarty->clearAllCache();
|
||||
return false;
|
||||
}
|
||||
$is_valid = true;
|
||||
if (Smarty::SMARTY_VERSION != $properties[ 'version' ]) {
|
||||
// new version must rebuild
|
||||
$is_valid = false;
|
||||
} elseif ($is_valid && !empty($properties[ 'file_dependency' ]) &&
|
||||
if (!empty($properties[ 'file_dependency' ]) &&
|
||||
((!$cache && $tpl->smarty->compile_check) || $tpl->smarty->compile_check == 1)
|
||||
) {
|
||||
// check file dependencies at compiled code
|
||||
|
Reference in New Issue
Block a user