Added complete install/uninstall feature for plugins, allowing for interface-based configurable plugins (soon extending to allow custom course tools)

skala
Yannick Warnier 15 years ago
parent 8770320334
commit 2be3d5d69e
  1. 1
      documentation/changelog.html
  2. 33
      main/admin/settings.lib.php
  3. 17
      main/inc/lib/add_course.lib.inc.php

@ -34,6 +34,7 @@
<li>The documents tool and the learn path tool can display vectorial images</li>
<li>An optional "Course (training) validation" feature has been implemented. When it is activated, teachers loose ability to create coursers. Teachers fill course requests instead. Then, after approval, the requested courses are created by the platform administrator. (Feature # 2099)</li>
<li>A new UI option "Fill with exemplary content" have been added to the forms about training/course creation. Now teachers and platform administrators are able to choose whether exemplary content should be put or not in the trainings/courses they are going to create. When a training/course is not created directly by a user, then the platform setting "Example material on training creation" is taken into account. (Feature # 539)</li>
<li>Added install/uninstall script possibilities for plugins (BT#1752)</li>
</ul>
<h3>Debugging</h3>
<ul>

@ -43,7 +43,6 @@ function handle_plugins() {
$user_id = api_get_user_id();
$category = $_GET['category'];
event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, $time, $user_id);
Display :: display_confirmation_message(get_lang('SettingsStored'));
}
@ -91,6 +90,8 @@ function handle_plugins() {
echo get_lang('Header');
echo '</th><th>';
echo get_lang('Footer');
echo '</th><th>';
echo get_lang('CourseTool');
echo '</th>';
echo '</tr>';
@ -137,6 +138,7 @@ function handle_plugins() {
display_plugin_cell('mycourses_menu', $plugin_info, $testplugin, $usedplugins);
display_plugin_cell('header', $plugin_info, $testplugin, $usedplugins);
display_plugin_cell('footer', $plugin_info, $testplugin, $usedplugins);
display_plugin_cell('course_tool_plugin', $plugin_info, $testplugin, $usedplugins);
echo '</tr>';
}
}
@ -398,20 +400,45 @@ function store_plugins() {
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
global $_configuration;
// Get a list of all current 'Plugins' settings
$installed_plugins = api_get_settings('Plugins','list',$_configuration['access_url']);
$shortlist_installed = array();
foreach ($installed_plugins as $plugin) {
$shortlist_installed[] = $plugin['subkey'];
}
$shortlist_installed = array_flip(array_flip($shortlist_installed));
// Step 1 : We remove all the plugins.
//$sql = "DELETE FROM $table_settings_current WHERE category='Plugins'";
//Database::query($sql);
$r = api_delete_category_settings('Plugins', $_configuration['access_url']);
$shortlist_required = array();
// Step 2: Looping through all the post values we only store these which are really a valid plugin location.
foreach ($_POST as $form_name => $formvalue) {
$form_name_elements = explode('-', $form_name);
if (is_valid_plugin_location($form_name_elements[1])) {
$shortlist_required[] = $form_name_elements[0];
//$sql = "INSERT into $table_settings_current (variable,category,selected_value) VALUES ('".$form_name_elements['1']."','Plugins','".$form_name_elements['0']."')";
//Database::query($sql);
api_add_setting($form_name_elements['0'], $form_name_elements['1'], $form_name_elements['0'], null, 'Plugins', $form_name_elements['0'], null, null, null, $_configuration['access_url'], 1);
// check if there is an install procedure
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$form_name_elements[0].'/install.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the install procedure
include $pluginpath;
}
}
}
foreach ($shortlist_installed as $plugin) {
// if one plugin was really deleted, execute the uninstall script
if (!in_array($plugin,$shortlist_required)) {
// check if there is an install procedure
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin.'/uninstall.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the install procedure
include $pluginpath;
}
}
}
}
/**
@ -419,7 +446,7 @@ function store_plugins() {
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function is_valid_plugin_location($location) {
static $valid_locations = array('loginpage_main', 'loginpage_menu', 'campushomepage_main', 'campushomepage_menu', 'mycourses_main', 'mycourses_menu', 'header', 'footer');
static $valid_locations = array('loginpage_main', 'loginpage_menu', 'campushomepage_main', 'campushomepage_menu', 'mycourses_main', 'mycourses_menu', 'header', 'footer', 'course_tool_plugin');
return in_array($location, $valid_locations);
}

@ -2053,6 +2053,7 @@ function fill_Db_course($course_db_name, $course_repository, $language, $default
}
global $_configuration, $_user;
$cdb = $course_db_name; //save it for plugins, later on
$course_db_name = $_configuration['table_prefix'].$course_db_name.$_configuration['db_glue'];
@ -2392,6 +2393,22 @@ function fill_Db_course($course_db_name, $course_repository, $language, $default
Database::query("INSERT INTO `$TABLEFORUMPOSTS` VALUES (1, '".lang2db(get_lang('ExampleThread'))."', '".lang2db(get_lang('ExampleThreadContent'))."', 1, 1, 1, '', NOW(), 0, 0, 1)");
}
// PLUGINS - if an installed plugin has a course_install.php file, execute it
$installed_plugins = api_get_settings('Plugins','list',$_configuration['access_url']);
$shortlist_installed = array();
foreach ($installed_plugins as $plugin) {
$shortlist_installed[] = $plugin['subkey'];
}
$shortlist_installed = array_flip(array_flip($shortlist_installed));
foreach ($shortlist_installed as $plugin) {
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin.'/course_install.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the install procedure
include $pluginpath;
}
}
//end of installed plugins alterations
$language_interface = $language_interface_tmp;

Loading…
Cancel
Save