WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: BlackBird on January 06, 2011, 03:23:12 PM

Title: Howto: Install a droplet with a module
Post by: BlackBird on January 06, 2011, 03:23:12 PM
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):

Code: [Select]
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_impor t() function returns an array you may use to check out the result:

Code: [Select]
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:

Code: [Select]
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.