Skip to content

Commit

Permalink
Version 4.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Apr 4, 2023
1 parent 85f7c33 commit 504f840
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For more information, go to https://www.luigifab.fr/openmage/minifier (IPv6 is r

This repository is a releases mirror. To install the module, please use the composer key available in the documentation.

- Current version: 4.4.2 (03/03/2023)
- Current version: 4.5.0 (04/04/2023)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2
- Client compatibility: Firefox 36+, Chrome 32+, Opera 19+, Edge 16+, Safari 9+
- Translations: English (en), French (fr-FR/fr-CA), German (de), Italian (it), Portuguese (pt-PT/pt-BR), Spanish (es) / Chinese (zh), Czech (cs), Dutch (nl), Greek (el), Hungarian (hu), Japanese (ja), Polish (pl), Romanian (ro), Russian (ru), Slovak (sk), Turkish (tr), Ukrainian (uk)
Expand Down
6 changes: 5 additions & 1 deletion src/app/code/community/Luigifab/Minifier/Block/Calendar.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created D/20/05/2018
* Updated D/18/07/2021
* Updated J/09/03/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -65,4 +65,8 @@ public function getHtml(string $locale) {

return $this->renderView();
}

public function getStoreTimestamp($store = null) {
return 'parseInt(Date.now() / 1000)';
}
}
43 changes: 29 additions & 14 deletions src/app/code/community/Luigifab/Minifier/Model/Files.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created W/13/04/2016
* Updated D/06/11/2022
* Updated V/10/03/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2022-2023 | Fabrice Creuzot <fabrice~cellublue~com>
Expand Down Expand Up @@ -43,7 +43,8 @@ public function getMinifiedFiles(int $storeId) {

// cherche les fichiers sources
// depuis le cache ou depuis le layout
$items = Mage::app()->useCache('layout') ? Mage::app()->loadCache('minifier_layout_'.$storeId) : null;
$ckey = ($storeId == 0) ? 'admin_'.Mage::getSingleton('core/translate')->getLocale() : 'store_'.$storeId;
$items = Mage::app()->useCache('layout') ? Mage::app()->loadCache('minifier_layout_'.$ckey) : null;
$items = empty($items) ? null : @json_decode($items, true);

if (empty($items)) {
Expand All @@ -52,11 +53,13 @@ public function getMinifiedFiles(int $storeId) {
$items = $this->searchFiles($design, $storeId);

if (Mage::app()->useCache('layout'))
Mage::app()->saveCache(json_encode($items), 'minifier_layout_'.$storeId,
Mage::app()->saveCache(json_encode($items), 'minifier_layout_'.$ckey,
[Mage_Core_Model_Layout_Update::LAYOUT_GENERAL_CACHE_TAG]);
}

// minifie les fichiers sources (et change la clé)
// attention lorsque les fichiers sont en cache et que les fichiers sont supprimés sans vider le cache
// les fichiers virtuels ne seront pas régénérés car il faut passer dans searchFiles avant minifyFiles
$hasChange = $this->minifyFiles($items);
if ($hasChange && (Mage::getStoreConfig('minifier/cssjs/solution') == 1)) {
$value = Mage::getSingleton('core/date')->date('YmdHis');
Expand Down Expand Up @@ -94,7 +97,6 @@ public function getMinifiedFiles(int $storeId) {
// utilise uglify-js et clean-css
protected function minifyFiles(array $items) {

$core = max(1, Mage::helper('minifier')->getNumberOfCpuCore() - 2);
$pids = [];
$files = [];
$new = false;
Expand All @@ -121,6 +123,29 @@ protected function minifyFiles(array $items) {

if (is_file($source) && !is_file($cache)) {

if (empty($core)) {
$core = max(1, Mage::helper('minifier')->getNumberOfCpuCore() - 2);
$maxc = ceil($core * 1.5);
}

while (count($pids) >= $core) {
foreach ($pids as $key => $pid) {
if (file_exists('/proc/'.$pid))
clearstatcache('/proc/'.$pid);
else
unset($pids[$key]);
}
usleep(100000); // 0.1 s
}

$runs = [];
exec('ps aux | grep Minifier/lib/minify.php', $runs);
while (count($runs) >= $maxc) {
usleep(90000); // 0.09 s
$runs = [];
exec('ps aux | grep Minifier/lib/minify.php', $runs);
}

clearstatcache(true, $lock);
if (!is_file($lock))
file_put_contents($lock, getenv('REMOTE_ADDR'), LOCK_EX);
Expand All @@ -140,16 +165,6 @@ protected function minifyFiles(array $items) {

Mage::log($cmd, Zend_Log::DEBUG, 'minifier.log');
$pids[] = exec($cmd);

while (count($pids) >= $core) {
foreach ($pids as $key => $pid) {
if (file_exists('/proc/'.$pid))
clearstatcache('/proc/'.$pid);
else
unset($pids[$key]);
}
usleep(100000); // 0.1 s
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/code/community/Luigifab/Minifier/etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* Created L/27/06/2011
* Updated J/02/03/2023
* Updated V/03/03/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand All @@ -20,7 +20,7 @@
<config>
<modules>
<Luigifab_Minifier>
<version>4.4.2</version>
<version>4.5.0</version>
</Luigifab_Minifier>
</modules>
<global>
Expand Down
7 changes: 6 additions & 1 deletion src/app/code/community/Luigifab/Minifier/readme
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ Files and directories
- app/design/adminhtml/default/default/template/luigifab/minifier/
- app/design/frontend/base/default/layout/luigifab/minifier.xml
- app/design/frontend/base/default/template/luigifab/minifier/

Depends (with php exec)
- npm
- cleancss
- uglifyjs
- rm -rf
- also used: nproc, ps aux | grep


Translations in en-US (english/United-States) by:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/03/11/2016
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -39,12 +39,13 @@
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "design/head/shortcut_icon";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/css/%";
DELETE FROM '.$this->getTable('core_config_data').' WHERE path LIKE "dev/js/%";
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/css/merge_css_files", 0);
INSERT INTO '.$this->getTable('core_config_data').' (scope, scope_id, path, value) VALUES ("default", 0, "dev/js/merge_files", 0);
DROP TABLE IF EXISTS '.$this->getTable('luigifab_minifier_kraken').';
');

$this->setConfigData('dev/css/merge_css_files', '0');
$this->setConfigData('dev/js/merge_files', '0');

$variable = Mage::getModel('core/variable')->loadByCode('cachekey');
if (!empty($variable->getId()))
$variable->delete();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created L/13/09/2021
* Updated L/26/12/2022
* Updated V/03/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -32,27 +32,15 @@
try {
$config = Mage::getModel('core/config_data')->load('minifier/html/enabled', 'path');
if (!empty($config->getData('value'))) {
Mage::getModel('core/config_data')
->setData('path', 'minifier/html/enabled_back')
->setData('value', 1)
->save();
Mage::getModel('core/config_data')
->setData('path', 'minifier/html/enabled_front')
->setData('value', 1)
->save();
$this->setConfigData('minifier/html/enabled_back', '1');
$this->setConfigData('minifier/html/enabled_front', '1');
}
$config->delete();

$config = Mage::getModel('core/config_data')->load('minifier/cssjs/enabled', 'path');
if (!empty($config->getData('value'))) {
Mage::getModel('core/config_data')
->setData('path', 'minifier/cssjs/enabled_back')
->setData('value', 1)
->save();
Mage::getModel('core/config_data')
->setData('path', 'minifier/cssjs/enabled_front')
->setData('value', 1)
->save();
$this->setConfigData('minifier/cssjs/enabled_back', '1');
$this->setConfigData('minifier/cssjs/enabled_front', '1');
}
$config->delete();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/15/04/2016
* Updated V/28/10/2022
* Updated V/10/02/2023
*
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
Expand Down Expand Up @@ -50,7 +50,7 @@ Ext.UpdateManager.defaults.disableCaching = true;
<?php endif ?>
//]]></script>

<?php if ($this->getCanLoadTinyMce()): // TinyMCE is broken when loaded through index.php ?>
<?php if (!empty($this->getCanLoadTinyMce()) && (Mage::getStoreConfig('cms/wysiwyg/enabled') != 'disabled')): ?>
<script type="text/javascript" src="<?php echo Mage::getDesign()->getJsUrl('tiny_mce/tiny_mce.js') ?>"></script>
<?php endif ?>
<?php if (!Mage::getStoreConfigFlag('minifier/cssjs/enabled_back')): ?>
Expand Down

0 comments on commit 504f840

Please sign in to comment.