Skip to content

Commit

Permalink
Remove restoreLTISession()
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Jun 10, 2024
1 parent eb0f398 commit a227d15
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 78 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"react/dns" : ">=1.12.0",
"react/socket" : ">=1.15.0",

"tsugi/lib": "dev-master#a2dc13192f9462bc4a05f336d9384ba1eb7c6b0b",
"tsugi/lib": "dev-master#8b5148497114bd3c5f174dc54eece0a383c47ff0",
"koseu/lib": "dev-master#b9a31b7875108196dbdf284e685b813d424f2def"
},
"config": {
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7708,12 +7708,12 @@
"source": {
"type": "git",
"url": "https://github.com/tsugiproject/tsugi-php.git",
"reference": "a2dc13192f9462bc4a05f336d9384ba1eb7c6b0b"
"reference": "8b5148497114bd3c5f174dc54eece0a383c47ff0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tsugiproject/tsugi-php/zipball/a2dc13192f9462bc4a05f336d9384ba1eb7c6b0b",
"reference": "a2dc13192f9462bc4a05f336d9384ba1eb7c6b0b",
"url": "https://api.github.com/repos/tsugiproject/tsugi-php/zipball/8b5148497114bd3c5f174dc54eece0a383c47ff0",
"reference": "8b5148497114bd3c5f174dc54eece0a383c47ff0",
"shasum": ""
},
"require": {
Expand All @@ -7727,7 +7727,7 @@
"phpunit/php-timer": "v5.0.3",
"phpunit/phpunit": "9.*"
},
"time": "2024-06-10T13:06:33+00:00",
"time": "2024-06-10T13:47:13+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",
Expand Down
6 changes: 3 additions & 3 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'ed495c6c11c20d61809d922d40eb17b37ff7a732',
'reference' => 'eb0f398d07b416d3f5581bf65d2e6c6e2df822a1',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'ed495c6c11c20d61809d922d40eb17b37ff7a732',
'reference' => 'eb0f398d07b416d3f5581bf65d2e6c6e2df822a1',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -1078,7 +1078,7 @@
'tsugi/lib' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'a2dc13192f9462bc4a05f336d9384ba1eb7c6b0b',
'reference' => '8b5148497114bd3c5f174dc54eece0a383c47ff0',
'type' => 'library',
'install_path' => __DIR__ . '/../tsugi/lib',
'aliases' => array(
Expand Down
69 changes: 4 additions & 65 deletions vendor/tsugi/lib/src/Core/LTIX.php
Original file line number Diff line number Diff line change
Expand Up @@ -1977,70 +1977,6 @@ public static function requireDataOverride($needed,
$pdox, $session_object, $current_url, $request_data);
}

/**
* Restore an LTI session and check if it worked
*
* If we are using memcached with php_serialize serialization,
* we take a wild guess that we might be having a race condition
* with memcache. So we wait a tic, and re-try the read.
*/
public static function restoreLTISession($session_id) {
global $CFG;

// You would think that this would just work :)
if ( session_id() == "" ) {
session_id($session_id);
session_start();
}

if ( U::get($_SESSION, 'lti') && U::get($_SESSION, 'lti_post') ) return;

// https://stackoverflow.com/questions/35728486/read-php-session-without-actually-starting-it
$serializer = ini_get('session.serialize_handler');
if ( ! isset($CFG->memcached) || U::isEmpty($CFG->memcached) || $serializer != 'php_serialize') return;

sleep(1);
try {
$servers = explode(',', $CFG->memcached);
$c = count($servers);
for ($i = 0; $i < $c; ++$i) {
$servers[$i] = explode(':', $servers[$i]);
}

$memcached = new \Memcached();
$memcached->addServers($servers);
$sessionPrefix = ini_get('memcached.sess_prefix');

$rawData = $memcached->get($sessionPrefix.$session_id);
if ( ! $rawData ) {
error_log("restoreLTISession - nothing to retrieve from memcached ".$session_id);
return;
}

// Keep unserialize() from issuing a notice
$data = $rawData ? @unserialize($rawData) : false;
if ( ! is_array($data) ) {
error_log("restoreLTISession - could not unserialize () ".$session_id);
return;
}

if ( count($data) < 1 ) {
error_log("restoreLTISession - empty memcached data ".$session_id);
return;
}

// Copy into session
$fields = "";
foreach($data as $k => $v) {
$_SESSION[$k] = $data[$k];
if ( strlen($fields) < 50 && is_string($data[$k]) ) $fields .= ' '.$k.'='.$data[$k];
}
error_log("restoreLTISession copied ".count($data)." ".$session_id.$fields);
} catch(\Exception $e) {
error_log("restoreLTISession exception ".$e->getMessage());
}
}

/**
* Internal method to handle the data setup
*/
Expand Down Expand Up @@ -2102,7 +2038,10 @@ public static function requireDataPrivate($needed=self::ALL,
if ( $newlaunch || isset($_POST[$sess]) || isset($_GET[$sess]) ) {
$session_id = $_POST[$sess] ?? $_GET[$sess] ?? null;
// Do our best to restore a session
if ( $session_id ) self::restoreLTISession($session_id);
if ( $session_id && session_id() == "" ) {
session_id($session_id);
session_start();
}
} else {
self::wrapped_session_flush($session_object);
self::send403();
Expand Down

0 comments on commit a227d15

Please sign in to comment.