Need new hook

Re: [jenolan] Need new hook

By jenolan - March 29, 2011

Another issue .. can't create an index for a table in the schema ini (at least that I can find).

Oh yeah .. being able to hide a table totally, I know I could create one outside the name space but I want to keep everything installable/uninstallable from within cms Builder [cool]
---
<?= "Jenolan(Larry) :: Coding Since 1973" ?>
Peace and Long Life

Re: [jenolan] Need new hook

By Dave - March 29, 2011

Hi Jenolan,

For adding a field after the fact the easiest is to do it with the record_postsave hook and update it after the fact. This gives you the record number as well if you need that (which isn't available beforehand when creating records).

It's true that it's not the most efficient way, but save doesn't get called very much (relative to the code on viewer pages) and it's still fractions of a second.

As for indexes, that is on our (and my) wishlist, but for now you need to do it manually. A good place would be in the same code that creates your schemas when the plugin is actived.

For hiding tables, we usually set menuHidden = 1 in the schema which hides it from the menu but still have it accessible by direct link or from the section editors menu. Also we prefix tables with _ so as to not conflict with any user created tables (user tables must start with a letter).

Hope that helps! Any questions let me know.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Need new hook

By jenolan - March 29, 2011

Me really lost...

There is no hook called for plugin activate/deactivate for a hook pr have I missed something obvious?

Larry
---
<?= "Jenolan(Larry) :: Coding Since 1973" ?>
Peace and Long Life

Re: [jenolan] Need new hook

By jenolan - March 29, 2011

In plugin functions can you add a hook plugin_activate and plugin_deactivate (as per below) so that a plugin can do post process stuff.
function activatePlugin($file) {
global $SETTINGS;

// test for errors - if this dies it won't activate the plugin
$pluginsDir = "{$GLOBALS['PROGRAM_DIR']}/plugins";
include "$pluginsDir/$file";

// add plugin to list
$activePluginFiles = array();
$activePluginFiles[$file] = 1;
foreach (preg_split('/,\s+/', $SETTINGS['activePlugins']) as $activeFile) {
$activePluginFiles[$activeFile] = 1;

}

// save settings
$GLOBALS['SETTINGS']['activePlugins'] = join(', ', array_keys($activePluginFiles));
saveINI(SETTINGS_FILEPATH, $SETTINGS, 'sortKeys');
doAction( 'plugin_activate', $file );

}

function deactivatePlugin($file) {
global $SETTINGS;

// remove plugin from list
$activePluginFiles = array();
foreach (preg_split('/,\s+/', $SETTINGS['activePlugins']) as $activeFile) {
$activePluginFiles[$activeFile] = 1;
}
unset($activePluginFiles[$file]);

// save settings
$GLOBALS['SETTINGS']['activePlugins'] = join(', ', array_keys($activePluginFiles));
saveINI(SETTINGS_FILEPATH, $SETTINGS, 'sortKeys');
doAction( 'plugin_deactivate', $file );

}

---
<?= "Jenolan(Larry) :: Coding Since 1973" ?>
Peace and Long Life

Re: [jenolan] Need new hook

By Dave - March 31, 2011

Hi jenolan,

That's a good idea, I've added both of those to 2.08. You can add them to your code manually and know they'll be in the next release.

Another way I sometimes create schemas is like this (from outgoing SMSl):

$GLOBALS['OUTGOING_SMS_TABLENAME'] = '_outgoing_sms';
addAction('admin_postlogin', '_outgoingSMS_createSchema', null, 0);
...

//
function _outgoingSMS_createSchema() {
$tableName = $GLOBALS['OUTGOING_SMS_TABLENAME'];
$sourcePath = dirname(__FILE__) . "/$tableName.ini.php";
createSchemaFromFile( $sourcePath );
}


And then I add other code in there as needed.

Let me know any other questions or suggestions. Thanks!
Dave Edis - Senior Developer
interactivetools.com