/**
 * Upgrade custom fields plugin
 *
 * @param $oldversion Version to upgrade from
 */
function plugin_customfields_upgrade($oldversion)
{
    global $DB;
    // Upgrade logging feature
    if ($oldversion < 101) {
        plugin_customfields_upgradeto101();
    }
    // Upgrade date fields to be compatible with GLPI 0.72+
    if ($oldversion < 110) {
        plugin_customfields_upgradeto110();
    }
    // Add a column to indicate if a field is required
    if ($oldversion < 112) {
        plugin_customfields_upgradeto112();
    }
    // Add a column to indicate which entities to show the field with
    // Remove column for hidden field, use blank in entites
    // field to replace this functionality
    // Add restricted field to allow field-based permissions
    if ($oldversion < 113) {
        plugin_customfields_upgradeto113();
    }
    // Upgrade fields to be compatable with mysql strict mode
    if ($oldversion < 116) {
        plugin_customfields_upgradeto116();
        echo 'finished.';
        Html::glpi_flush();
    }
    if ($oldversion < 117) {
        plugin_customfields_upgradeto117();
    }
    if ($oldversion < 12) {
        plugin_customfields_upgradeto12();
    }
    if ($oldversion < 150) {
        plugin_customfields_upgradeto150();
    }
    if ($oldversion < 160) {
        plugin_customfields_upgradeto160();
    }
    if ($oldversion < 170) {
        plugin_customfields_upgradeto170();
    }
    if (CUSTOMFIELDS_AUTOACTIVATE) {
        plugin_customfields_activate_all_types();
    }
}
Example #2
0
/**
 * Checks prerequisites before install. May print errors or add message after
 * redirect
 *
 * @return bool Success
 */
function plugin_customfields_check_prerequisites()
{
    if (GLPI_VERSION >= 0.84) {
        $plugin = new Plugin();
        // Automatically upgrade db (if necessary) when plugin is activated
        if (Session::haveRight('config', 'w') && $plugin->isActivated("customfields")) {
            global $DB;
            // Check the version of the database tables.
            $query = "SELECT `enabled`\r\n                    FROM `glpi_plugin_customfields_itemtypes`\r\n                    WHERE itemtype='Version'\r\n                    ORDER BY `enabled` DESC\r\n                    LIMIT 1;";
            $result = $DB->query($query);
            $data = $DB->fetch_array($result);
            //Version of the last modification to the plugin tables' structure
            $dbversion = $data['enabled'];
            if ($dbversion == 12) {
                $dbversion = 120;
            }
            if ($dbversion < CUSTOMFIELDS_DB_VERSION_REQUIRED) {
                plugin_customfields_upgrade($dbversion);
            }
            if (CUSTOMFIELDS_AUTOACTIVATE) {
                plugin_customfields_activate_all_types();
            }
        }
        return true;
    } else {
        echo "This plugin requires GLPI version 0.84 or higher";
    }
}