7

I have written a module that uses vqmod for opencart. How can I check if vqmod is installed from within the admin module?

I would like to display a warning inside of the module that checks if vqmod is installed? Even better would be to check if it also has correct write permission to generate cached files and write to the vamod.log

What is the best way of doing this?

PS: it would be cool if you could tag questions with vqmod. I dont have enough reputation to create a new tag.

Haroon
  • 496
  • 5
  • 14
  • 31
John Magnolia
  • 16,769
  • 36
  • 159
  • 270
  • if you have ftp access you can just check to see if the directory exists,no? i cant create tags either so for now just xml. – Rooster May 02 '12 at 15:04
  • You could try checking that the vqmod.log exists and is being written to (i.e. file last changed date). This assumes you don't have `$vqmod->logging = FALSE;` in index.php. Normally you set it up and forget it. I'm assuming youre trying to implement some sort of plug-in installer? – Brad May 02 '12 at 15:33
  • @Brad no it's just a normal module, I just want to add a couple of extra feature to check that vqmod set up correctly. Hopefully reduce the amount of support comments – John Magnolia May 02 '12 at 15:35
  • @Brad in some cases if there is no errors then the vqmod.log file wont exist until there is an error. – John Magnolia May 02 '12 at 15:35
  • Then I guess you need to check the vqmod/cache for the file existing if you know the name of the file. Which you will if you've written the XML config for it. Does that help? – Brad May 02 '12 at 15:49

4 Answers4

6
/vqmod/install

if it is installed it will tell you "vqmod is already installed"

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
jaja
  • 61
  • 1
  • 2
2

To check via code, you would need to do

global $vqmod;
if(!empty($vqmod) && is_a($vqmod, 'VQMod')) {
    // INSTALLED
} else {
    //
}

While @NADH's is along the right lines, it only checks that vqmod's class has been included, not that it's been set to the $vqmod variable

Edit

As of 2.4.0, this will no longer work, and it's recommended to use NADH's method

Jay Gilford
  • 15,141
  • 5
  • 37
  • 56
  • No sorry, I mean from within the module code I want to do something like: if(!$vqmodInstalled) { die('install vqmod first'); } – John Magnolia May 02 '12 at 15:27
  • @John. In your original question you asked "check if it also has correct write permission to generate cached files". How does this answer address this issue? – Brad May 02 '12 at 17:26
  • @Brad it answers half my issues. The caching would of just been a nice requirement although wasn't essential. – John Magnolia May 02 '12 at 17:48
  • To be fair I think checking that cache files are written is a little outside the scope of a modification to check. There is also the issue that files can be cached using `$vqmod->useCache = true;` which would mean it may not have written accurately – Jay Gilford May 02 '12 at 17:58
2
<?php
    if(class_exists('VQMod')) {
         // vqmod exists
    }
?>
Nadh
  • 6,987
  • 2
  • 21
  • 21
1

Based on your comments @John, since you're looking for confirmation that VQmod is installed and also executing correctly, the safest thing to do to is check for the filename you are expecting to appear in the vqmod/cache directory. You'll know the filename if you have created the vqmod/xml definition file yourself.

You could also check for the VQMod class existing like @NADH suggested, but it doesn't mean that its working correctly. A bit like writing unit tests, always assert on the desired output. In this case its' the cache file you are creating.

Brad
  • 15,186
  • 11
  • 60
  • 74