Esempio n. 1
0
/**
* Change the load order of a plugin
*
* @param    string  $pi_name    Name of the plugin
* @param    mixed   $where      Where to move the plugin specified by $pi_name.
*                               Valid values are "up" and "dn", which stand for
*                               "Move 'Up' or 'Down' through the load order"
*                               or any integer between 0 and 10000.
* @return   void
*
*/
function change_load_order($pi_name = '', $where = '')
{
    if (!empty($pi_name) && !empty($where)) {
        global $_CONF, $_TABLES;
        $q = "SELECT pi_load FROM {$_TABLES['plugins']} WHERE pi_name = '{$pi_name}'";
        $q = DB_query($q);
        if (DB_numRows($q) == 1) {
            // if the plugin exists
            $query = '';
            switch ($where) {
                case "up":
                    $A = DB_fetchArray($q);
                    if ($A['pi_load'] > 10) {
                        // no negative values
                        $query = "UPDATE {$_TABLES['plugins']} SET pi_load = pi_load-11 WHERE pi_name = '{$pi_name}'";
                    }
                    break;
                case "dn":
                    $query = "UPDATE {$_TABLES['plugins']} SET pi_load = pi_load+11 WHERE pi_name = '{$pi_name}'";
                    break;
                default:
                    if (is_numeric($where) && $where >= 0 && $where <= 10000) {
                        $where = (int) $where;
                        $query = "UPDATE {$_TABLES['plugins']} SET pi_load = {$where} WHERE pi_name = '{$pi_name}'";
                    } else {
                        COM_errorLog("plugins admin error: Attempt to assign an invalid load order '{$where}' to plugin '{$pi_name}'");
                    }
                    break;
            }
            if (!empty($query)) {
                DB_query($query);
                reorderplugins();
            }
        } else {
            COM_errorLog("plugins admin error: Attempt to move a non existent plugin: {$pi_name}");
        }
    }
}
Esempio n. 2
0
/**
*  Disables all plugins with unresolved dependencies
*  and resolves the load order for all enabled plugins.
*
* @return   bool    True or False, depending on whether it was
*                   necessary to alter the load order of a plugin
* @since            Geeklog 1.8.0
*/
function PLG_resolveDependencies()
{
    global $_PLUGINS, $_TABLES;
    $retval = '';
    $flag = true;
    // false means that all dependencies are resolved
    while ($flag) {
        // loop until ALL dependencies are satisfied
        $flag = false;
        // set this if any plugin has been disabled during the loop
        foreach ($_PLUGINS as $key => $pi_name) {
            if (!PLG_checkDependencies($pi_name)) {
                // plugin has unresolved dependencies
                // disable plugin;
                $flag = true;
                // disabling a plugin can break the dependencies of a plugin that has already been checked, remember to loop again
                PLG_enableStateChange($pi_name, false);
                DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $pi_name);
                PLG_pluginStateChange($pi_name, 'disabled');
                unset($_PLUGINS[$key]);
            }
        }
    }
    // automatically resolve load order for enabled plugins
    $index = 2000;
    // how far through the load order to push back plugins
    $maxqueries = 50;
    // just in case...
    $globalflag = false;
    // remember if we change the load order of any plugin
    $flag = true;
    // set true if we need another pass in the while loop
    while ($flag && $maxqueries) {
        // Now check if the load order is correct
        $flag = false;
        // get the load orders of all enabled plugins
        $q = DB_query("SELECT pi_name, pi_load FROM {$_TABLES['plugins']} WHERE pi_enabled='1'");
        $plo = array();
        // Plugins Load Order
        while ($a = DB_fetchArray($q)) {
            $plo[] = $a;
        }
        $params = array();
        foreach ($plo as $key => $value) {
            // for each available plugin
            $maxqueries--;
            $params = PLG_getParams($value['pi_name']);
            // get dependencies
            if (isset($params['requires']) && is_array($params['requires'])) {
                // if any
                foreach ($params['requires'] as $rkey => $rvalue) {
                    // process each dependency
                    if (isset($rvalue['plugin'])) {
                        // get the load order of the required plugin
                        foreach ($plo as $new_key => $new_value) {
                            if ($new_value['pi_name'] == $rvalue['plugin']) {
                                $dep_load = $new_value['pi_load'];
                                break;
                            }
                        }
                        if ($dep_load > $value['pi_load']) {
                            // incorrect load order
                            // move down the order
                            DB_query("UPDATE {$_TABLES['plugins']} SET pi_load = '{$index}' WHERE pi_name = '{$value['pi_name']}'");
                            $index++;
                            $flag = true;
                            $globalflag = true;
                        }
                    }
                }
            }
        }
    }
    reorderplugins();
    if ($globalflag == false) {
        return true;
        // no change
    } else {
        return false;
        // something changed
    }
}