]> git.mjollnir.org Git - moodle.git/commitdiff
Added hooks so that blocks can create functions that are run when they are installed...
authorsam_marshall <sam_marshall>
Fri, 14 Jul 2006 11:17:46 +0000 (11:17 +0000)
committersam_marshall <sam_marshall>
Fri, 14 Jul 2006 11:17:46 +0000 (11:17 +0000)
admin/blocks.php
blocks/moodleblock.class.php
lib/blocklib.php

index 32553d99929044e4ddce18b17fd921e63f9af681..76f4c9f98b416b11195a2d10a1761603457ef5e4 100644 (file)
@@ -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");
index b18f85f0320c0dfc7cfd8858ae643f2773dd5250..a6ffbdca4ce9801be65786d913d2bf06b4244f63 100644 (file)
@@ -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,
index 2b0cf5927f2ab4d548d9576f054956e123f40568..c73a53b83f3825c76ba3430c35ce3c402365374d 100644 (file)
@@ -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) {
     }
 }
 
-?>
+?>
\ No newline at end of file