From: sam_marshall Date: Fri, 14 Jul 2006 11:17:46 +0000 (+0000) Subject: Added hooks so that blocks can create functions that are run when they are installed... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=44c55d4662a95aaccf5444e5c35fff4b89890e9e;p=moodle.git Added hooks so that blocks can create functions that are run when they are installed and uninstalled. The base implementation does nothing. --- diff --git a/admin/blocks.php b/admin/blocks.php index 32553d9992..76f4c9f98b 100644 --- a/admin/blocks.php +++ b/admin/blocks.php @@ -89,6 +89,9 @@ exit; } else { + // Inform block it's about to be deleted + block_instance($block->name)->before_delete(); + // Delete block if (!delete_records('block', 'id', $block->id)) { notify("Error occurred while deleting the $strblockname record from blocks table"); diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index b18f85f032..a6ffbdca4c 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -108,6 +108,20 @@ class block_base { function __construct() { $this->block_base(); } + + /** + * Function that can be overridden to do extra setup after + * the database install. (Called once per block, not per instance!) + */ + function after_install() { + } + + /** + * Function that can be overridden to do extra cleanup before + * the database tables are deleted. (Called once per block, not per instance!) + */ + function before_delete() { + } /** * Returns the block name, as present in the class name, diff --git a/lib/blocklib.php b/lib/blocklib.php index 2b0cf5927f..c73a53b83f 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1130,6 +1130,7 @@ function upgrade_blocks_plugins($continueto) { if (!is_dir($fullblock .'/db/') || modify_database($fullblock .'/db/'. $CFG->dbtype .'.sql')) { $db->debug = false; if ($block->id = insert_record('block', $block)) { + $blockobj->after_install(); notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess'); echo '
'; } else { @@ -1173,4 +1174,4 @@ function upgrade_blocks_plugins($continueto) { } } -?> +?> \ No newline at end of file