Commit de22acac authored by Penny Leach's avatar Penny Leach
Browse files

base class for plugins now used in upgrade_plugin

(cron/postinst/events). fixed a few todos too.
parent 691e51a8
...@@ -187,7 +187,6 @@ function upgrade_plugin($upgrade) { ...@@ -187,7 +187,6 @@ function upgrade_plugin($upgrade) {
$db->StartTrans(); $db->StartTrans();
if (!empty($upgrade->install)) { if (!empty($upgrade->install)) {
// @todo add to installed_artefacts
if (is_readable($location . 'install.xml')) { if (is_readable($location . 'install.xml')) {
$status = install_from_xmldb_file($location . 'install.xml'); $status = install_from_xmldb_file($location . 'install.xml');
} }
...@@ -196,13 +195,15 @@ function upgrade_plugin($upgrade) { ...@@ -196,13 +195,15 @@ function upgrade_plugin($upgrade) {
} }
} }
else { else {
require_once($location . 'upgrade.php'); if (is_readable($location . 'upgrade.php')) {
// @todo check file exists first - reasonable for it not to have require_once($location . 'upgrade.php');
// db tables at all. should still insert version number and cron etc $function = 'xmldb_' . $plugintype . '_' . $pluginname . '_upgrade';
$function = 'xmldb_' . $plugintype . '_' . $pluginname . '_upgrade'; $status = $function($upgrade->from);
$status = $function($upgrade->from); }
else {
$status = true;
}
} }
if (!$status || $db->HasFailedTrans()) { if (!$status || $db->HasFailedTrans()) {
$db->CompleteTrans(); $db->CompleteTrans();
throw new DatalibException("Failed to upgrade $upgrade->name"); throw new DatalibException("Failed to upgrade $upgrade->name");
...@@ -221,7 +222,17 @@ function upgrade_plugin($upgrade) { ...@@ -221,7 +222,17 @@ function upgrade_plugin($upgrade) {
update_record($installtable, $installed, 'name'); update_record($installtable, $installed, 'name');
} }
// @todo here is where plugins register events and set their crons up // postinst stuff...
safe_require($plugintype, $pluginname, 'lib.php');
$pcname = 'Plugin' . ucfirst($plugintype) . ucfirst($pluginname);
$crons = call_static_method($pcname, 'get_cron');
// @todo save cronjobs.
$events = call_static_method($pcname, 'get_event_subscriptions');
// @todo save event subscriptions
call_static_method($pcname,'postinst');
if ($db->HasFailedTrans()) { if ($db->HasFailedTrans()) {
$status = false; $status = false;
...@@ -758,4 +769,23 @@ function xmldb_dbg($message) { ...@@ -758,4 +769,23 @@ function xmldb_dbg($message) {
} }
define('DEBUG_DEVELOPER', 'whocares'); define('DEBUG_DEVELOPER', 'whocares');
/**
* Base class for all plugintypes.
* @abstract
*/
abstract class Plugin {
public static function get_cron() {
return array();
}
public static function get_event_subscriptions() {
return array();
}
public static function postinst() {
return true;
}
}
?> ?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment