How to disable a certain vmod if another one is set to enabled

LiteCart Fan
De Netherlands
Membro desde dez 2022

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

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.
LiteCart Fan
De Netherlands
Membro desde dez 2022

Thanks. I understand. I am going to play with it

Moderator
De United States
Membro desde out 2019

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

@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');
}```
Moderator
De United States
Membro desde out 2019

@tim 
[quote]Anything that can go wrong will eventually go wrong.[/quote]
How could I have forgotten that gem?!? 🤣  So true.

LiteCart Fan
De Netherlands
Membro desde dez 2022

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');
        }
}```
Tu
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.