Permalink
Browse files

Added hooks so that blocks can create functions that are run when the…

…y are installed and uninstalled. The base implementation does nothing.
  • Loading branch information...
1 parent a62b843 commit 44c55d4662a95aaccf5444e5c35fff4b89890e9e sam_marshall committed Jul 14, 2006
Showing with 19 additions and 1 deletion.
  1. +3 −0 admin/blocks.php
  2. +14 −0 blocks/moodleblock.class.php
  3. +2 −1 lib/blocklib.php
View
@@ -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");
@@ -108,6 +108,20 @@ function 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,
View
@@ -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 '<hr />';
} else {
@@ -1173,4 +1174,4 @@ function upgrade_blocks_plugins($continueto) {
}
}
-?>
+?>

0 comments on commit 44c55d4

Please sign in to comment.