General developer forum

 
 
Picture of Vitaly Potenko
The best way to ensure a certain plugin is installed in Moodle
 

Hi! What's the best way to check in code that some plugin (say, by its shortname - the plugin directory name) is installed in system? What functions or classes should I use to do it?

 
Average of ratings: -
Picture of Rex Lorenzo
Re: The best way to ensure a certain plugin is installed in Moodle
Group DevelopersGroup Particularly helpful MoodlersGroup Testers

Try look at the lib/moodlelib.php function moodle_needs_upgrading. It calls useful functions like get_plugin_list().

 
Average of ratings:Useful (1)
Picture of Vitaly Potenko
Re: The best way to ensure a certain plugin is installed in Moodle
 

Thanks Rex, I'm aware of this function and some other functions which Moodle uses for installation and upgrading. I just hoped that Moodle has a brilliant function, something like plugin_is_installed($pluginname, ...) so I just write a line of code and that's it. A good reason to make it myself.

 
Average of ratings: -
Picture of Jitendra Gaur
Re: The best way to ensure a certain plugin is installed in Moodle
 

Hi Vitaly,

You can use moodle(M2.3) default plugin manager code.

require_once('config.php');
require_once($CFG->libdir . '/pluginlib.php');


$pluginman = plugin_manager::instance();
$plugin_info = $pluginman->get_plugin_info('qtype_calculated');

print_object($plugin_info);

plugininfo_qtype Object
(
    [type] => qtype
    [typerootdir] => /Users/jitendra/Sites/moodle_23/question/type
    [name] => calculated
    [displayname] => Calculated
    [source] => std
    [rootdir] => /Users/jitendra/Sites/moodle_23/question/type/calculated
    [versiondisk] => 2012061700
    [versiondb] => 2012061700
    [versionrequires] => 2012061700
    [dependencies] => 
    [instances] => 
    [sortorder] => 
    [availableupdates] => 
)

You can pass the plugin name is the get_plugin_info() code and It will tell you about the plugin.But the problem with this code is that you have to specify the plugin type.

Hope it will help you.

 
Average of ratings: -