]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14992 refactored use of session_write_close()
authorskodak <skodak>
Sat, 17 Jan 2009 15:25:08 +0000 (15:25 +0000)
committerskodak <skodak>
Sat, 17 Jan 2009 15:25:08 +0000 (15:25 +0000)
15 files changed:
admin/cron.php
admin/dbtransfer/lib.php
course/report/log/index.php
course/report/log/live.php
draftfile.php
file.php
lib/dml/moodle_database.php
lib/filelib.php
lib/moodlelib.php
lib/sessionlib.php
mod/chat/gui_ajax/post.php
mod/chat/gui_header_js/insert.php
pluginfile.php
question/file.php
userfile.php

index f3e98bfd3d37a4c993b0581bf5561698d63e4db6..49d92a6e1e5b03a3f2e334cbef9d4e8d661b6421 100644 (file)
@@ -37,7 +37,7 @@
     }
 
 /// extra safety
-    @session_write_close();
+    @session_get_instance()->write_close();
 
 /// check if execution allowed
     if (isset($_SERVER['REMOTE_ADDR'])) { // if the script is accessed via the web.
index 4241c3039507a768e65cd016af036456a16bd44c..c1d7858a8672f49ac95bf4e5144969d07cf661f5 100644 (file)
@@ -24,7 +24,7 @@ require_once($CFG->libdir.'/dtllib.php');
 function dbtransfer_export_xml_database($description, $mdb) {
     @set_time_limit(0);
 
-    session_write_close(); // release session
+    session_get_instance()->write_close(); // release session
 
     header('Content-Type: application/xhtml+xml');
     header('Content-Disposition: attachment; filename=database.xml');
@@ -45,7 +45,7 @@ function dbtransfer_export_xml_database($description, $mdb) {
 function dbtransfer_transfer_database($sourcedb, $targetdb) {
     @set_time_limit(0);
 
-    session_write_close(); // release session
+    session_get_instance()->write_close(); // release session
 
     $var = new database_mover($sourcedb, $targetdb);
     $var->export_database(null);
index 76186f1d8f1155b86d0d3962df1393a6849ff0e6..052a5716af4a9a0bc707288223925793d9f1189e 100644 (file)
@@ -56,7 +56,7 @@
     $stradministration = get_string('administration');
     $strreports = get_string('reports');
 
-    session_write_close();
+    session_get_instance()->write_close();
 
     $navlinks = array();
 
index 8dce7e52192b3418b15173f40c57de7b012bcabb..ebf4ad189bd5c814ffa1616227eb0fa20aa1fe56 100644 (file)
@@ -18,7 +18,7 @@
 
     add_to_log($course->id, "course", "report live", "report/log/live.php?id=$course->id", $course->id); 
 
-    session_write_close();
+    session_get_instance()->write_close();
 
     // we override the default framename so header/footer
     // links open in a new window 
index 3908a7d037bd3f682cd51387476c1ed2cf7e9efe..91b5f5ec604cfe6465a9aaf79547740992337ba2 100644 (file)
@@ -62,5 +62,5 @@
     // ========================================
     // finally send the file
     // ========================================
-    session_write_close(); // unlock session during fileserving
+    session_get_instance()->write_close(); // unlock session during fileserving
     send_stored_file($file, 0, false, true); // force download - security first!
index 00227f781e9f908f897b6c18829a577608f09a51..de2968c1c38e52c445ea16682c7e151e0b5c2a8e 100644 (file)
--- a/file.php
+++ b/file.php
@@ -93,7 +93,7 @@
     // ========================================
     // finally send the file
     // ========================================
-    session_write_close(); // unlock session during fileserving
+    session_get_instance()->write_close(); // unlock session during fileserving
     send_stored_file($file, $lifetime, $CFG->filteruploadedfiles, $forcedownload);
 
 
index 31c1fc0f2a0145391165d20a5801b1e7a8666890..08baff21c0417a592565e26bfb373df54904bc94 100644 (file)
@@ -246,7 +246,7 @@ abstract class moodle_database {
     public function dispose() {
         if ($this->used_for_db_sessions) {
             // this is needed because we need to save session to db before closing it
-            session_write_close();
+            session_get_instance()->write_close();
             $this->used_for_db_sessions = false;
         }
         if ($this->database_manager) {
index 6b2d2210ecabab7f0e1b7231eff649fe4c487857..14072b5d3e4ea18fb1953a8307eb9b717a6ee232 100644 (file)
@@ -787,7 +787,7 @@ function send_temp_file($path, $filename, $pathisstring=false) {
     global $CFG;
 
     // close session - not needed anymore
-    @session_write_close();
+    @session_get_instance()->write_close();
 
     if (!$pathisstring) {
         if (!file_exists($path)) {
@@ -874,7 +874,7 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
         }
     }
 
-    session_write_close(); // unlock session during fileserving
+    session_get_instance()->write_close(); // unlock session during fileserving
 
     // Use given MIME type if specified, otherwise guess it using mimeinfo.
     // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O
@@ -1078,7 +1078,7 @@ function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownl
         ignore_user_abort(true);
     }
 
-    session_write_close(); // unlock session during fileserving
+    session_get_instance()->write_close(); // unlock session during fileserving
 
     // Use given MIME type if specified, otherwise guess it using mimeinfo.
     // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O
index 35b071e06cf2e3733eb27d6a0e850dfdb7af27d4..50c7ee71ee51b7b8280ef8cb2432d821cb61c330 100644 (file)
@@ -2182,7 +2182,7 @@ function require_logout() {
         }
     }
 
-    session_get_instance()->terminate();
+    session_get_instance()->terminate_current();
 }
 
 /**
index 8c3db52fe3d4f56897cc5fb94b1c36461e4a893e..e5603de6494286e3eaf7497d521c85ff288d50c0 100644 (file)
@@ -33,7 +33,19 @@ function session_get_instance() {
 }
 
 interface moodle_session {
-    public function terminate();
+    /**
+     * Terminate current session
+     * @return void
+     */
+    public function terminate_current();
+
+    /**
+     * No more changes in session expected.
+     * Unblocks the sesions, other scripts may start executing in parallel.
+     * @return void
+     */
+    public function write_close();
+
 }
 
 /**
@@ -87,6 +99,52 @@ abstract class session_stub implements moodle_session {
         $this->check_security();
     }
 
+    /**
+     * Terminates active moodle session
+     */
+    public function terminate_current() {
+        global $CFG, $SESSION, $USER;
+
+        if (NO_MOODLE_COOKIES) {
+            return;
+        }
+
+        $_SESSION = array();
+
+        $SESSION  = new object();
+        $USER     = new object();
+        $USER->id = 0;
+        if (isset($CFG->mnet_localhost_id)) {
+            $USER->mnethostid = $CFG->mnet_localhost_id;
+        }
+
+        // Initialize variable to pass-by-reference to headers_sent(&$file, &$line)
+        $file = null;
+        $line = null;
+        if (headers_sent($file, $line)) {
+            error_log('Can not terminate session properly - headers were already sent in file: '.$file.' on line '.$line);
+        }
+
+        // now let's try to get a new session id and destroy the old one
+        @session_regenerate_id(true);
+
+        // close the session
+        @session_write_close();
+    }
+
+    /**
+     * No more changes in session expected.
+     * Unblocks the sesions, other scripts may start executing in parallel.
+     * @return void
+     */
+    public function write_close() {
+        if (NO_MOODLE_COOKIES) {
+            return;
+        }
+
+        session_write_close();
+    }
+
     /**
      * Initialise $USER object, handles google access.
      *
@@ -158,41 +216,12 @@ abstract class session_stub implements moodle_session {
 
             if ($_SESSION['USER']->sessionip != $remoteaddr) {
                 // this is a security feature - terminate the session in case of any doubt
-                $this->terminate();
+                $this->terminate_current();
                 print_error('sessionipnomatch2', 'error');
             }
         }
     }
 
-    /**
-     * Terminates active moodle session
-     */
-    public function terminate() {
-        global $CFG, $SESSION, $USER;
-
-        $_SESSION = array();
-
-        $SESSION  = new object();
-        $USER     = new object();
-        $USER->id = 0;
-        if (isset($CFG->mnet_localhost_id)) {
-            $USER->mnethostid = $CFG->mnet_localhost_id;
-        }
-
-        // Initialize variable to pass-by-reference to headers_sent(&$file, &$line)
-        $file = null;
-        $line = null;
-        if (headers_sent($file, $line)) {
-            error_log('Can not terminate session properly - headers were already sent in file: '.$file.' on line '.$line);
-        }
-
-        // now let's try to get a new session id and destroy the old one
-        @session_regenerate_id(true);
-
-        // close the session
-        @session_write_close();
-    }
-
     /**
      * Prepare cookies and varions system settings
      */
@@ -268,6 +297,7 @@ class legacy_file_session extends session_stub {
         }
         ini_set('session.save_path', $CFG->dataroot .'/sessions');
     }
+
 }
 
 /**
index 7c3302b4349e9e7e99eff559089eb610d30c52d4..198978317998a852237f96d0752a7df302297718 100755 (executable)
@@ -29,7 +29,7 @@ if (!$cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
 if (isguest()) {
     chat_print_error('ERROR', get_string('notlogged','chat'));
 }
-session_write_close();
+session_get_instance()->write_close();
 chat_delete_old_users();
 $chat_message = clean_text($chat_message, FORMAT_MOODLE);
 
index 797feb10193f05f9b6afe31338516549bda1968c..269ad81cd62a50f7e9790ddca86d3dd694d8fcdb 100644 (file)
@@ -28,7 +28,7 @@
         print_error('noguests');
     }
 
-    session_write_close();
+    session_get_instance()->write_close();
 
 /// Delete old users now
 
index c47c863f10cdfaddd51f8ebb30540d6a08bfa511..7e95039629051c1d792eccdf7fbb69a506b1b086 100644 (file)
             send_file_not_found();
         }
 
-        session_write_close(); // unlock session during fileserving
+        session_get_instance()->write_close(); // unlock session during fileserving
         send_stored_file($file, 60*60, 0, $forcedownload);
 
 
                 send_file_not_found();
             }
 
-            session_write_close(); // unlock session during fileserving
+            session_get_instance()->write_close(); // unlock session during fileserving
             send_stored_file($file, 0, 0, true);
 
         } else if ($filearea === 'course_intro') {
                 send_file_not_found();
             }
 
-            session_write_close(); // unlock session during fileserving
+            session_get_instance()->write_close(); // unlock session during fileserving
             send_stored_file($file, 60*60, 0, false); // TODO: change timeout?
 
         } else if ($filearea === 'user_profile') {
                 send_file_not_found();
             }
 
-            session_write_close(); // unlock session during fileserving
+            session_get_instance()->write_close(); // unlock session during fileserving
             send_stored_file($file, 0, 0, true); // must force download - security!
 
         } else {
index e0ab078f14fdd03502bd80ecad1e66072313864b..80e9615551e93664753c91b487c461fdc0d7bfe3 100644 (file)
@@ -71,7 +71,7 @@
         }
 
         // send the file
-        session_write_close(); // unlock session during fileserving
+        session_get_instance()->write_close(); // unlock session during fileserving
         $filename = $args[count($args)-1];
         send_file($pathname, $filename, $lifetime, $CFG->filteruploadedfiles, false, $forcedownload);
     } else {
index ae5a49dec850d71b3d94e70ca6cfbd2cf4627045..c7096cf1a8830c9df1819692a425097b79dbb848 100644 (file)
@@ -83,5 +83,5 @@
     // ========================================
     // finally send the file
     // ========================================
-    session_write_close(); // unlock session during fileserving
+    session_get_instance()->write_close(); // unlock session during fileserving
     send_stored_file($file, 0, false, $forcedownload);