From 96e63f5b9e38725aa9f11176d3517dd2c8ddf4f4 Mon Sep 17 00:00:00 2001 From: therampagerado Date: Tue, 26 Aug 2025 23:57:31 +0300 Subject: [PATCH 1/5] Add file ignore and preview features --- .../admin/AdminCoreUpdaterController.php | 71 +++++++++++++++++++ views/js/controller.js | 13 +++- views/templates/admin/result.tpl | 57 +++++++++++++-- 3 files changed, 134 insertions(+), 7 deletions(-) diff --git a/controllers/admin/AdminCoreUpdaterController.php b/controllers/admin/AdminCoreUpdaterController.php index d5c6e06..57b5257 100644 --- a/controllers/admin/AdminCoreUpdaterController.php +++ b/controllers/admin/AdminCoreUpdaterController.php @@ -49,6 +49,7 @@ class AdminCoreUpdaterController extends ModuleAdminController const ACTION_GET_DATABASE_DIFFERENCES = "GET_DATABASE_DIFFERENCES"; const ACTION_APPLY_DATABASE_FIX = 'APPLY_DATABASE_FIX'; const ACTION_RUN_POST_UPDATE_PROCESSES = 'RUN_POST_UPDATE_PROCESSES'; + const ACTION_PREVIEW_FILE = 'PREVIEW_FILE'; const SELECTED_PROCESS_MIGRATE_DB = 'SELECTED_PROCESS_MIGRATE_DB'; const SELECTED_PROCESS_INITIALIZATION_CALLBACK = 'SELECTED_PROCESS_INITIALIZATION_CALLBACK'; @@ -777,6 +778,8 @@ protected function processAction($action) return $this->getDatabaseDifferences(); case static::ACTION_APPLY_DATABASE_FIX: return $this->applyDatabaseFix(Tools::getValue('ids')); + case static::ACTION_PREVIEW_FILE: + return $this->previewFile(); default: throw new PrestaShopException("Invalid action: $action"); } @@ -955,6 +958,19 @@ protected function initUpdateProcess() if (! $result) { throw new PrestaShopException("Comparision result not found. Please reload the page and try again"); } + $ignored = Tools::getValue('ignoreFiles'); + if ($ignored && !is_array($ignored)) { + $ignored = [$ignored]; + } + if ($ignored) { + foreach ($ignored as $path) { + foreach (['change','add','remove'] as $type) { + if (isset($result['changeSet'][$type][$path])) { + unset($result['changeSet'][$type][$path]); + } + } + } + } $targetFileList = $comparator->getFileList( $compareProcessId, $result['targetRevision'], @@ -979,6 +995,61 @@ protected function initUpdateProcess() ]; } + /** + * Returns preview of given file + * + * @return array + * + * @throws PrestaShopException + */ + protected function previewFile() + { + $compareProcessId = Tools::getValue('compareProcessId'); + $file = Tools::getValue('file'); + if (!$file) { + throw new PrestaShopException('File not specified'); + } + $comparator = $this->factory->getComparator(); + $result = $comparator->getResult($compareProcessId); + if (!$result) { + throw new PrestaShopException('Comparision result not found. Please reload the page and try again'); + } + $apiPath = preg_replace('#^' . preg_quote(basename(_PS_ADMIN_DIR_) . '/') . '#', 'admin/', $file); + $tmp = tempnam(_PS_CACHE_DIR_, 'cu'); + try { + $this->factory->getApi()->downloadFiles( + $result['targetPHPVersion'], + $result['targetRevision'], + [ $apiPath ], + $tmp + ); + $tar = new Archive_Tar($tmp); + $remoteContent = $tar->extractInString($apiPath); + } finally { + @unlink($tmp); + } + + $localPath = _PS_ROOT_DIR_ . '/' . $this->fixAdminDirectory($file); + $localContent = file_exists($localPath) ? file_get_contents($localPath) : ''; + + return [ + 'local' => $localContent, + 'remote' => $remoteContent, + ]; + } + + /** + * Replace admin directory placeholder with real directory name + * + * @param string $file + * @return string + */ + protected function fixAdminDirectory($file) + { + $adminDir = basename(_PS_ADMIN_DIR_); + return preg_replace('#^admin/#', $adminDir . '/', $file); + } + /** * Returns currently selected tab * diff --git a/views/js/controller.js b/views/js/controller.js index 520c8d7..1d03efa 100644 --- a/views/js/controller.js +++ b/views/js/controller.js @@ -174,13 +174,21 @@ window.initializeCoreUpdater = function(translations) { incrementProcess('UPDATE', process, endProgress); }; - var update = function(compareProcessId) { + var update = function(compareProcessId, ignored) { initProgress(translations.UPDATE, translations.UPDATE_DESCRIPTION); - executeAction('INIT_UPDATE', { compareProcessId: compareProcessId }) + var params = { compareProcessId: compareProcessId }; + if (ignored && ignored.length > 0) { + params.ignoreFiles = ignored; + } + executeAction('INIT_UPDATE', params) .then(runUpdate) .catch(displayError); }; + var preview = function(compareProcessId, file) { + return executeAction('PREVIEW_FILE', { compareProcessId: compareProcessId, file: file }); + }; + var checkDatabase = function() { document.getElementById('db-changes').className = 'status-running'; executeAction('GET_DATABASE_DIFFERENCES') @@ -282,6 +290,7 @@ window.initializeCoreUpdater = function(translations) { compare: compare, update: update, checkDatabase: checkDatabase, + preview: preview, } }; diff --git a/views/templates/admin/result.tpl b/views/templates/admin/result.tpl index 3e8fb95..6d9cd0d 100644 --- a/views/templates/admin/result.tpl +++ b/views/templates/admin/result.tpl @@ -115,6 +115,8 @@ {if $modified} {l s='modified' mod='coreupdater'} {/if} + {l s='Preview' mod='coreupdater'} + {/foreach} @@ -131,6 +133,8 @@ {if $modified} {l s='modified' mod='coreupdater'} {/if} + {l s='Preview' mod='coreupdater'} + {/foreach} @@ -147,6 +151,8 @@ {if $modified} {l s='modified' mod='coreupdater'} {/if} + {l s='Preview' mod='coreupdater'} + {/foreach} @@ -160,10 +166,51 @@ {l s='Update store' mod='coreupdater'} - {/if} + + + + From 04805fc30b8cecb6d3c3272dcd74c6a2111ba057 Mon Sep 17 00:00:00 2001 From: therampagerado Date: Wed, 27 Aug 2025 00:11:49 +0300 Subject: [PATCH 2/5] Show diff preview and ignore options only in developer mode --- .../admin/AdminCoreUpdaterController.php | 39 +++++++++---- views/templates/admin/result.tpl | 58 +++++++++++++------ 2 files changed, 67 insertions(+), 30 deletions(-) diff --git a/controllers/admin/AdminCoreUpdaterController.php b/controllers/admin/AdminCoreUpdaterController.php index 57b5257..eb24275 100644 --- a/controllers/admin/AdminCoreUpdaterController.php +++ b/controllers/admin/AdminCoreUpdaterController.php @@ -938,7 +938,8 @@ public function createCompareResult($compareProcessId, $result, $installedRevisi 'versionType' => $versionType, 'installedRevision' => $installedRevision, 'targetRevision' => $targetRevision, - 'changeSet' => $changeSet + 'changeSet' => $changeSet, + 'developerMode' => Settings::isDeveloperMode(), ]); return [ @@ -958,15 +959,18 @@ protected function initUpdateProcess() if (! $result) { throw new PrestaShopException("Comparision result not found. Please reload the page and try again"); } - $ignored = Tools::getValue('ignoreFiles'); - if ($ignored && !is_array($ignored)) { - $ignored = [$ignored]; - } - if ($ignored) { - foreach ($ignored as $path) { - foreach (['change','add','remove'] as $type) { - if (isset($result['changeSet'][$type][$path])) { - unset($result['changeSet'][$type][$path]); + $ignored = null; + if (Settings::isDeveloperMode()) { + $ignored = Tools::getValue('ignoreFiles'); + if ($ignored && !is_array($ignored)) { + $ignored = [$ignored]; + } + if ($ignored) { + foreach ($ignored as $path) { + foreach (['change','add','remove'] as $type) { + if (isset($result['changeSet'][$type][$path])) { + unset($result['changeSet'][$type][$path]); + } } } } @@ -1004,6 +1008,9 @@ protected function initUpdateProcess() */ protected function previewFile() { + if (!Settings::isDeveloperMode()) { + throw new PrestaShopException('Developer mode is not enabled'); + } $compareProcessId = Tools::getValue('compareProcessId'); $file = Tools::getValue('file'); if (!$file) { @@ -1032,9 +1039,17 @@ protected function previewFile() $localPath = _PS_ROOT_DIR_ . '/' . $this->fixAdminDirectory($file); $localContent = file_exists($localPath) ? file_get_contents($localPath) : ''; + $tmpRemote = tempnam(_PS_CACHE_DIR_, 'cu'); + $tmpLocal = tempnam(_PS_CACHE_DIR_, 'cu'); + file_put_contents($tmpRemote, $remoteContent); + file_put_contents($tmpLocal, $localContent); + $cmd = sprintf('diff -u %s %s 2>&1', escapeshellarg($tmpLocal), escapeshellarg($tmpRemote)); + $diff = shell_exec($cmd); + @unlink($tmpRemote); + @unlink($tmpLocal); + return [ - 'local' => $localContent, - 'remote' => $remoteContent, + 'diff' => base64_encode($diff === null ? '' : $diff), ]; } diff --git a/views/templates/admin/result.tpl b/views/templates/admin/result.tpl index 6d9cd0d..f5b2440 100644 --- a/views/templates/admin/result.tpl +++ b/views/templates/admin/result.tpl @@ -115,8 +115,10 @@ {if $modified} {l s='modified' mod='coreupdater'} {/if} - {l s='Preview' mod='coreupdater'} - + {if $developerMode} + {l s='Preview' mod='coreupdater'} + + {/if} {/foreach} @@ -133,8 +135,10 @@ {if $modified} {l s='modified' mod='coreupdater'} {/if} - {l s='Preview' mod='coreupdater'} - + {if $developerMode} + {l s='Preview' mod='coreupdater'} + + {/if} {/foreach} @@ -151,8 +155,10 @@ {if $modified} {l s='modified' mod='coreupdater'} {/if} - {l s='Preview' mod='coreupdater'} - + {if $developerMode} + {l s='Preview' mod='coreupdater'} + + {/if} {/foreach} @@ -169,6 +175,7 @@ {/if} +{if $developerMode} + +{/if} From 5245bc1154f9eea48797dbefe4b52378c7f64922 Mon Sep 17 00:00:00 2001 From: therampagerado Date: Wed, 27 Aug 2025 00:41:28 +0300 Subject: [PATCH 4/5] Add developer mode warning and tweak ignore label style --- views/css/coreupdater.css | 4 ++-- views/templates/admin/result.tpl | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/views/css/coreupdater.css b/views/css/coreupdater.css index eff59f4..4aa5bd9 100644 --- a/views/css/coreupdater.css +++ b/views/css/coreupdater.css @@ -109,6 +109,6 @@ #file-preview-diff .diff-hunk { background-color: #f1f8ff; } .ignore-label { - font-weight: normal; - margin-left: 5px; + font-weight: normal !important; + margin: 0 0 0 5px; } diff --git a/views/templates/admin/result.tpl b/views/templates/admin/result.tpl index 92cfcbd..0339aa1 100644 --- a/views/templates/admin/result.tpl +++ b/views/templates/admin/result.tpl @@ -71,6 +71,9 @@

{l s='Oh, bummer. Some of thirty bees core files have been [1]modified[/1]. That makes it a little bit harder to update your store.' tags=[''] mod='coreupdater'}

+ {if $developerMode} +

{l s='You are using Developer mode and few functions are visible. Use them at your own risk and only if you know what they do.' mod='coreupdater'}

+ {/if}

{l s='Modification of core files is not recommended. It makes it very hard to keep your store updated.' tags=[''] mod='coreupdater'} {l s='You should [1]extract[/1] your modifications to overrides or to module. If unsure how to do that, please contact [2]thirty bees support[/2], we can help.' tags=['', ''] mod='coreupdater'} From 4611711716e2a617a528346d212c66e73248243c Mon Sep 17 00:00:00 2001 From: therampagerado Date: Wed, 27 Aug 2025 00:50:19 +0300 Subject: [PATCH 5/5] Improve diff preview color contrast --- views/css/coreupdater.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/views/css/coreupdater.css b/views/css/coreupdater.css index 4aa5bd9..270b873 100644 --- a/views/css/coreupdater.css +++ b/views/css/coreupdater.css @@ -104,9 +104,9 @@ background: #f8f8f8; padding: 10px; } -#file-preview-diff .diff-add { background-color: #e6ffed; } -#file-preview-diff .diff-del { background-color: #ffeef0; } -#file-preview-diff .diff-hunk { background-color: #f1f8ff; } +#file-preview-diff .diff-add { background-color: #c8f7cf; } +#file-preview-diff .diff-del { background-color: #ffd2d7; } +#file-preview-diff .diff-hunk { background-color: #e0ecff; } .ignore-label { font-weight: normal !important;