Howto: Install a droplet with a module

BlackBird

#1
Some modules need to install a Droplet. The problem is that the source code has to be quoted correctly, and if the code changes, you will have to remember to include it into your install.php and upgrade.php.

Since Droplets version 1.4, Droplets can easily be exported and imported by the Droplets module. So what's easier than to use this feature?

Prerequisites

You should check for the Droplets version in your install.php or put it into your precheck.php.

How to use it

Of course, you will have to export the Droplet(s) using the Droplets Admin Tool first. After doing this, copy the ZIP file into your module's folder. I prefer to put it into a sub folder named "install", but of course you may choose another.

Now, add just two lines to your install.php / upgrade.php (Example):


include_once WB_PATH.'/droplets/functions.inc.php';
wb_unpack_and_import( WB_PATH.'<MODULENAME>/install/<FILENAME>.zip', WB_PATH.'/temp/unzip/' );


That's it! Of course, you will have to replace <MODULENAME> with the path name of your module, and <FILENAME>.zip with the correct file name. ;)

The wb_unpack_and_import() function returns an array you may use to check out the result:


array( 'count' => $count, 'errors' => $errors, 'imported'=> $imports );



KeyExplanation
countThe number of droplets imported
errorsArray of errors encountered ( <Droplet> => <Errormsg> )
importedArray of names of imported droplets ( <Droplet> => 1 )

So, to check for success, try this:


include_once WB_PATH.'/droplets/functions.inc.php';
list( $count, $errors, $imported ) = wb_unpack_and_import( WB_PATH.'<MODULENAME>/install/<FILENAME>.zip', WB_PATH.'/temp/unzip/' );
if ( count( $errors ) > 0 ) {
   // your error handling here
}


Try this and let me know your opinion.
[url=http://wbaddons.webbird.de]http://wbaddons.webbird.de[/url] [url=http://www.WebsiteBaker.org/forum/index.php/topic,27476.msg189845.html#msg189845]Don't miss this[/url]