Skip to content
Snippets Groups Projects
Commit a1d9951c authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'dev#141983_prendre_en_charge_les_zend_session_start' into 'hotline'

dev #141983 on Zend_Session start error, automatically reload the page

See merge request !4222
parents 3bc0bf85 da45c2f2
3 merge requests!4234Master,!4232Hotline,!4222dev #141983 on Zend_Session start error, automatically reload the page
Pipeline #14892 canceled with stage
in 1 minute and 30 seconds
- ticket #141983 : Hébergement : Rechargement automatique de la page lorsque la session n'a pas pu être ouverte
\ No newline at end of file
......@@ -31,10 +31,17 @@ function defineConstant($name, $value) {
class Bokeh_Engine {
protected static
$_zend_session_namespace,
$_php_command;
protected
$_config,
$_front_controller;
public function powerOn() {
return
$this
......@@ -202,19 +209,72 @@ class Bokeh_Engine {
function setupSession() {
// Start Session
$session = new Zend_Session_Namespace(md5(BASE_URL));
if (!isset($session->initialized))
{
Zend_Session::regenerateId();
$session->initialized = true;
}
if (!isset($session->baseUrl)) $session->baseUrl = BASE_URL;
try {
$session = $this->_getZendSessionNamespace()->get(md5(BASE_URL));
} catch (Zend_Session_Exception $e) {
return $this->_timeoutReload();
}
if (!isset($session->initialized)) {
Zend_Session::regenerateId();
$session->initialized = true;
}
if (!isset($session->baseUrl))
$session->baseUrl = BASE_URL;
Zend_Registry::set('session', $session);
return $this;
}
protected function _timeoutReload() {
$this->_getPhpCommand()->header('HTTP/1.1 503 Service Unavailable');
$this->_getPhpCommand()->echoHtml('<html>'
. '<body style="text-align:center">'
. '<img src="' . URL_SHARED_IMG . 'patience.gif' . '" />'
. 'Attente de connexion...'
. '<script>'
. 'setTimeout(() => window.location.reload(),5000);'
. '</script>'
. '</body>'
.'</html>');
$this->_getPhpCommand()->exitDispatch();
}
protected function _getPhpCommand() {
if ( static::$_php_command)
return static::$_php_command;
return new Bokeh_PhpCommand;
}
public static function setPhpCommand($instance) {
static::$_php_command = $instance;
}
protected function _getZendSessionNamespace() {
if ( static::$_zend_session_namespace )
return static::$_zend_session_namespace;
return new Bokeh_Session;
}
public function setZendSessionNamespace($instance) {
return static::$_zend_session_namespace = $instance;
}
public static function reset() {
static::$_zend_session_namespace = null;
static::$_php_command = null;
}
function setupLanguage() {
$default = Class_AdminVar::getDefaultLanguage();
ZendAfi_Locale::setDefault($default);
......@@ -426,6 +486,32 @@ class Bokeh_Engine {
}
class Bokeh_PhpCommand {
public function header($text) {
header($text);
}
public function echoHtml($html) {
echo $html;
}
public function exitDispatch() {
exit;
}
}
class Bokeh_Session {
public function get($session_id) {
return new Zend_Session_Namespace($session_id);
}
}
function setupOpac() {
return (new Bokeh_Engine())
->powerOn()
......
......@@ -28,4 +28,36 @@ class BokehEngineLanguageTest extends ModelTestCase {
$engine = (new Bokeh_Engine)->setupLanguage();
$this->assertEquals('fr', Zend_Registry::get('translate')->getLocale());
}
/** @test */
public function withZendSessionExceptionShouldReturnHtmlWithScript() {
$html = '<html><body style="text-align:center"><img src="' . BASE_URL . '/public/opac/images/patience.gif" />Attente de connexion...<script>setTimeout(() => window.location.reload(),5000);</script></body></html>';
$zend_session = $this
->mock()->beStrict()
->whenCalled('get')->with(md5(BASE_URL))
->willDo(function() {throw new Zend_Session_Exception;});
$php_command = $this
->mock()->beStrict()
->whenCalled('header')->with('HTTP/1.1 503 Service Unavailable')
->answers('503')
->whenCalled('echoHtml')->with($html)
->answers('')
->whenCalled('exitDispatch')
->answers('')
;
Bokeh_Engine::setZendSessionNameSpace($zend_session);
Bokeh_Engine::setPhpCommand($php_command);
$engine = (new Bokeh_Engine)->setupSession();
$this->assertNotNull(Zend_Registry::get('session'));
}
}
......@@ -98,6 +98,7 @@ abstract class ModelTestCase extends Storm_Test_ModelTestCase {
protected function tearDown() {
Bokeh_Engine::reset();
Class_Url::setPhpMode(null);
Class_Notice_Thumbnail_ResizeImage::reset();
Class_Album::setFileSystem(null);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment