jackmaessen LiteCart Fan De Netherlands Membro desde dez 2022 jackmaessen 2 out 2024 18:39 I have 2 vmods which grab to the same file. So i am wondering if it is possible when a certain vmod is set to enabled, another one is automatically set to disabled and vice versa. So: only one of these 2 vmods can be enabled. But both should have the opportunity to set to disabled at the same time Possible scenarios: vmod 1: enabled vmod 2: disabled vmod 1: disabled vmod 2: enabled vmod 1: disabled vmod 2: disabled NOT possible scenario: vmod 1: enabled vmod 2: enabled
tim Founder De Sweden Membro desde mai 2013 tim 3 out 2024 19:01 Perhaps accessing the entity is what you are looking for? $vmod->data['status'] = 0; $vmod->save();``` Or use the file system directly: ```if (file_exists($file = FS_DIR_STORAGE . 'vmods/modfile.xml')) { rename($file, preg_replace('#\.xml$#', '.disabled', $file)); }``` You can use install or uninstall in the vmod for executing the commands.
jackmaessen LiteCart Fan De Netherlands Membro desde dez 2022 jackmaessen 3 out 2024 20:10 Thanks. I understand. I am going to play with it
s22_tech Moderator De United States Membro desde out 2019 s22_tech 4 out 2024 14:39 Good idea! I think this can open up new possibilities for us. If you opt for the "file system" version above, you could also use str_replace instead of preg_replace since it's only a simple string. No need to breakout the heavy artillery for this one. 🤣 rename($file, str_replace('.xml', '.disabled', $file)); }```
tim Founder De Sweden Membro desde mai 2013 tim 4 out 2024 15:50 @s22_tech str_replace() will replace all matches anywhere in the string. S22.xmlparser.xml >> S22.disabledparser.disabled. Although unlikely someone would name it that. I learned the hard way over the years not to rely on str_replace(). Anything that can go wrong will eventually go wrong. ;) I use regex to make sure it's the end of string $. Here is another option using pathinfo(): rename($file, dirname($file) .'/'. pathinfo($file, PATHINFO_FILENAME) . '.disabled'); }```
s22_tech Moderator De United States Membro desde out 2019 s22_tech 4 out 2024 17:21 @tim [quote]Anything that can go wrong will eventually go wrong.[/quote] How could I have forgotten that gem?!? 🤣 So true.
jackmaessen LiteCart Fan De Netherlands Membro desde dez 2022 jackmaessen 5 out 2024 10:47 Works great: (admin/vmods.app/vmods.inc.php) if (!empty($_POST['enable'])) { // if chosen enable if($vmod == 'minicart_overlay_1.disabled') { if (file_exists($file = FS_DIR_STORAGE . 'vmods/minicart_overlay_2.xml')) { rename($file, preg_replace('#\.xml$#', '.disabled', $file)); } } elseif($vmod == 'minicart_overlay_2.disabled') { if (file_exists($file = FS_DIR_STORAGE . 'vmods/minicart_overlay_1.xml')) { rename($file, preg_replace('#\.xml$#', '.disabled', $file)); } } elseif (!is_file(FS_DIR_STORAGE . 'vmods/' . pathinfo($vmod, PATHINFO_FILENAME) .'.disabled')) continue; rename(FS_DIR_STORAGE . 'vmods/' . pathinfo($vmod, PATHINFO_FILENAME) .'.disabled', FS_DIR_STORAGE . 'vmods/' . pathinfo($vmod, PATHINFO_FILENAME) .'.xml'); } else { // if chosen disable if (!is_file(FS_DIR_STORAGE . 'vmods/' . pathinfo($vmod, PATHINFO_FILENAME) .'.xml')) continue; rename(FS_DIR_STORAGE . 'vmods/' . pathinfo($vmod, PATHINFO_FILENAME) .'.xml', FS_DIR_STORAGE . 'vmods/' . pathinfo($vmod, PATHINFO_FILENAME) .'.disabled'); } }```