install.php file structure

install.php file structure

by lapo nesi -
Number of replies: 1

I need to add a install.php file to a my local plugin, for exccuting some logics when the plugin is installed for the first time.


All clear to me, but i cannot find a way to make it works!

I've found no guide of how naming and convention for such type of file, so browsing code ive found that u need a function called:


functionxmldb_local_PLUGINNAME_install(){}


but this give me some errors back:

Exception - Call to undefined function xmldb_local_PLUGINNAME_install()


if i put the code without the function, all works, but the script isn't executed at the install of the plugin.

I am trying to understand if importing of classes at the top of "install.php" can broke all, i cannot find example anywhere!

As I need a namespace to for using some external functions it can be a problem too?




Average of ratings: -
In reply to lapo nesi

Re: install.php file structure

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

As an example local_reminders implements this function even if it doesn't do anything with it:

function xmldb_local_reminders_install() {

    // What should be done when the plugin is installed for the first time.

}

So in the function name xmldb_local_reminders_install(): local is the plugin type (it's in the local subfolder in the Moodle source code folder) and reminders is the plugin directory (the plugin source code is in the local/reminders subfolder).

There's also a description in the dev docs.

If you're still stuck, tell us the name of the plugin as it appears in $plugin->component in version.php.