Exemple #1
0
/**
* Puts the datastructures for this plugin into the Geeklog database
*
*/
function plugin_install_now()
{
    global $_CONF, $_TABLES, $_USER, $_DB_dbms, $GROUPS, $FEATURES, $MAPPINGS, $DEFVALUES, $base_path, $pi_name, $pi_display_name, $pi_version, $gl_version, $pi_url;
    COM_errorLog("Attempting to install the {$pi_display_name} plugin", 1);
    // create the plugin's groups
    $admin_group_id = 0;
    foreach ($GROUPS as $name => $desc) {
        COM_errorLog("Attempting to create {$name} group", 1);
        $grp_name = addslashes($name);
        $grp_desc = addslashes($desc);
        DB_query("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) VALUES ('{$grp_name}', '{$grp_desc}')", 1);
        if (DB_error()) {
            PLG_uninstall($pi_name);
            return false;
        }
        // replace the description with the new group id so we can use it later
        $GROUPS[$name] = DB_insertId();
        // assume that the first group is the plugin's Admin group
        if ($admin_group_id == 0) {
            $admin_group_id = $GROUPS[$name];
        }
    }
    // Create the plugin's table(s)
    $_SQL = array();
    if (file_exists($base_path . 'sql/' . $_DB_dbms . '_install.php')) {
        require_once $base_path . 'sql/' . $_DB_dbms . '_install.php';
    }
    if (count($_SQL) > 0) {
        $use_innodb = false;
        if ($_DB_dbms == 'mysql' && DB_getItem($_TABLES['vars'], 'value', "name = 'database_engine'") == 'InnoDB') {
            $use_innodb = true;
        }
        foreach ($_SQL as $sql) {
            $sql = str_replace('#group#', $admin_group_id, $sql);
            if ($use_innodb) {
                $sql = str_replace('MyISAM', 'InnoDB', $sql);
            }
            DB_query($sql);
            if (DB_error()) {
                COM_errorLog('Error creating table', 1);
                PLG_uninstall($pi_name);
                return false;
            }
        }
    }
    // Add the plugin's features
    COM_errorLog("Attempting to add {$pi_display_name} feature(s)", 1);
    foreach ($FEATURES as $feature => $desc) {
        $ft_name = addslashes($feature);
        $ft_desc = addslashes($desc);
        DB_query("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " . "VALUES ('{$ft_name}', '{$ft_desc}')", 1);
        if (DB_error()) {
            PLG_uninstall($pi_name);
            return false;
        }
        $feat_id = DB_insertId();
        if (isset($MAPPINGS[$feature])) {
            foreach ($MAPPINGS[$feature] as $group) {
                COM_errorLog("Adding {$feature} feature to the {$group} group", 1);
                DB_query("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ({$feat_id}, {$GROUPS[$group]})");
                if (DB_error()) {
                    PLG_uninstall($pi_name);
                    return false;
                }
            }
        }
    }
    // Add plugin's Admin group to the Root user group
    // (assumes that the Root group's ID is always 1)
    COM_errorLog("Attempting to give all users in the Root group access to the {$pi_display_name}'s Admin group", 1);
    DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES " . "({$admin_group_id}, NULL, 1)");
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
    }
    // Pre-populate tables or run any other SQL queries
    COM_errorLog('Inserting default data', 1);
    foreach ($DEFVALUES as $sql) {
        $sql = str_replace('#group#', $admin_group_id, $sql);
        DB_query($sql, 1);
        if (DB_error()) {
            PLG_uninstall($pi_name);
            return false;
        }
    }
    // Load the online configuration records
    if (function_exists('plugin_load_configuration')) {
        if (!plugin_load_configuration()) {
            PLG_uninstall($pi_name);
            return false;
        }
    }
    // Finally, register the plugin with Geeklog
    COM_errorLog("Registering {$pi_display_name} plugin with Geeklog", 1);
    // silently delete an existing entry
    DB_delete($_TABLES['plugins'], 'pi_name', $pi_name);
    DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) VALUES " . "('{$pi_name}', '{$pi_version}', '{$gl_version}', '{$pi_url}', 1)");
    if (DB_error()) {
        PLG_uninstall($pi_name);
        return false;
    }
    // give the plugin a chance to perform any post-install operations
    if (function_exists('plugin_postinstall')) {
        if (!plugin_postinstall()) {
            PLG_uninstall($pi_name);
            return false;
        }
    }
    COM_errorLog("Successfully installed the {$pi_display_name} plugin!", 1);
    return true;
}
Exemple #2
0
/**
* Creates the datastructures for this plugin into the Geeklog database
* Note: Corresponding uninstall routine is in functions.inc
* @return    boolean    True if successful False otherwise
*/
function plugin_install_now()
{
    global $pi_name, $pi_version, $gl_version, $pi_url, $NEWTABLE, $DEFVALUES, $NEWFEATURE;
    global $_TABLES, $_CONF, $_FM_TABLES;
    COM_errorLog("Attempting to install the {$pi_name} Plugin", 1);
    $uninstall_plugin = 'plugin_uninstall_' . $pi_name;
    // Create the Plugins Tables
    require_once $_CONF['path'] . 'plugins/filemgmt/sql/filemgmt_sql_install.php';
    for ($i = 1; $i <= count($_SQL); $i++) {
        $progress .= "executing " . current($_SQL) . "<br>\n";
        COM_errorLOG("executing " . current($_SQL));
        DB_query(current($_SQL), '1');
        if (DB_error()) {
            COM_errorLog("Error Creating {$table} table", 1);
            $uninstall_plugin('DeletePlugin');
            return false;
            exit;
        }
        next($_SQL);
    }
    COM_errorLog("Success - Created {$table} table", 1);
    // Insert Default Data
    foreach ($DEFVALUES as $table => $sql) {
        COM_errorLog("Inserting default data into {$table} table", 1);
        DB_query($sql, 1);
        if (DB_error()) {
            COM_errorLog("Error inserting default data into {$table} table", 1);
            $uninstall_plugin();
            return false;
            exit;
        }
        COM_errorLog("Success - inserting data into {$table} table", 1);
    }
    // Create the plugin admin security group
    COM_errorLog("Attempting to create {$pi_name} admin group", 1);
    DB_query("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr) " . "VALUES ('{$pi_name} Admin', 'Users in this group can administer the {$pi_name} plugin')", 1);
    if (DB_error()) {
        $uninstall_plugin();
        return false;
        exit;
    }
    COM_errorLog('...success', 1);
    $group_id = DB_insertId();
    // Save the grp id for later uninstall
    COM_errorLog('About to save group_id to vars table for use during uninstall', 1);
    DB_query("INSERT INTO {$_TABLES['vars']} VALUES ('{$pi_name}_admingrp_id', {$group_id})", 1);
    if (DB_error()) {
        $uninstall_plugin();
        return false;
        exit;
    }
    COM_errorLog('...success', 1);
    // Add plugin Features
    foreach ($NEWFEATURE as $feature => $desc) {
        COM_errorLog("Adding {$feature} feature", 1);
        DB_query("INSERT INTO {$_TABLES['features']} (ft_name, ft_descr) " . "VALUES ('{$feature}','{$desc}')", 1);
        if (DB_error()) {
            COM_errorLog("Failure adding {$feature} feature", 1);
            $uninstall_plugin();
            return false;
            exit;
        }
        $feat_id = DB_insertId();
        COM_errorLog("Success", 1);
        COM_errorLog("Adding {$feature} feature to admin group", 1);
        DB_query("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ({$feat_id}, {$group_id})");
        if (DB_error()) {
            COM_errorLog("Failure adding {$feature} feature to admin group", 1);
            $uninstall_plugin();
            return false;
            exit;
        }
        COM_errorLog("Success", 1);
    }
    // OK, now give Root users access to this plugin now! NOTE: Root group should always be 1
    COM_errorLog("Attempting to give all users in Root group access to {$pi_name} admin group", 1);
    DB_query("INSERT INTO {$_TABLES['group_assignments']} VALUES ({$group_id}, NULL, 1)");
    if (DB_error()) {
        $uninstall_plugin();
        return false;
        exit;
    }
    // Load the online configuration records
    if (function_exists('plugin_load_configuration')) {
        if (!plugin_load_configuration()) {
            $uninstall_plugin();
            return false;
            exit;
        }
    }
    // Register the plugin with Geeklog
    COM_errorLog("Registering {$pi_name} plugin with Geeklog", 1);
    DB_delete($_TABLES['plugins'], 'pi_name', $pi_name);
    DB_query("INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_homepage, pi_enabled) " . "VALUES ('{$pi_name}', '{$pi_version}', '{$gl_version}', '{$pi_url}', 1)");
    if (DB_error()) {
        $uninstall_plugin();
        return false;
        exit;
    }
    COM_errorLog("Succesfully installed the {$pi_name} Plugin!", 1);
    return true;
}