]> git.mjollnir.org Git - moodle.git/commitdiff
Preparation for Nuke blocks integration, and relaxing of requirements for
authordefacer <defacer>
Tue, 11 May 2004 16:08:03 +0000 (16:08 +0000)
committerdefacer <defacer>
Tue, 11 May 2004 16:08:03 +0000 (16:08 +0000)
block db upgrade scripts. We 're getting to a point where you can really
have a directory with just a single 20-line file for your block and Moodle
will do all the rest. Much like Nuke does now. That is A Good Thing! :-)

blocks/moodleblock.class.php
lib/blocklib.php

index c8fbd13f25e54d771bdeb28c4656729ceb25dc29..0f66e24d13900ae2afce4e080faac9fc1427fc64 100644 (file)
@@ -2,6 +2,7 @@
 
 define('BLOCK_TYPE_LIST',    1);
 define('BLOCK_TYPE_TEXT',    2);
+define('BLOCK_TYPE_NUKE',    3);
 
 class MoodleBlock {
     var $str;
@@ -59,6 +60,7 @@ class MoodleBlock {
         $this->get_content();
 
         switch($this->content_type) {
+            case BLOCK_TYPE_NUKE:
             case BLOCK_TYPE_TEXT:
                 if(empty($this->content->text) && empty($this->content->footer)) {
                     break;
@@ -162,7 +164,7 @@ class MoodleBlock {
             $errors[] = 'title_not_set';
             $correct = false;
         }
-        if(!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT))) {
+        if(!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT, BLOCK_TYPE_NUKE))) {
             $errors[] = 'invalid_content_type';
             $correct = false;
         }
@@ -212,4 +214,39 @@ class MoodleBlock {
     }
 }
 
+class MoodleBlock_Nuke extends MoodleBlock {
+    function get_content() {
+
+        // This whole thing begs to be written for PHP >= 4.3.0
+        // using glob();
+
+        global $CFG;
+        $dir = $CFG->dirroot.'/blocks/'.$this->name().'/nuke/';
+        if($dh = @opendir($dir)) {
+            while (($file = readdir($dh)) !== false) {
+                $regs = array();
+                if(ereg('^block\-(.*)\.php$', $file, $regs)) {
+                    $old = $_SERVER['PHP_SELF'];
+                    $_SERVER['PHP_SELF'] = 'index.php';
+
+                    // Do our best to suppress any spurious output
+                    ob_start();
+                    @include($dir.$file);
+                    ob_end_clean();
+
+                    // We should have $content set now
+                    $_SERVER['PHP_SELF'] = $old;
+                    if(!isset($content)) {
+                        return NULL;
+                    }
+                    return $this->content->text = $content;
+                }
+            }
+        }
+        else {
+            // nuke subdirectory does not exist
+        }
+    }
+}
+
 ?>
index 29f1c54c891d67bd45a29517c3bcb629cecd15b0..ad66a8ed430bbb2b064792fa94810175c83ae23e 100644 (file)
@@ -419,7 +419,7 @@ function upgrade_blocks_plugins($continueto) {
         error("No blocks installed!");
     }
 
-    @include_once($CFG->dirroot."/blocks/moodleblock.class.php");
+    include_once($CFG->dirroot."/blocks/moodleblock.class.php");
     if(!class_exists('moodleblock')) {
         error('Class MoodleBlock is not defined or file not found for /blocks/moodleblock.class.php');
     }
@@ -439,11 +439,13 @@ function upgrade_blocks_plugins($continueto) {
             continue;
         }
 
-        if ( is_readable("$fullblock/db/$CFG->dbtype.php")) {
-            include_once("$fullblock/db/$CFG->dbtype.php");  # defines upgrading function
-        } else {
-            $notices[] ="Block $blockname: $fullblock/db/$CFG->dbtype.php was not readable";
-            continue;
+        if ( is_dir("$fullblock/db/")) {
+            if ( is_readable("$fullblock/db/$CFG->dbtype.php")) {
+                include_once("$fullblock/db/$CFG->dbtype.php");  # defines upgrading function
+            } else {
+                $notices[] ="Block $blockname: $fullblock/db/$CFG->dbtype.php was not readable";
+                continue;
+            }
         }
 
         $classname = 'CourseBlock_'.$blockname;
@@ -536,7 +538,7 @@ function upgrade_blocks_plugins($continueto) {
             $updated_blocks = true;
             $db->debug = true;
             set_time_limit(0);  // To allow slow databases to complete the long SQL
-            if (modify_database("$fullblock/db/$CFG->dbtype.sql")) {
+            if (!is_dir("$fullblock/db/") || modify_database("$fullblock/db/$CFG->dbtype.sql")) {
                 $db->debug = false;
                 if ($block->id = insert_record('blocks', $block)) {
                     notify(get_string('blocksuccess', '', $blocktitle), 'green');