From 7a1a6e1c5b33f9b5d61321b6800c90a5a41f5a7e Mon Sep 17 00:00:00 2001 From: Anant Negi Date: Mon, 29 Jul 2024 17:50:41 +0530 Subject: [PATCH] fixed twig loading issue when admin name is changed --- README.md | 2 +- .../controller/marketplace/modification.php | 74 ++++++++++++------- upload/admin/controller/module/ces_ocmod.php | 4 +- upload/install.json | 2 +- upload/system/library/ces/cesOcmodLib.php | 2 +- upload/system/modification.xml | 24 ++++++ 6 files changed, 76 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index d7e0833..5e8875a 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,4 @@ npm install rollup -c ``` -Replace Bundle generated editor.bundle.js file with [old file](./4.x.x.x/admin/view/javascript/) +Replace Bundle generated editor.bundle.js file with [old file](./upload/admin/view/javascript/) diff --git a/upload/admin/controller/marketplace/modification.php b/upload/admin/controller/marketplace/modification.php index f7dc627..17ac5e7 100644 --- a/upload/admin/controller/marketplace/modification.php +++ b/upload/admin/controller/marketplace/modification.php @@ -1,4 +1,5 @@ load->language($this->ePathModification); $this->load->model($this->ePathModificationModel); @@ -73,7 +75,8 @@ public function commonMethod(): void { /** * @return void */ - public function index(): void { + public function index(): void + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -84,13 +87,15 @@ public function index(): void { /** * @return void */ - public function list(): void { + public function list(): void + { $this->load->language($this->ePathModification); $this->response->setOutput($this->getList()); } - public function delete(): void { + public function delete(): void + { $this->load->language($this->ePathModification); $json = []; @@ -119,7 +124,8 @@ public function delete(): void { $this->response->setOutput(json_encode($json)); } - public function refresh($data = array()) { + public function refresh($data = array()) + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -155,7 +161,8 @@ public function refresh($data = array()) { $this->commonMethod(); } - public function clear() { + public function clear() + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -193,7 +200,7 @@ public function clear() { if (is_file($file)) { unlink($file); - // If directory use the remove directory function + // If directory use the remove directory function } elseif (is_dir($file)) { rmdir($file); } @@ -222,7 +229,8 @@ public function clear() { $this->commonMethod(); } - public function enable() { + public function enable() + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -254,7 +262,8 @@ public function enable() { $this->commonMethod(); } - public function disable() { + public function disable() + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -286,7 +295,8 @@ public function disable() { $this->commonMethod(); } - public function clearlog() { + public function clearlog() + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -323,7 +333,8 @@ public function clearlog() { /** * @return string */ - protected function getList(): string { + protected function getList(): string + { if (isset($this->request->get['sort'])) { $sort = (string)$this->request->get['sort']; } else { @@ -459,7 +470,8 @@ protected function getList(): string { return $this->load->view($this->ePathModification . '_list', $data); } - protected function validate() { + protected function validate() + { if (!$this->user->hasPermission('modify', $this->ePathModification)) { $this->error['warning'] = $this->language->get('error_permission'); } @@ -470,7 +482,8 @@ protected function validate() { /** * @return void */ - public function form(): void { + public function form(): void + { $this->load->language($this->ePathModification); $this->document->setTitle($this->language->get('heading_title')); @@ -543,7 +556,8 @@ public function form(): void { /** * @return void */ - public function save(): void { + public function save(): void + { $this->load->language($this->ePathModification); $json = $data = []; @@ -578,14 +592,14 @@ public function save(): void { $this->model_extension_ces_ocmod_setting_modification->editModification($modification_id, $data); } else { - if (!empty($data['code'])) { - // Check to see if the modification is already installed or not. - $modification_info = $this->model_extension_ces_ocmod_setting_modification->getModificationByCode($data['code']); + if (!empty($data['code'])) { + // Check to see if the modification is already installed or not. + $modification_info = $this->model_extension_ces_ocmod_setting_modification->getModificationByCode($data['code']); - if ($modification_info) { - $this->model_extension_ces_ocmod_setting_modification->deleteModification($modification_info['modification_id']); - } - } + if ($modification_info) { + $this->model_extension_ces_ocmod_setting_modification->deleteModification($modification_info['modification_id']); + } + } // hardcoded $data['extension_install_id'] = 0; @@ -604,7 +618,8 @@ public function save(): void { $this->response->setOutput(json_encode($json)); } - private function saveData($data) { + private function saveData($data) + { // Just before files are deleted, if config settings say maintenance mode is off then turn it on $maintenance = $this->config->get('config_maintenance'); @@ -646,7 +661,7 @@ private function saveData($data) { if (is_file($file)) { unlink($file); - // If directory use the remove directory function + // If directory use the remove directory function } elseif (is_dir($file)) { rmdir($file); } @@ -685,7 +700,7 @@ private function saveData($data) { $modification = array(); foreach ($xml as $xml) { - if (empty($xml)){ + if (empty($xml)) { continue; } @@ -754,11 +769,9 @@ private function saveData($data) { // Log $log[] = PHP_EOL . 'FILE: ' . $key; - } else { // Log $log[] = PHP_EOL . 'FILE: (sub modification) ' . $key; - } foreach ($operations as $operation) { @@ -932,7 +945,7 @@ private function saveData($data) { else { // Log $log[] = 'NOT FOUND - OPERATIONS ABORTED!'; - break; + break; } } } @@ -980,5 +993,12 @@ private function saveData($data) { // Do not return success message if refresh() was called with $data $this->session->data['success'] = $this->language->get('text_success'); + // when admin folder is changed from default admin to different + rename(DIR_MODIFICATION . 'admin/', DIR_MODIFICATION . $this->adminFolderName()); + } + + private function adminFolderName() + { + return str_replace([DIR_OPENCART, '/'], '', DIR_APPLICATION); } } diff --git a/upload/admin/controller/module/ces_ocmod.php b/upload/admin/controller/module/ces_ocmod.php index faf844e..8cb96c6 100644 --- a/upload/admin/controller/module/ces_ocmod.php +++ b/upload/admin/controller/module/ces_ocmod.php @@ -173,7 +173,7 @@ public function save(): void $this->response->setOutput(json_encode($json)); } - public function installEvents() + public function installEvents(): void { $this->load->model('setting/event'); @@ -191,7 +191,7 @@ public function installEvents() } } - public function uninstallEvents() + public function uninstallEvents(): void { $this->load->model('setting/event'); diff --git a/upload/install.json b/upload/install.json index a4ab6ff..55e93c1 100644 --- a/upload/install.json +++ b/upload/install.json @@ -1,6 +1,6 @@ { "name": "CES Ocmod", - "version": "1.0", + "version": "1.1", "author": "CodeEshop", "link": "https://codeeshop.com" } \ No newline at end of file diff --git a/upload/system/library/ces/cesOcmodLib.php b/upload/system/library/ces/cesOcmodLib.php index eca34f6..8b3ff9d 100644 --- a/upload/system/library/ces/cesOcmodLib.php +++ b/upload/system/library/ces/cesOcmodLib.php @@ -8,7 +8,7 @@ trait cesOcmodLib { protected $eName = 'module_ces_ocmod'; protected $ePath = 'extension/ces_ocmod/module/ces_ocmod'; protected $ePathEvent = 'extension/ces_ocmod/event'; - protected $eVersion = '1.0.0'; + protected $eVersion = '1.1.0'; protected $separator = '.'; protected $ePathMarketplace = 'extension/ces_ocmod/marketplace'; diff --git a/upload/system/modification.xml b/upload/system/modification.xml index b4bbf46..e80851b 100644 --- a/upload/system/modification.xml +++ b/upload/system/modification.xml @@ -37,5 +37,29 @@ ]]> + + + root) + 1);]]> + + + loader = new \Twig\Loader\FilesystemLoader('/', $this->root); + ]]> + + + + + root) + 1);]]> + + + loader = new \Twig\Loader\FilesystemLoader('/', DIR_STORAGE); + $file = substr($file, strlen(DIR_STORAGE)); + } + ]]> + +