mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
related to #1316 Calculates cache size and cache size derivatives
This commit is contained in:
@@ -3410,3 +3410,46 @@ SELECT *
|
||||
|
||||
return $images[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return each cache image sizes.
|
||||
*
|
||||
* @since 12
|
||||
* @param string $path_to_file
|
||||
*/
|
||||
function get_cache_size_derivatives($path)
|
||||
{
|
||||
$msizes = array(); //final res
|
||||
$subdirs = array(); //sous-rep
|
||||
|
||||
if (is_dir($path))
|
||||
{
|
||||
if ($contents = opendir($path))
|
||||
{
|
||||
while (($node = readdir($contents)) !== false)
|
||||
{
|
||||
if ($node == '.' or $node == '..') continue;
|
||||
|
||||
if (is_file($path.'/'.$node))
|
||||
{
|
||||
if ($split = explode('-' ,$node))
|
||||
{
|
||||
$size_code = substr(end($split), 0, 2);
|
||||
@$msizes[$size_code] += filesize($path.'/'.$node);
|
||||
}
|
||||
}
|
||||
elseif (is_dir($path.'/'.$node))
|
||||
{
|
||||
$tmp_msizes = get_cache_size_derivatives($path.'/'.$node);
|
||||
foreach ($tmp_msizes as $size_key => $value)
|
||||
{
|
||||
@$msizes[$size_key] += $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($contents);
|
||||
}
|
||||
return $msizes;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,9 @@ $template->assign(
|
||||
'U_PHPINFO' => sprintf($url_format, 'phpinfo'),
|
||||
'PHP_DATATIME' => $php_current_timestamp,
|
||||
'DB_DATATIME' => $db_current_date,
|
||||
'pwg_token' => $pwg_token
|
||||
'pwg_token' => $pwg_token,
|
||||
'cache_sizes' => (isset($conf['cache_sizes'])) ? unserialize($conf['cache_sizes']) : null,
|
||||
'time_elapsed_since_last_calc' => (isset($conf['cache_sizes'])) ? time_since(unserialize($conf['cache_sizes'])[3]['value'], 'year') : null,
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -292,6 +292,8 @@ $template->assign(
|
||||
'U_PHPINFO' => sprintf($url_format, 'phpinfo'),
|
||||
'PHP_DATATIME' => $php_current_timestamp,
|
||||
'DB_DATATIME' => $db_current_date,
|
||||
'cache_sizes' => (isset($conf['cache_sizes'])) ? unserialize($conf['cache_sizes']) : null,
|
||||
'time_elapsed_since_last_calc' => (isset($conf['cache_sizes'])) ? time_since(unserialize($conf['cache_sizes'])[3]['value'], 'year') : null,
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
function displayResponse(domElem, values, mDivs, mValues, lastTimeCalc) {
|
||||
function displayResponse(domElem, values, mDivs, mValues) {
|
||||
|
||||
for (let index = 0; index < domElem.length; index++) {
|
||||
domElem[index].html(values[index])
|
||||
domElem[index].html(values[index] + " Mo")
|
||||
}
|
||||
|
||||
for (let index = 0; index < mDivs.length; index++) {
|
||||
mDivs[index].title = mValues[index] + "Mo";
|
||||
mDivName = mDivs[index].getAttribute("name");
|
||||
mDivs[index].title = mValues[mDivName] + " Mo";
|
||||
}
|
||||
|
||||
$(".cache-lastCalculated-value").html(lastTimeCalc)
|
||||
$(".cache-lastCalculated-value").html(no_time_elapsed);
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
@@ -28,26 +29,29 @@ $(document).ready(function () {
|
||||
if (data.stat === "ok") {
|
||||
res();
|
||||
|
||||
console.log(data);
|
||||
|
||||
console.log(data.result.infos[1].value);
|
||||
|
||||
var domElemToRefresh = [$(".cache-size-value"), $(".multiple-pictures-sizes"), $(".multiple-compiledTemplate-sizes")];
|
||||
var domElemValues = [data.result.infos[0].value, 69, 42];
|
||||
var domElemValues = [data.result.infos[0].value, data.result.infos[1].value.all, data.result.infos[2].value];
|
||||
for (let i = 0; i < domElemValues.length; i++) {
|
||||
domElemValues[i] = (domElemValues[i]/1024/1024).toFixed(2);
|
||||
}
|
||||
|
||||
var multipleSizes = $(".delete-check-container").children(".delete-size-check");
|
||||
var multipleSizesValues = data.result.infos[1].value;
|
||||
var multipleSizesValues = data.result.infos[1].value
|
||||
for (const [key, value] of Object.entries(multipleSizesValues)) {
|
||||
multipleSizesValues[key] = (multipleSizesValues[key]/1024/1024).toFixed(2);
|
||||
}
|
||||
|
||||
displayResponse(domElemToRefresh , domElemValues, multipleSizes, multipleSizesValues, data.result.infos[2].value);
|
||||
displayResponse(domElemToRefresh , domElemValues, multipleSizes, multipleSizesValues);
|
||||
|
||||
$(".refresh-icon").addClass("icon-arrows-cw").removeClass("spin6");
|
||||
$(this).children("span").addClass("icon-arrows-cw").removeClass("spin6");
|
||||
|
||||
} else {
|
||||
rej(raw_data);
|
||||
rej(data);
|
||||
}
|
||||
},
|
||||
error: function(message) {
|
||||
rej(message);
|
||||
console.log(message);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
{footer_script}
|
||||
const confirm_msg = '{"Yes, I am sure"|@translate}';
|
||||
const cancel_msg = "{"No, I have changed my mind"|@translate}";
|
||||
const no_time_elapsed = "{"right now"|@translate}";
|
||||
let selected = [];
|
||||
$(".lock-gallery-button").each(function() {
|
||||
const gallery_tip = '{"A locked gallery is only visible to administrators"|@translate|@escape:'javascript'}';
|
||||
@@ -113,11 +114,11 @@ $(".delete-size-check").click( function () {
|
||||
<fieldset class="">
|
||||
<legend><span class="icon-globe icon-blue"></span>Global Gallery Actions</legend>
|
||||
<div style="display:flex;flex-wrap: wrap;">
|
||||
{if (isset($U_MAINT_LOCK_GALLERY))}
|
||||
<a href="{$U_MAINT_LOCK_GALLERY}" class="lock-gallery-button icon-lock maintenance-action">{'Lock gallery'|@translate}</a>
|
||||
{else}
|
||||
<a href="{$U_MAINT_UNLOCK_GALLERY}" class="lock-gallery-button icon-lock maintenance-action">{'Unlock gallery'|@translate}</a>
|
||||
{/if}
|
||||
{if (isset($U_MAINT_LOCK_GALLERY))}
|
||||
<a href="{$U_MAINT_LOCK_GALLERY}" class="lock-gallery-button icon-lock maintenance-action">{'Lock gallery'|@translate}</a>
|
||||
{else}
|
||||
<a href="{$U_MAINT_UNLOCK_GALLERY}" class="lock-gallery-button icon-lock maintenance-action">{'Unlock gallery'|@translate}</a>
|
||||
{/if}
|
||||
<a href="{$U_MAINT_CATEGORIES}" class="icon-folder-open maintenance-action">{'Update albums informations'|@translate}</a>
|
||||
<a href="{$U_MAINT_IMAGES}" class="icon-info-circled-1 maintenance-action">{'Update photos information'|@translate}</a>
|
||||
<a href="{$U_MAINT_DATABASE}" class="icon-database maintenance-action">{'Repair and optimize database'|@translate}</a>
|
||||
@@ -138,28 +139,50 @@ $(".delete-size-check").click( function () {
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="">
|
||||
<legend><span class="icon-trash-1 icon-red"></span>Purge Cache</legend>
|
||||
<legend><span class="icon-trash-1 icon-red"></span>Purge Cache</legend>
|
||||
|
||||
<div class="template-purge">
|
||||
<div class="cache-infos">
|
||||
<span class="cache-size-text">{'Cache size'|@translate}</span>
|
||||
<span class="cache-size-value">999 Go</span>
|
||||
<span class="cache-lastCalculated-text">{'calculated'|@translate}</span>
|
||||
<span class="cache-lastCalculated-value">42 {'months ago'|@translate}</span>
|
||||
<a class="refresh-cache-size"><span class="refresh-icon icon-arrows-cw"></span>{'Refresh'|@translate}</a>
|
||||
<div class="template-purge">
|
||||
<div class="cache-infos">
|
||||
<span class="cache-size-text">{'Cache size'|@translate}</span>
|
||||
<span class="cache-size-value">
|
||||
{if isset($cache_sizes)}
|
||||
{round($cache_sizes[0]['value']/1024/1024, 2)} Mo
|
||||
{else}
|
||||
{'N/A'|translate}
|
||||
{/if}
|
||||
</span>
|
||||
<span class="cache-lastCalculated-text">{if $time_elapsed_since_last_calc}  {'calculated'|@translate}{/if}</span>
|
||||
<span class="cache-lastCalculated-value">{if $time_elapsed_since_last_calc} {$time_elapsed_since_last_calc} {else}   {"never calculated"|@translate} {/if}</span>
|
||||
<a class="refresh-cache-size"><span class="refresh-icon icon-arrows-cw"></span>{'Refresh'|@translate}</a>
|
||||
</div>
|
||||
<a href="{$U_MAINT_COMPILED_TEMPLATES}" class="icon-file-code maintenance-action">{'Purge compiled templates'|@translate} <span class="multiple-compiledTemplate-sizes"> 999 Go </span></a>
|
||||
<a href="{$U_MAINT_COMPILED_TEMPLATES}" class="icon-file-code maintenance-action">{'Purge compiled templates'|@translate}
|
||||
<span class="multiple-compiledTemplate-sizes">
|
||||
{if isset($cache_sizes)}
|
||||
{round($cache_sizes[2]['value']/1024/1024, 2)} Mo
|
||||
{else}
|
||||
{'N/A'|translate}
|
||||
{/if}
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="delete-size-checks">
|
||||
<span id="label-delete-size-checkbox">{'Delete multiple size images'|@translate}<span class="multiple-pictures-sizes">999 Go</span></span>
|
||||
<span id="label-delete-size-checkbox">{'Delete multiple size images'|@translate}
|
||||
<span class="multiple-pictures-sizes">
|
||||
{if isset($cache_sizes)}
|
||||
{round($cache_sizes[1]['value']['all']/1024/1024, 2)} Mo
|
||||
{else}
|
||||
{'N/A'|translate}
|
||||
{/if}
|
||||
</span>
|
||||
</span>
|
||||
<div class="delete-check-container">
|
||||
{foreach from=$purge_derivatives key=name item=url name=loop}
|
||||
<div class="delete-size-check" title="Poids : 999Go" data-selected="0" name="{$url}">
|
||||
<span class="select-checkbox"><i class="icon-ok" style="margin-left:8px"></i></span><span class="picture-deletion-size" style="font-size:14px;margin-left:5px;padding-top:2px;">{$name}</span>
|
||||
{foreach from=$purge_derivatives key=name item=url name=loop}
|
||||
<div class="delete-size-check" title="{if isset($cache_sizes)} {round($cache_sizes[1]['value'][$url]/1024/1024, 2)} Mo{else}{'N/A'|translate}{/if}" data-selected="0" name="{$url}">
|
||||
<span class="select-checkbox"><i class="icon-ok" style="margin-left:8px"></i></span>
|
||||
<span class="picture-deletion-size" style="font-size:14px;margin-left:5px;padding-top:2px;">{$name}</span>
|
||||
</div>
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -168,8 +191,8 @@ $(".delete-size-check").click( function () {
|
||||
|
||||
<style>
|
||||
#label-delete-size-checkbox {
|
||||
font-weight:bold;
|
||||
white-space:nowrap;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.maintenance-action:hover {
|
||||
@@ -178,41 +201,41 @@ $(".delete-size-check").click( function () {
|
||||
}
|
||||
|
||||
.maintenance-action {
|
||||
border:solid 1px;
|
||||
padding:8px 10px;
|
||||
border: solid 1px;
|
||||
padding: 8px 10px;
|
||||
margin-right: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.delete-size-checks {
|
||||
display:flex;
|
||||
text-align:left;
|
||||
margin-bottom:5px;
|
||||
display: flex;
|
||||
text-align: left;
|
||||
margin-bottom: 5px;
|
||||
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.delete-check-container {
|
||||
display:flex;
|
||||
flex-wrap:wrap;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.delete-size-check {
|
||||
margin-right:15px;
|
||||
margin-bottom:10px;
|
||||
display:flex;
|
||||
cursor:pointer
|
||||
margin-right: 15px;
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
cursor: pointer
|
||||
}
|
||||
|
||||
.select-checkbox {
|
||||
display:inline-block;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.delete-sizes {
|
||||
display:block;
|
||||
width:max-content;
|
||||
text-align:left;
|
||||
display: block;
|
||||
width: max-content;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.delete-sizes {
|
||||
@@ -233,11 +256,10 @@ $(".delete-size-check").click( function () {
|
||||
animation: spin 4s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
100% {
|
||||
@keyframes spin {
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform:rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -1,4 +1,7 @@
|
||||
{combine_script id='ajax' load='footer' path='admin/themes/default/js/maintenance.js'}
|
||||
{footer_script}
|
||||
const no_time_elapsed = "{"right now"|@translate}";
|
||||
{/footer_script}
|
||||
|
||||
<fieldset id="environment">
|
||||
<legend><span class="icon-television icon-red"></span> {'Environment'|@translate}</legend>
|
||||
@@ -12,9 +15,15 @@
|
||||
{/if}
|
||||
<li>
|
||||
<span class="cache-size-text">{'Cache size'|@translate}</span>
|
||||
<span class="cache-size-value">999 Go</span>
|
||||
<span class="cache-lastCalculated-text">{'calculated'|@translate}</span>
|
||||
<span class="cache-lastCalculated-value">{'42 months ago'|@translate}</span>
|
||||
<span class="cache-size-value">
|
||||
{if isset($cache_sizes)}
|
||||
{round($cache_sizes[0]['value']/1024/1024, 2)} Mo
|
||||
{else}
|
||||
{'N/A'|translate}
|
||||
{/if}
|
||||
</span>
|
||||
<span class="cache-lastCalculated-text">{if $time_elapsed_since_last_calc}  {'calculated'|@translate}{/if}</span>
|
||||
<span class="cache-lastCalculated-value">{if $time_elapsed_since_last_calc} {$time_elapsed_since_last_calc} {else}   {"never calculated"|@translate} {/if}</span>
|
||||
<a class="refresh-cache-size"><span class="refresh-icon icon-arrows-cw"></span>{'Refresh'|@translate}</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -197,31 +197,63 @@ function ws_getInfos($params, &$service)
|
||||
/**
|
||||
* API method
|
||||
* Calculates and returns the size of the cache
|
||||
*
|
||||
* @since 12
|
||||
* @param mixed[] $params
|
||||
*/
|
||||
function ws_getCacheSize($params, &$service)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Cache size
|
||||
$infos['cache_size'] = 4444;
|
||||
$path_cache = $conf['data_location'];
|
||||
$infos['cache_size'] = null;
|
||||
if (function_exists('exec'))
|
||||
{
|
||||
@exec('du -sk '.$path_cache, $return_array_cache);
|
||||
if (
|
||||
is_array($return_array_cache)
|
||||
and !empty($return_array_cache[0])
|
||||
and preg_match('/^(\d+)\s/', $return_array_cache[0], $matches_cache)
|
||||
)
|
||||
{
|
||||
$infos['cache_size'] = $matches_cache[1] * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
// Multiples sizes size
|
||||
$path_msizes = $conf['data_location'].'i';
|
||||
$msizes = get_cache_size_derivatives($path_msizes);
|
||||
|
||||
/* Multiples sizes */
|
||||
$infos['msizes'] = array_fill_keys(array_keys(ImageStdParams::get_defined_type_map()), 0);
|
||||
$infos['msizes']['custom'] = 0;
|
||||
$all = 0;
|
||||
|
||||
$custom = 1;
|
||||
$huge = 2;
|
||||
$extra_large = 3;
|
||||
$large = 4;
|
||||
$medium = 5;
|
||||
$small = 6;
|
||||
$extra_small = 7;
|
||||
$tiny = 8;
|
||||
$thumbnail = 9;
|
||||
$squarre = 10;
|
||||
$all = $squarre + $thumbnail + $tiny + $extra_small + $small + $medium + $large + $extra_large + $huge + $custom;
|
||||
foreach(array_keys($infos['msizes']) as $size_type)
|
||||
{
|
||||
$infos['msizes'][$size_type] += @$msizes[derivative_to_url($size_type)];
|
||||
$all += $infos['msizes'][$size_type];
|
||||
}
|
||||
$infos['msizes']['all'] = $all;
|
||||
|
||||
$infos['msizes'] = [$all, $squarre, $thumbnail, $tiny, $extra_small, $small, $medium, $large, $extra_large, $huge, $custom];
|
||||
// Compiled templates size
|
||||
$path_template_c = $conf['data_location'].'templates_c';
|
||||
$infos['tsizes'] = null;
|
||||
if (function_exists('exec'))
|
||||
{
|
||||
@exec('du -sk '.$path_template_c, $return_array_template_c);
|
||||
if (
|
||||
is_array($return_array_template_c)
|
||||
and !empty($return_array_template_c[0])
|
||||
and preg_match('/^(\d+)\s/', $return_array_template_c[0], $matches_template_c)
|
||||
)
|
||||
{
|
||||
$infos['tsizes'] = $matches_template_c[1] * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
$infos['last_time_calc'] = "now";
|
||||
$infos['last_date_calc'] = date("Y-m-d H:i:s");
|
||||
|
||||
foreach ($infos as $name => $value)
|
||||
{
|
||||
@@ -231,10 +263,11 @@ function ws_getCacheSize($params, &$service)
|
||||
);
|
||||
}
|
||||
|
||||
conf_update_param("cache_sizes", $output, true);
|
||||
|
||||
return array('infos' => new PwgNamedArray($output, 'item'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Adds images to the caddie
|
||||
|
||||
@@ -1227,4 +1227,6 @@ $lang['Plugin "%s" has been activated!'] = 'Plugin "%s" has been activated!';
|
||||
$lang['Plugin "%s" deleted!'] = 'Plugin "%s" deleted!';
|
||||
$lang['Activated'] = 'Activated';
|
||||
$lang['Deactivated'] = 'Deactivated';
|
||||
$lang['Restored'] = 'Restored';
|
||||
$lang['Restored'] = 'Restored';
|
||||
$lang['right now'] = 'right now';
|
||||
$lang['never calculated'] = 'never calculated';
|
||||
@@ -1171,7 +1171,7 @@ $lang['Apply to the whole hierarchy'] = 'Appliquer à toute l\'arborescence';
|
||||
$lang['<b>%d+</b> albums found, try to refine the search'] = '<b>%d+</b> albums trouvé, essayez d\'affiner la recherche';
|
||||
$lang['Select an album... or type it!'] = 'Sélectionnez un album... ou tapez-le !';
|
||||
$lang['Cache size'] = "Taille du cache";
|
||||
$lang['calculated'] = "calculé il y a";
|
||||
$lang['calculated'] = "calculé";
|
||||
$lang['months ago'] = "mois";
|
||||
$lang['Delete these sizes'] = 'Supprimer les tailles';
|
||||
$lang['Activity'] = 'Activité';
|
||||
@@ -1229,4 +1229,6 @@ $lang['Plugin "%s" has been activated!'] = 'Le plugin "%s" a été activé !';
|
||||
$lang['Plugin "%s" deleted!'] = 'Plugin "%s" supprimé !';
|
||||
$lang['Activated'] = 'Activé';
|
||||
$lang['Deactivated'] = 'Désactivé';
|
||||
$lang['Restored'] = 'Restoré';
|
||||
$lang['Restored'] = 'Restoré';
|
||||
$lang['right now'] = 'à l\'instant';
|
||||
$lang['never calculated'] = 'jamais calculé';
|
||||
Reference in New Issue
Block a user