]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17457 moved a lot of code into lib/db/install.php + other refactoring and cleanup
authorskodak <skodak>
Sun, 11 Jan 2009 09:41:48 +0000 (09:41 +0000)
committerskodak <skodak>
Sun, 11 Jan 2009 09:41:48 +0000 (09:41 +0000)
15 files changed:
admin/settings/courses.php
admin/settings/server.php
admin/settings/top.php
admin/settings/users.php
lib/adminlib.php
lib/blocklib.php
lib/completionlib.php
lib/db/install.php [new file with mode: 0644]
lib/db/upgrade.php
lib/moodlelib.php
login/index.php
mnet/environment.php
mnet/lib.php
mod/hotpot/lib.php
version.php

index a884a46dc42c38aceb16eeb6b99fd6cad1e6ad97..682729e3e8468e85c785c2c4f5fd7f1b8f2da57d 100644 (file)
@@ -15,108 +15,110 @@ if ($hassiteconfig
 
 /// Course Default Settings Page
 /// NOTE: these settings must be applied after all other settings because they depend on them
-    if (isset($CFG->maxbytes)) { // TODO: replace this hack by something better
-        ///main course settings
-        $temp = new admin_settingpage('coursesettings', get_string('coursesettings'));
-        $temp->add(new admin_settings_coursecat_select('moodlecourse/category', get_string('category'), get_string('coursehelpcategory'), 1));
-        $courseformats = get_list_of_plugins('course/format');
-        $formcourseformats = array();
-        foreach ($courseformats as $courseformat) {
-            $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
-            if ($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
-                $formcourseformats["$courseformat"] = get_string("format$courseformat");
-            }
+    ///main course settings
+    $temp = new admin_settingpage('coursesettings', get_string('coursesettings'));
+    $temp->add(new admin_settings_coursecat_select('moodlecourse/category', get_string('category'), get_string('coursehelpcategory'), 1));
+    $courseformats = get_list_of_plugins('course/format');
+    $formcourseformats = array();
+    foreach ($courseformats as $courseformat) {
+        $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
+        if ($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
+            $formcourseformats["$courseformat"] = get_string("format$courseformat");
         }
-        $temp->add(new admin_setting_configselect('moodlecourse/format', get_string('format'), get_string('coursehelpformat'), 'weeks',$formcourseformats));
-        for ($i=1; $i<=52; $i++) {
-            $sectionmenu[$i] = "$i";
-        }
-        $temp->add(new admin_setting_configselect('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 3,$sectionmenu));
-        $choices = array();
-        $choices['0'] = get_string('hiddensectionscollapsed');
-        $choices['1'] = get_string('hiddensectionsinvisible');
-        $temp->add(new admin_setting_configselect('moodlecourse/hiddensections', get_string('hiddensections'), get_string('coursehelphiddensections'), 0,$choices));
-        $options = range(0, 10);
-        $temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options));
-        $temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes'))));
-        $temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+    }
+    $temp->add(new admin_setting_configselect('moodlecourse/format', get_string('format'), get_string('coursehelpformat'), 'weeks',$formcourseformats));
+    for ($i=1; $i<=52; $i++) {
+        $sectionmenu[$i] = "$i";
+    }
+    $temp->add(new admin_setting_configselect('moodlecourse/numsections', get_string('numberweeks'), get_string('coursehelpnumberweeks'), 3,$sectionmenu));
+    $choices = array();
+    $choices['0'] = get_string('hiddensectionscollapsed');
+    $choices['1'] = get_string('hiddensectionsinvisible');
+    $temp->add(new admin_setting_configselect('moodlecourse/hiddensections', get_string('hiddensections'), get_string('coursehelphiddensections'), 0,$choices));
+    $options = range(0, 10);
+    $temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options));
+    $temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes'))));
+    $temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+    if (isset($CFG->maxbytes)) {
         $choices = get_max_upload_sizes($CFG->maxbytes);
-        $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices),$choices));
-        $temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
-
-        ///enrolement course settings
-        $temp->add(new admin_setting_heading('enrolhdr', get_string('enrolments'), ''));
-        require_once($CFG->dirroot.'/enrol/enrol.class.php');
-        $choices = array();
-        $modules = explode(',', $CFG->enrol_plugins_enabled);
-        foreach ($modules as $module) {
-            $name = get_string('enrolname', "enrol_$module");
-            $plugin = enrolment_factory::factory($module);
-            if (method_exists($plugin, 'print_entry')) {
-                $choices[$name] = $module;
-            }
-        }
-        asort($choices);
-        $choices = array_flip($choices);
-        $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
-        $temp->add(new admin_setting_configselect('moodlecourse/enrol', get_string('enrolmentplugins'), get_string('coursehelpenrolmentplugins'), key($choices),$choices));
-        $choices = array(0 => get_string('no'), 1 => get_string('yes'), 2 => get_string('enroldate'));
-        $temp->add(new admin_setting_configselect('moodlecourse/enrollable', get_string('enrollable'), get_string('coursehelpenrollable'), 1,$choices));
-        $periodmenu=array();
-        $periodmenu[0] = get_string('unlimited');
-        for ($i=1; $i<=365; $i++) {
-            $seconds = $i * 86400;
-            $periodmenu[$seconds] = get_string('numdays', '', $i);
-        }
-        $temp->add(new admin_setting_configselect('moodlecourse/enrolperiod', get_string('enrolperiod'), '', 0,$periodmenu));
-
-        ///
-        $temp->add(new admin_setting_heading('expirynotifyhdr', get_string('expirynotify'), ''));
-        $temp->add(new admin_setting_configselect('moodlecourse/expirynotify', get_string('notify'), get_string('coursehelpnotify'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
-        $temp->add(new admin_setting_configselect('moodlecourse/notifystudents', get_string('expirynotifystudents'), get_string('coursehelpexpirynotifystudents'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
-        $thresholdmenu=array();
-        for ($i=1; $i<=30; $i++) {
-            $seconds = $i * 86400;
-            $thresholdmenu[$seconds] = get_string('numdays', '', $i);
-        }
-        $temp->add(new admin_setting_configselect('moodlecourse/expirythreshold', get_string('expirythreshold'), get_string('coursehelpexpirythreshold'), 10 * 86400,$thresholdmenu));
-
-
-        $temp->add(new admin_setting_heading('groups', get_string('groups', 'group'), ''));
-        $choices = array();
-        $choices[NOGROUPS] = get_string('groupsnone', 'group');
-        $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
-        $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
-        $temp->add(new admin_setting_configselect('moodlecourse/groupmode', get_string('groupmode'), '', key($choices),$choices));
-        $temp->add(new admin_setting_configselect('moodlecourse/groupmodeforce', get_string('force'), get_string('coursehelpforce'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
-
-
-        $temp->add(new admin_setting_heading('availability', get_string('availability'), ''));
-        $choices = array();
-        $choices['0'] = get_string('courseavailablenot');
-        $choices['1'] = get_string('courseavailable');
-        $temp->add(new admin_setting_configselect('moodlecourse/visible', get_string('visible'), '', 1,$choices));
-        $temp->add(new admin_setting_configpasswordunmask('moodlecourse/enrolpassword', get_string('enrolmentkey'), get_string('coursehelpenrolmentkey'),''));
-        $choices = array();
-        $choices['0'] = get_string('guestsno');
-        $choices['1'] = get_string('guestsyes');
-        $choices['2'] = get_string('guestskey');
-        $temp->add(new admin_setting_configselect('moodlecourse/guest', get_string('opentoguests'), '', 0,$choices));
-
-
-        $temp->add(new admin_setting_heading('language', get_string('language'), ''));
-        $languages=array();
-        $languages[''] = get_string('forceno');
-        $languages += get_list_of_languages();
-        $temp->add(new admin_setting_configselect('moodlecourse/lang', get_string('forcelanguage'), '',key($languages),$languages));
-
-        if(completion_info::is_enabled_for_site()) {
-            $temp->add(new admin_setting_heading('progress', get_string('progress','completion'), ''));
-            $temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', get_string('completion','completion'), '',
-                1,array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));
+    } else {
+        $choices = get_max_upload_sizes();
+    }
+    $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices));
+    $temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+
+    ///enrolement course settings
+    $temp->add(new admin_setting_heading('enrolhdr', get_string('enrolments'), ''));
+    require_once($CFG->dirroot.'/enrol/enrol.class.php');
+    $choices = array();
+    $modules = explode(',', $CFG->enrol_plugins_enabled);
+    foreach ($modules as $module) {
+        $name = get_string('enrolname', "enrol_$module");
+        $plugin = enrolment_factory::factory($module);
+        if (method_exists($plugin, 'print_entry')) {
+            $choices[$name] = $module;
         }
-        $ADMIN->add('courses', $temp);
     }
+    asort($choices);
+    $choices = array_flip($choices);
+    $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string('enrolname', "enrol_$CFG->enrol").')'), $choices);
+    $temp->add(new admin_setting_configselect('moodlecourse/enrol', get_string('enrolmentplugins'), get_string('coursehelpenrolmentplugins'), key($choices),$choices));
+    $choices = array(0 => get_string('no'), 1 => get_string('yes'), 2 => get_string('enroldate'));
+    $temp->add(new admin_setting_configselect('moodlecourse/enrollable', get_string('enrollable'), get_string('coursehelpenrollable'), 1,$choices));
+    $periodmenu=array();
+    $periodmenu[0] = get_string('unlimited');
+    for ($i=1; $i<=365; $i++) {
+        $seconds = $i * 86400;
+        $periodmenu[$seconds] = get_string('numdays', '', $i);
+    }
+    $temp->add(new admin_setting_configselect('moodlecourse/enrolperiod', get_string('enrolperiod'), '', 0,$periodmenu));
+
+    ///
+    $temp->add(new admin_setting_heading('expirynotifyhdr', get_string('expirynotify'), ''));
+    $temp->add(new admin_setting_configselect('moodlecourse/expirynotify', get_string('notify'), get_string('coursehelpnotify'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+    $temp->add(new admin_setting_configselect('moodlecourse/notifystudents', get_string('expirynotifystudents'), get_string('coursehelpexpirynotifystudents'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+    $thresholdmenu=array();
+    for ($i=1; $i<=30; $i++) {
+        $seconds = $i * 86400;
+        $thresholdmenu[$seconds] = get_string('numdays', '', $i);
+    }
+    $temp->add(new admin_setting_configselect('moodlecourse/expirythreshold', get_string('expirythreshold'), get_string('coursehelpexpirythreshold'), 10 * 86400,$thresholdmenu));
+
+
+    $temp->add(new admin_setting_heading('groups', get_string('groups', 'group'), ''));
+    $choices = array();
+    $choices[NOGROUPS] = get_string('groupsnone', 'group');
+    $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
+    $choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
+    $temp->add(new admin_setting_configselect('moodlecourse/groupmode', get_string('groupmode'), '', key($choices),$choices));
+    $temp->add(new admin_setting_configselect('moodlecourse/groupmodeforce', get_string('force'), get_string('coursehelpforce'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
+
+
+    $temp->add(new admin_setting_heading('availability', get_string('availability'), ''));
+    $choices = array();
+    $choices['0'] = get_string('courseavailablenot');
+    $choices['1'] = get_string('courseavailable');
+    $temp->add(new admin_setting_configselect('moodlecourse/visible', get_string('visible'), '', 1,$choices));
+    $temp->add(new admin_setting_configpasswordunmask('moodlecourse/enrolpassword', get_string('enrolmentkey'), get_string('coursehelpenrolmentkey'),''));
+    $choices = array();
+    $choices['0'] = get_string('guestsno');
+    $choices['1'] = get_string('guestsyes');
+    $choices['2'] = get_string('guestskey');
+    $temp->add(new admin_setting_configselect('moodlecourse/guest', get_string('opentoguests'), '', 0,$choices));
+
+
+    $temp->add(new admin_setting_heading('language', get_string('language'), ''));
+    $languages=array();
+    $languages[''] = get_string('forceno');
+    $languages += get_list_of_languages();
+    $temp->add(new admin_setting_configselect('moodlecourse/lang', get_string('forcelanguage'), '',key($languages),$languages));
+
+    if(completion_info::is_enabled_for_site()) {
+        $temp->add(new admin_setting_heading('progress', get_string('progress','completion'), ''));
+        $temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', get_string('completion','completion'), '',
+            1,array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));
+    }
+    $ADMIN->add('courses', $temp);
 
 /// "courserequests" settingpage
     $temp = new admin_settingpage('courserequest', get_string('courserequest'));
index c2d09f8a2d677879307184475da85d586eb0eaac..3338d768a05f480bbffbdf0c368dd028ab2666f1 100644 (file)
@@ -12,7 +12,7 @@ $temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','a
                                                                                                                                                           '2' => get_string('gd2'))));
 $temp->add(new admin_setting_configexecutable('pathtodu', get_string('pathtodu', 'admin'), get_string('configpathtodu', 'admin'), ''));
 $temp->add(new admin_setting_configexecutable('aspellpath', get_string('aspellpath', 'admin'), get_string('edhelpaspellpath'), ''));
-$ADMIN->add('server', $temp, 0);
+$ADMIN->add('server', $temp);
 
 
 
@@ -69,7 +69,7 @@ if (isloggedin()) {
 $temp->add(new admin_setting_configtext('supportname', get_string('supportname', 'admin'), get_string('configsupportname', 'admin'), $primaryadminname, PARAM_NOTAGS));
 $temp->add(new admin_setting_configtext('supportemail', get_string('supportemail', 'admin'), get_string('configsupportemail', 'admin'), $primaryadminemail, PARAM_NOTAGS));
 $temp->add(new admin_setting_configtext('supportpage', get_string('supportpage', 'admin'), get_string('configsupportpage', 'admin'), '', PARAM_URL));
-$ADMIN->add('server', $temp, 100);
+$ADMIN->add('server', $temp);
 
 
 
@@ -88,7 +88,7 @@ $temp->add(new admin_setting_configselect('sessiontimeout', get_string('sessiont
 $temp->add(new admin_setting_configtext('sessioncookie', get_string('sessioncookie', 'admin'), get_string('configsessioncookie', 'admin'), '', PARAM_ALPHANUM));
 $temp->add(new admin_setting_configtext('sessioncookiepath', get_string('sessioncookiepath', 'admin'), get_string('configsessioncookiepath', 'admin'), '/', PARAM_LOCALURL));
 $temp->add(new admin_setting_configtext('sessioncookiedomain', get_string('sessioncookiedomain', 'admin'), get_string('configsessioncookiedomain', 'admin'), '', PARAM_TEXT, 50));
-$ADMIN->add('server', $temp, 50);
+$ADMIN->add('server', $temp);
 
 
 
index b316f0bb0a3e050f05411120c6fe39716e417b4c..b44a58e2a500643b7c0c71d3df6918e62f373bda 100644 (file)
@@ -6,11 +6,11 @@
 // are added to them.
 
 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
-if (get_site()) {
-    $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
-} else {
+if (empty($CFG->rolesactive)) {
     // installation starts - no permission checks
     $hassiteconfig = true;
+} else {
+    $hassiteconfig = has_capability('moodle/site:config', $systemcontext);
 }
 
 $ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
index 84690cd1805d617158c1b0b094d7681b827b7d76..d0f00ecc1cfb4194666f85ce9a63b0664ceb1385 100644 (file)
@@ -66,7 +66,7 @@ if ($hassiteconfig
     }
 
 
-    if(empty($CFG->loginhttps)) {
+    if (empty($CFG->loginhttps)) {
         $securewwwroot = $CFG->wwwroot;
     } else {
         $securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
index 3a53534255e1d09a37ae5ee1f7b9109ee3ab6161..eced21fd2d9f7f983fd9253e41bb52031ab2a665 100644 (file)
@@ -128,6 +128,10 @@ function upgrade_db($version, $release) {
 
         $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
 
+    /// set all core default records and default settings
+        require_once("$CFG->libdir/db/install.php");
+        xmldb_main_install($version);
+
     /// Continue with the instalation
 
         // Install the roles system.
@@ -140,39 +144,13 @@ function upgrade_db($version, $release) {
         message_update_providers();
         message_update_providers('message');
 
-        /// This is used to handle any settings that must exist in $CFG but which do not exist in
-        /// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
-        apply_default_exception_settings(array('auth' => 'email',
-                                               'auth_pop3mailbox' => 'INBOX',
-                                               'enrol' => 'manual',
-                                               'enrol_plugins_enabled' => 'manual',
-                                               'style' => 'default',
-                                               'template' => 'default',
-                                               'theme' => 'standardwhite',
-                                               'filter_multilang_converted' => 1,
-                                               'backup_version' => 2008111700,
-                                               'backup_release' => '2.0 dev',
-                                               'blocks_version' => 2007081300, // might be removed soon
-                                              ));
-
-        // store main version
-        if (!set_config('version', $version)) {
-            print_error('cannotupdateversion', 'debug');
-        }
-
-
         // Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
-        // (this should only have any effect during initial install).
         admin_apply_default_settings(NULL, true);
-
         notify($strdatabasesuccess, 'notifysuccess');
 
         /// do not show certificates in log ;-)
         $DB->set_debug(false);
 
-        // hack - set up mnet
-        require_once $CFG->dirroot.'/mnet/lib.php';
-
         print_continue("index.php?continuesetuptesttables=$setuptesttables&amp;upgradetesttables=$upgradetesttables");
         print_footer('none');
 
@@ -190,7 +168,6 @@ function upgrade_db($version, $release) {
     }
 
     if ($version > $CFG->version) {  // upgrade
-
         require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
         require_once($CFG->libdir.'/db/upgradelib.php');   // Upgrade-related functions
 
@@ -297,14 +274,7 @@ function upgrade_db($version, $release) {
             print_heading($strdatabasechecking);
             $DB->set_debug(true);
         /// Launch the old main upgrade (if exists)
-            $status = true;
-            if (function_exists('main_upgrade')) {
-                $status = main_upgrade($CFG->version);
-            }
-        /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
-            if ($status && function_exists('xmldb_main_upgrade')) {
-                $status = xmldb_main_upgrade($CFG->version);
-            }
+            $status = xmldb_main_upgrade($CFG->version);
             $DB->set_debug(false);
         /// If successful, continue upgrading roles and setting everything properly
             if ($status) {
@@ -369,13 +339,15 @@ function upgrade_db($version, $release) {
 
     if ($upgradedplugins) {
         print_continue($return_url);
-        print_footer();
+        print_footer('none');
         die;
     }
 
 /// Check for changes to RPC functions
-    require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
-    upgrade_RPC_functions($return_url);  // Return here afterwards
+    if ($CFG->mnet_dispatcher_mode != 'off') {
+        require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
+        upgrade_RPC_functions($return_url);  // Return here afterwards
+    }
 
 /// Check for local database customisations
 /// first old *.php update and then the new upgrade.php script
@@ -388,103 +360,13 @@ function upgrade_db($version, $release) {
     // Turn xmlstrictheaders back on now.
     $CFG->xmlstrictheaders = $origxmlstrictheaders;
 
-    if (!$unittest) {
-    /// Set up the blank site - to be customized later at the end of install.
-        if (! $site = get_site()) {
-            build_site_course();
-            redirect("index.php?continuesetuptesttables=$continuesetuptesttables&amp;upgradetesttables=$upgradetesttables");
-        }
-
-        // initialise default blocks on admin and site page if needed
-        if (empty($CFG->adminblocks_initialised)) {
-            require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
-            require_once($CFG->libdir.'/blocklib.php');
-            page_map_class(PAGE_ADMIN, 'page_admin');
-            $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
-            blocks_repopulate_page($page);
-
-            //add admin_tree block to site if not already present
-            if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) {
-                $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
-                $pageblocks=blocks_get_by_page($page);
-                blocks_execute_action($page, $pageblocks, 'add', (int)$admintree->id, false, false);
-                if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) {
-                    $pageblocks=blocks_get_by_page($page);
-                    blocks_execute_action($page, $pageblocks, 'moveleft', $admintreeinstance, false, false);
-                }
-            }
-
-            set_config('adminblocks_initialised', 1);
-        }
-
-    /// Define the unique site ID code if it isn't already
-        if (empty($CFG->siteidentifier)) {    // Unique site identification code
-            set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
-        }
-
-    /// ugly hack - if mnet is not initialised include the mnet lib, it adds needed mnet records and configures config options
-    ///             we should not do such crazy stuff in lib functions!!!
-        if (empty($CFG->mnet_localhost_id)) {
-            require_once $CFG->dirroot.'/mnet/lib.php';
-        }
-
-    /// Check if the guest user exists.  If not, create one.
-        if (!$DB->record_exists('user', array('username'=>'guest'))) {
-            if (! $guest = create_guest_record()) {
-                notify("Could not create guest user record !!!");
-            }
-        }
-
-    /// Set up the admin user
-        if (empty($CFG->rolesactive)) {
-            build_context_path(); // just in case - should not be needed
-            create_admin_user();
-        }
-    } else {
-        build_site_course();
-        create_guest_record();
+/// make sure admin user is created - this is the last step because we need
+/// session to be working properly in order to edit admin account
+    if (empty($CFG->rolesactive)) {
         create_admin_user();
-        redirect($return_url);
     }
 }
 
-function build_site_course() {
-    global $CFG, $DB, $unittest;
-
-    $continuesetuptesttables= optional_param('continuesetuptesttables', $unittest, PARAM_BOOL);
-
-    // We are about to create the site "course"
-    require_once($CFG->libdir.'/blocklib.php');
-
-    $newsite = new object();
-    $newsite->fullname = "";
-    $newsite->shortname = "";
-    $newsite->summary = NULL;
-    $newsite->newsitems = 3;
-    $newsite->numsections = 0;
-    $newsite->category = 0;
-    $newsite->format = 'site';  // Only for this course
-    $newsite->teacher = get_string("defaultcourseteacher");
-    $newsite->teachers = get_string("defaultcourseteachers");
-    $newsite->student = get_string("defaultcoursestudent");
-    $newsite->students = get_string("defaultcoursestudents");
-    $newsite->timemodified = time();
-
-    if (!$newid = $DB->insert_record('course', $newsite)) {
-        print_error('cannotsetupsite', 'error');
-    }
-    // make sure course context exists
-    get_context_instance(CONTEXT_COURSE, $newid);
-
-    // Site created, add blocks for it
-    $page = page_create_object(PAGE_COURSE_VIEW, $newid);
-    blocks_repopulate_page($page); // Return value not checked because you can always edit later
-
-    // create default course category
-    $cat = get_course_category();
-
-}
-
 /**
  * Upgrade savepoint, marks end of each upgrade block.
  * It stores new main version, resets upgrade timeout
@@ -1329,9 +1211,9 @@ function create_admin_user($user_input=NULL) {
                 print_error('noadminrole', 'message');
             }
 
-            $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+            $systemcontext = get_context_instance(CONTEXT_SYSTEM);
             foreach ($adminroles as $adminrole) {
-                role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
+                role_assign($adminrole->id, $user->id, 0, $systemcontext->id);
             }
 
             //set default message preferences
@@ -2120,7 +2002,8 @@ class admin_externalpage extends part_of_admin_tree {
      * @return bool True if user has access, false otherwise.
      */
     function check_access() {
-        if (!get_site()) {
+        global $CFG;
+        if (empty($CFG->rolesactive)) {
             return true; // no access check before site is fully set up
         }
         $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
@@ -2270,7 +2153,8 @@ class admin_settingpage extends part_of_admin_tree {
 
     // see admin_externalpage
     function check_access() {
-        if (!get_site()) {
+        global $CFG;
+        if (empty($CFG->rolesactive)) {
             return true; // no access check before site is fully set up
         }
         $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
@@ -5347,7 +5231,7 @@ function admin_externalpage_print_footer() {
  * Returns the reference to admin tree root
  * @return reference
  */
-function &admin_get_root($reload=false, $requirefulltree=true) {
+function admin_get_root($reload=false, $requirefulltree=true) {
     global $CFG, $DB;
 
     static $ADMIN = NULL;
@@ -5390,12 +5274,12 @@ function &admin_get_root($reload=false, $requirefulltree=true) {
                 // plugins are loaded last - they may insert pages anywhere
                 continue;
             }
-            include($file);
+            require($file);
         }
-        include($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
+        require($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
 
         if (file_exists($CFG->dirroot.'/local/settings.php')) {
-            include_once($CFG->dirroot.'/local/settings.php');
+            require($CFG->dirroot.'/local/settings.php');
         }
     }
 
@@ -5414,7 +5298,7 @@ function admin_apply_default_settings($node=NULL, $unconditional=true) {
     global $CFG;
 
     if (is_null($node)) {
-        $node =& admin_get_root(true, true);
+        $node = admin_get_root(true, true);
     }
 
     if (is_a($node, 'admin_category')) {
@@ -5622,16 +5506,6 @@ function admin_output_new_settings_by_page($node) {
     return $return;
 }
 
-/**
- * Unconditionally applies default admin settings in main config table
- * @param array $defaults array of string values
- */
-function apply_default_exception_settings($defaults) {
-    foreach($defaults as $key => $value) {
-        set_config($key, $value, NULL);
-    }
-}
-
 /**
  * Format admin settings
  * @param string $object setting
index c497309c7792af9ff49a50f839aebdae219e8e86..d7efa6263e17d99a22fc5de78aeeb4d2c60b9235 100644 (file)
@@ -1072,32 +1072,27 @@ function blocks_repopulate_page($page) {
 //This function finds all available blocks and install them
 //into blocks table or do all the upgrade process if newer
 function upgrade_blocks_plugins() {
-    global $CFG, $interactive, $DB;
+    global $CFG, $interactive, $DB, $SITE;
+
+    require_once($CFG->dirroot .'/blocks/moodleblock.class.php');
 
     $updated_blocks = false;
 
-    $blocktitles = array();
+    $blocktitles   = array();
     $invalidblocks = array();
-    $validblocks = array();
-    $notices = array();
+    $validblocks   = array();
+    $notices       = array();
 
     //Count the number of blocks in db
     $blockcount = $DB->count_records('block');
     //If there isn't records. This is the first install, so I remember it
-    if ($blockcount == 0) {
-        $first_install = true;
-    } else {
-        $first_install = false;
-    }
-
-    $site = get_site();
+    $first_install = ($blockcount == 0);
 
     if (!$blocks = get_list_of_plugins('blocks') ) {
         print_error('noblocks', 'debug');
     }
 
-    include_once($CFG->dirroot .'/blocks/moodleblock.class.php');
-    if(!class_exists('block_base')) {
+    if (!class_exists('block_base')) {
         print_error('noblockbase');
     }
 
@@ -1308,24 +1303,22 @@ function upgrade_blocks_plugins() {
         }
     }
 
-    // Finally, if we are in the first_install of BLOCKS (this means that we are
-    // upgrading from Moodle < 1.3), put blocks in all existing courses.
+    // Finally, if we are in the first_install of BLOCKS setup frontpage and admin page blocks
     if ($first_install) {
+        require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');
+
         upgrade_log_start();
-        //Iterate over each course
+        //Iterate over each course - there should be only site course here now
         if ($courses = $DB->get_records('course')) {
             foreach ($courses as $course) {
                 $page = page_create_object(PAGE_COURSE_VIEW, $course->id);
                 blocks_repopulate_page($page);
             }
         }
-    }
 
-    if (!empty($CFG->siteblocksadded)) {     /// This is a once-off hack to make a proper upgrade
-        upgrade_log_start();
-        $page = page_create_object(PAGE_COURSE_VIEW, SITEID);
+        page_map_class(PAGE_ADMIN, 'page_admin');
+        $page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
         blocks_repopulate_page($page);
-        $DB->delete_records('config', array('name'=>'siteblocksadded'));
     }
 
     upgrade_log_finish();
index 110b72eb0dc29500cb1abffc6dbbed2ba380d3c8..4f15b4e83c7f64087677ea5794f53e078b4ae14b 100644 (file)
@@ -94,7 +94,7 @@ class completion_info {
      */
     public static function is_enabled_for_site() {
         global $CFG;
-        return $CFG->enablecompletion;
+        return !empty($CFG->enablecompletion);
     }
 
     /**
diff --git a/lib/db/install.php b/lib/db/install.php
new file mode 100644 (file)
index 0000000..f752059
--- /dev/null
@@ -0,0 +1,101 @@
+<?php  //$Id$
+
+// This file is executed right after the install.xml
+//
+
+function xmldb_main_install($version) {
+    global $CFG, $DB, $SITE;
+
+/// TODO: move all statements from install.xml here
+
+
+/// make sure system context exists
+    $syscontext = get_context_instance(CONTEXT_SYSTEM);
+    if ($syscontext->id != 1) {
+        throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected system context id created!');
+    }
+
+
+// create site course
+    $newsite = new object();
+    $newsite->fullname = "";
+    $newsite->shortname = "";
+    $newsite->summary = NULL;
+    $newsite->newsitems = 3;
+    $newsite->numsections = 0;
+    $newsite->category = 0;
+    $newsite->format = 'site';  // Only for this course
+    $newsite->teacher = get_string("defaultcourseteacher");
+    $newsite->teachers = get_string("defaultcourseteachers");
+    $newsite->student = get_string("defaultcoursestudent");
+    $newsite->students = get_string("defaultcoursestudents");
+    $newsite->timemodified = time();
+
+    $DB->insert_record('course', $newsite);
+    $SITE = get_site();
+    if ($SITE->id != 1) {
+        throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected site course id created!');
+    }
+
+
+/// make sure site course context exists
+    get_context_instance(CONTEXT_COURSE, $SITE->id);
+
+/// create default course category
+    $cat = get_course_category();
+
+
+    $defaults = array('auth'                  => 'email',
+                      'auth_pop3mailbox'      => 'INBOX',
+                      'enrol'                 => 'manual',
+                      'enrol_plugins_enabled' => 'manual',
+                      'style'                 => 'default',
+                      'template'              => 'default',
+                      'theme'                 => 'standardwhite',
+                      'filter_multilang_converted' => 1,
+                      'siteidentifier'        => random_string(32).$_SERVER['HTTP_HOST'],
+                      'backup_version'        => 2008111700,
+                      'backup_release'        => '2.0 dev',
+                      'blocks_version'        => 2007081300, // might be removed soon
+                      'mnet_dispatcher_mode'  => 'off',
+                      'sessiontimeout'        => 7200,       // must be present during roles installation
+
+                     );
+    foreach($defaults as $key => $value) {
+        set_config($key, $value);
+    }
+
+
+/// bootstrap mnet
+    $mnethost = new object();
+    $mnethost->wwwroot    = $CFG->wwwroot;
+    $mnethost->name       = '';
+    $mnethost->name       = '';
+    $mnethost->public_key = '';
+
+    if (empty($_SERVER['SERVER_ADDR'])) {
+        // SERVER_ADDR is only returned by Apache-like webservers
+        preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
+        $my_hostname = $matches[1];
+        $my_ip       = gethostbyname($my_hostname);  // Returns unmodified hostname on failure. DOH!
+        if ($my_ip == $my_hostname) {
+            $mnethost->ip_address = 'UNKNOWN';
+        } else {
+            $mnethost->ip_address = $my_ip;
+        }
+    } else {
+        $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
+    }
+
+    $mnetid = $DB->insert_record('mnet_host', $mnethost);
+    set_config('mnet_localhost_id', $mnetid);
+
+
+/// Create guest record
+    create_guest_record();
+
+
+/// everything ready - store main version :-D
+    set_config('version', $version);
+
+}
\ No newline at end of file
index e30cb8b6a9cfae9bddc93c4ba1696e001524ff25..cf47f0efe6b34c6c9535b9237e68870cb88def6c 100644 (file)
@@ -1309,15 +1309,6 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2009010800);
     }
 
-    if ($result && $oldversion < 2009010801) {
-    /// Remove unused settings
-        unset_config('zip');
-        unset_config('unzip');
-
-    /// Main savepoint reached
-        upgrade_main_savepoint($result, 2009010801);
-    }
-
     if ($result && $oldversion < 2009011000) {
 
     /// Changing nullability of field configdata on table block_instance to null
@@ -1332,6 +1323,17 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2009011000);
     }
 
+    if ($result && $oldversion < 2009011100) {
+    /// Remove unused settings
+        unset_config('zip');
+        unset_config('unzip');
+        unset_config('adminblocks_initialised');
+
+    /// Main savepoint reached
+        upgrade_main_savepoint($result, 2009011100);
+    }
+
+
     return $result;
 }
 
index fd29779d03fade165546fa0e8da5de874b0be49e..93417191d27abb8cb1824c21eef0dfdfe7ac61a2 100644 (file)
@@ -2834,9 +2834,8 @@ function create_guest_record() {
     $guest->lang        = $CFG->lang;
     $guest->timemodified= time();
 
-    if (! $guest->id = $DB->insert_record('user', $guest)) {
-        return false;
-    }
+    $id = $DB->insert_record('user', $guest);
+    $guest = $DB->get_record('user', array('id'=>$id));
 
     return $guest;
 }
index fd9c138376bd57255fe679d5d34356dbbdad358e..2ddacda86f57484b80a28f4f623583c0c8b4394f 100644 (file)
         $session_has_timed_out = false;
     }
 
-/// Check if the guest user exists.  If not, create one.
-    if (!$DB->record_exists('user', array('username'=>'guest', 'mnethostid'=>$CFG->mnet_localhost_id))) {
-        if (! $guest = create_guest_record()) {
-            notify('Could not create guest user record !!!');
-        }
-    }
-
 // setup and verify auth settings
 
 if (!isset($CFG->registerauth)) {
index 8fc7ad47c68b1535055e4855312f2ba154f42905..a4792717aed0d1321f4aad2a0717ea5170d898ea 100644 (file)
@@ -24,52 +24,19 @@ class mnet_environment {
     function init() {
         global $CFG, $DB;
 
-        if (empty($CFG->mnet_dispatcher_mode)) {
-            set_config('mnet_dispatcher_mode', 'off');
-        }
-
         // Bootstrap the object data on first load.
-        if (empty($CFG->mnet_localhost_id) ) {
-            if (!$CFG->mnet_localhost_id = get_config(NULL, 'mnet_localhost_id')) {  // Double-check db
-                $this->wwwroot    = $CFG->wwwroot;
-                if (empty($_SERVER['SERVER_ADDR'])) {
-                    // SERVER_ADDR is only returned by Apache-like webservers
-                    $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot);
-                    $my_ip       = gethostbyname($my_hostname);  // Returns unmodified hostname on failure. DOH!
-                    if ($my_ip == $my_hostname) {
-                        $this->ip_address = 'UNKNOWN';
-                    } else {
-                        $this->ip_address = $my_ip;
-                    }
-                } else {
-                    $this->ip_address = $_SERVER['SERVER_ADDR'];
-                }
-
-                if ($existingrecord = $DB->get_record('mnet_host', array('ip_address'=>$this->ip_address))) {
-                    $this->id = $existingrecord->id;
-                } else {  // make a new one
-                    $this->id       = $DB->insert_record('mnet_host', $this);
-                }
-    
-                set_config('mnet_localhost_id', $this->id);
-                $this->get_keypair();
-            }
-        } else {
-            $hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id));
-            if(is_object($hostobject)) {
-                $temparr = get_object_vars($hostobject);
-                foreach($temparr as $key => $value) {
-                    $this->$key = $value;
-                }
-                unset($hostobject, $temparr);
-            } else {
-                return false;
-            }
+        if (!$hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id))) {
+            return false;
+        }
+        $temparr = get_object_vars($hostobject);
+        foreach($temparr as $key => $value) {
+            $this->$key = $value;
+        }
+        unset($hostobject, $temparr);
 
-            // Unless this is an install/upgrade, generate the SSL keys.
-            if(empty($this->public_key)) {
-                $this->get_keypair();
-            }
+        // Unless this is an install/upgrade, generate the SSL keys.
+        if (empty($this->public_key)) {
+            $this->get_keypair();
         }
 
         // We need to set up a record that represents 'all hosts'. Any rights
@@ -93,11 +60,12 @@ class mnet_environment {
     }
 
     function get_keypair() {
-        global $DB, $SESSION;
+        global $DB, $CFG;
 
         // We don't generate keys on install/upgrade because we want the USER
         // record to have an email address, city and country already.
-        if (!empty($SESSION->upgraderunning)) return true;
+        if (empty($CFG->rolesactive)) return true;
+        if ($CFG->mnet_dispatcher_mode == 'off') return true;
         if (!extension_loaded("openssl")) return true;
         if (!empty($this->keypair)) return true;
 
index 8008e15f64bf65e38521cf806f358133a079158b..59050ee6dccad0c76abb90e9022f1f0cc6daf9a9 100644 (file)
@@ -350,18 +350,15 @@ function mnet_generate_keypair($dn = null, $days=28) {
     $break = strpos($host.'/' , '/');
     $host   = substr($host, 0, $break);
 
-    if ($result = $DB->get_record('course', array("id"=>SITEID))) {
-        $organization = $result->fullname;
-    } else {
-        $organization = 'None';
-    }
+    $site = get_site();
+    $organization = $site->fullname;
 
     $keypair = array();
 
     $country  = 'NZ';
     $province = 'Wellington';
     $locality = 'Wellington';
-    $email    = $CFG->noreplyaddress;
+    $email    = !empty($CFG->noreplyaddress) ? $CFG->noreplyaddress : 'noreply@'.$_SERVER['HTTP_HOST'];
 
     if(!empty($USER->country)) {
         $country  = $USER->country;
index cdf18f2f600eb1963f25a7cc365e168e2eb09f2a..89d95702feae894dbb83f60fbe83f0e56c1bcc9e 100644 (file)
@@ -1,15 +1,5 @@
 <?PHP  // $Id$
 
-//////////////////////////////////
-/// CONFIGURATION settings
-
-if (!isset($CFG->hotpot_showtimes)) {
-    set_config("hotpot_showtimes", 0);
-}
-if (!isset($CFG->hotpot_excelencodings)) {
-    set_config("hotpot_excelencodings", "");
-}
-
 //////////////////////////////////
 /// CONSTANTS and GLOBAL VARIABLES
 
index e5db807043bffda796175fbee7c1408d358647ba..70c097648e029357cef2a4918316e30eee0e25cf 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009011000;  // YYYYMMDD   = date of the last version bump
+    $version = 2009011100;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090111)';  // Human-friendly version name