Skip to content
Snippets Groups Projects

[RTKO] default volatile on setupOpac

Merged Sebastien ANDRE requested to merge fix_default_volatile_on_setup into master
Compare and
8 files
+ 367
173
Preferences
Compare changes
Files
8
+ 139
93
@@ -21,45 +21,48 @@
require_once "Polyfill80.php";
if (!function_exists('xdebug_break'))
if ( ! function_exists('xdebug_break'))
{
function xdebug_break(){};
function xdebug_break() {};
}
function defineConstant($name, $value)
{
if (!defined($name))
if ( ! defined($name))
define($name, $value);
}
class Bokeh_Engine {
class Bokeh_Engine
{
protected static
$_zend_session_namespace,
$_php_command,
$_instance;
protected
$_cache_seed,
$_config,
$_front_controller;
protected ?Zend_Config_Ini $_config = null;
protected ?string $_cache_seed = null;
protected ?Zend_Controller_Front $_front_controller = null;
protected bool $_for_test = false;
public static function getInstance()
{
if ( static::$_instance)
if (static::$_instance)
return static::$_instance;
return static::$_instance = new self();
return static::$_instance = new self;
}
public function powerOn()
public function powerOn(bool $for_test = false): self
{
return
$this
$this->_for_test = $for_test;
return $this
->warmUp()
->setupDevOptions()
->setupControllerActionHelper()
@@ -74,13 +77,13 @@ class Bokeh_Engine {
}
public function getFrontController()
public function getFrontController(): ?Zend_Controller_Front
{
return $this->_front_controller;
}
public function warmUp() : self
public function warmUp(): self
{
return $this
->warmUpFiles()
@@ -90,11 +93,11 @@ class Bokeh_Engine {
}
public function warmUpFiles() : self
public function warmUpFiles(): self
{
require_once('Class/Url.php');
defineConstant('BASE_URL', Class_Url::baseUrl());
defineConstant('BASE_URL', Class_Url::baseUrl());
require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();
@@ -103,11 +106,12 @@ class Bokeh_Engine {
$this->setupConstants();
require_once('requires.php');
return $this;
}
public function warmUpDB() : self
public function warmUpDB(): self
{
return $this
->loadConfig()
@@ -115,14 +119,15 @@ class Bokeh_Engine {
}
public function warmUpSession() : self
public function warmUpSession(): self
{
return $this->setupSession();
}
public function warmUpAdminVarLanguageAndStorm() : self
public function warmUpAdminVarLanguageAndStorm(): self
{
$this->_defaultToVolatile();
Class_AdminVar::findAll();
$this
@@ -133,16 +138,16 @@ class Bokeh_Engine {
}
public function setupConstants()
public function setupConstants(): self
{
defineConstant('BOKEH_MAJOR_VERSION','8.0');
defineConstant('BOKEH_MAJOR_VERSION', '8.0');
defineConstant('BOKEH_RELEASE_NUMBER', BOKEH_MAJOR_VERSION . '.198');
defineConstant('BOKEH_REMOTE_FILES', 'https://git.afi-sa.net/afi/opacce/');
defineConstant('ROOT_PATH', realpath(dirname(__FILE__).'/..').'/');
defineConstant('ROOT_PATH', realpath(dirname(__FILE__) . '/..') . '/');
defineConstant('ZEND_FRAMEWORK_PATH', ROOT_PATH . 'library/storm/zf/library/');
defineConstant('ZEND_FRAMEWORK_PATH', ROOT_PATH . 'library/storm/zf/library/');
defineConstant('MODULEDIRECTORY', ROOT_PATH . 'application/modules');
defineConstant('LANG_DIR', ROOT_PATH . 'library/translation/');
@@ -155,12 +160,12 @@ class Bokeh_Engine {
defineConstant('GIT_REALTIME', false);
defineConstant('GIT_SKINS', 'git@git.afi-sa.net:opac-skins');
defineConstant('PATH_TEMP', ROOT_PATH . 'temp/');
defineConstant('PATH_TEMP', ROOT_PATH . 'temp/');
defineConstant('CKBASEPATH', 'ckeditor/');
defineConstant('CKBASEURL', BASE_URL . '/ckeditor/');
defineConstant('CKBASEPATH', 'ckeditor/');
defineConstant('CKBASEURL', BASE_URL . '/ckeditor/');
defineConstant('AMBERURL', BASE_URL . '/amber/');
defineConstant('AMBERURL', BASE_URL . '/amber/');
defineConstant('URL_ADMIN_SKIN', BASE_URL . '/public/admin/skins/');
defineConstant('URL_ADMIN_CSS', BASE_URL . '/public/admin/css/');
@@ -168,19 +173,19 @@ class Bokeh_Engine {
defineConstant('URL_ADMIN_JS', BASE_URL . '/public/admin/js/');
defineConstant('JQUERY', URL_ADMIN_JS . 'jquery-3.6.0.min.js');
defineConstant('JQUERYMOBILE_VERSION', '1.4.5');
defineConstant('JQUERYMOBILE_VERSION', '1.4.5');
defineConstant('JQUERYUI', URL_ADMIN_JS . 'jquery-ui-1.12.1/jquery-ui.min.js');
defineConstant('JQUERYUI_CSS', URL_ADMIN_JS.'jquery-ui-1.12.1/jquery-ui.min.css');
defineConstant('JQUERYUI_CSS', URL_ADMIN_JS . 'jquery-ui-1.12.1/jquery-ui.min.css');
defineConstant("URL_JS", BASE_URL . "/public/opac/js/");
defineConstant("URL_EPUB", BASE_URL . "/temp/epub/");
defineConstant("URL_SHARED_IMG", BASE_URL . "/public/opac/images/");
defineConstant('URL_JS', BASE_URL . '/public/opac/js/');
defineConstant('URL_EPUB', BASE_URL . '/temp/epub/');
defineConstant('URL_SHARED_IMG', BASE_URL . '/public/opac/images/');
// il y a des autre define URL dans ZendAfi_Controller_Plugin_DefineURLs
// par exemple URL_IMG, URL_CSS, URL_HTML et URL_JS va chercher dans 'URL_SKIN . 'nom de le module' . /html' etc.
defineConstant('BR','<br />');
defineConstant('NL',"\n");
defineConstant('CRLF', chr(13).chr(10));
defineConstant('BR', '<br />');
defineConstant('NL', "\n");
defineConstant('CRLF', chr(13) . chr(10));
defineConstant('URL_JAVA', BASE_URL . '/public/opac/java/');
defineConstant('PATH_JAVA', ROOT_PATH . 'public/opac/java/');
@@ -198,18 +203,20 @@ class Bokeh_Engine {
defineConstant('THUMBNAIL_FIT_WIDTH_HEIGHT', '500');
defineConstant('PATCH_PATH', ROOT_PATH . 'cosmogramme/sql/patch/');
defineConstant('GIT_REALTIME',false);
defineConstant('GIT_REALTIME', false);
return $this;
}
public function loadConfig($config_init_file_path = './config.ini', $allowModifications=false)
public function loadConfig(string $config_init_file_path = './config.ini',
bool $allowModifications = false): self
{
// load configuration (local ou production)
if(array_isset('REMOTE_ADDR', $_SERVER) and $_SERVER['REMOTE_ADDR'] == '127.0.0.1')
$serveur='local';
else
$serveur='production';
$serveur = (array_isset('REMOTE_ADDR', $_SERVER) && $_SERVER['REMOTE_ADDR'] == '127.0.0.1')
? 'local'
: 'production';
$this->_config = new Zend_Config_Ini($config_init_file_path, $serveur, $allowModifications);
Zend_Registry::set('cfg', $this->_config);
@@ -224,7 +231,7 @@ class Bokeh_Engine {
}
public function setupCache()
public function setupCache(): self
{
$frontendOptions = ['lifetime' => CACHE_LIFETIME, // durée du cache: 1h
'automatic_serialization' => false,
@@ -234,7 +241,7 @@ class Bokeh_Engine {
$backendOptions = $use_memcached
? ['servers' => [ ['host' => MEMCACHED_HOST,
'port' => MEMCACHED_PORT] ]]
: ['cache_dir' => PATH_TEMP ];
: ['cache_dir' => PATH_TEMP ];
// getting a Zend_Cache_Core object
$backend = 'File';
@@ -268,49 +275,54 @@ class Bokeh_Engine {
}
public function getDbName() : string
public function getDbName(): string
{
$this->loadConfig();
return $this->_config->sgbd->config->dbname;
}
public function getCacheSeed()
public function getCacheSeed(): ?string
{
return $this->_cache_seed;;
return $this->_cache_seed;
}
public function setCacheSeed($seed)
public function setCacheSeed(string $seed): self
{
$this->_cache_seed = $seed;
return $this;
}
public function setupSession()
public function setupSession(): self
{
try
{
$session = $this->_getZendSessionNamespace()->get(md5(BASE_URL));
} catch (Zend_Session_Exception $e) {
} catch (Zend_Session_Exception $e)
{
return $this->_timeoutReload();
}
if (!isset($session->initialized)) {
if ( ! isset($session->initialized))
{
Zend_Session::regenerateId();
$session->initialized = true;
}
if (!isset($session->baseUrl))
if ( ! isset($session->baseUrl))
$session->baseUrl = BASE_URL;
Zend_Registry::set('session', $session);
return $this;
}
protected function _timeoutReload()
protected function _timeoutReload(): self
{
$this->_getPhpCommand()->header('HTTP/1.1 503 Service Unavailable');
$this->_getPhpCommand()->echoHtml('<html>'
@@ -323,12 +335,14 @@ class Bokeh_Engine {
. '</body>'
.'</html>');
$this->_getPhpCommand()->exitDispatch();
return $this;
}
protected function _getPhpCommand()
{
if ( static::$_php_command)
if (static::$_php_command)
return static::$_php_command;
return new Bokeh_PhpCommand;
@@ -343,7 +357,7 @@ class Bokeh_Engine {
protected function _getZendSessionNamespace()
{
if ( static::$_zend_session_namespace )
if (static::$_zend_session_namespace)
return static::$_zend_session_namespace;
return new Bokeh_Session;
@@ -353,6 +367,7 @@ class Bokeh_Engine {
public function setZendSessionNamespace($instance): self
{
static::$_zend_session_namespace = $instance;
return $this;
}
@@ -364,8 +379,9 @@ class Bokeh_Engine {
}
public function setupLanguage()
public function setupLanguage(): self
{
$this->_defaultToVolatile();
$default = Class_AdminVar::getDefaultLanguage();
ZendAfi_Locale::setDefault($default);
Zend_Registry::set('locale', new ZendAfi_Locale());
@@ -381,8 +397,9 @@ class Bokeh_Engine {
}
protected function _setupTranslationsIn($translate, $default)
protected function _setupTranslationsIn($translate, $default): self
{
$this->_defaultToVolatile();
if ( ! $languages = Class_AdminVar::getLanguesWithoutDefault())
return $this;
@@ -398,7 +415,7 @@ class Bokeh_Engine {
}
function setupDatabase()
function setupDatabase(): self
{
// setup database
$sql = Zend_Db::factory($this->_config->sgbd->adapter,
@@ -406,7 +423,7 @@ class Bokeh_Engine {
$sql->usePrepared(false);
Zend_Db_Table::setDefaultAdapter($sql);
$afi_sql = new Class_Systeme_Sql();
$afi_sql = new Class_Systeme_Sql;
Zend_Registry::set('sql', $afi_sql);
Zend_Db_Table::getDefaultAdapter()->query('set names "UTF8"');
Zend_Db_Table::getDefaultAdapter()->query('set SQL_MODE = ""');
@@ -419,6 +436,7 @@ class Bokeh_Engine {
{
try
{
$this->_defaultToVolatile();
Class_Journal_StormObserver::register();
} catch(Exception $e)
{
@@ -429,26 +447,30 @@ class Bokeh_Engine {
}
function setupDevOptions()
function setupDevOptions(): self
{
//permet d'activer les fonctions en développement
if (null !== $experimental_dev = $this->_config->get('experimental_dev'))
defineConstant('DEVELOPMENT', $experimental_dev);
return $this;
}
function setupControllerActionHelper() {
function setupControllerActionHelper(): self
{
Zend_Controller_Action_HelperBroker::resetHelpers();
Zend_Controller_Action_HelperBroker::addHelper(new ZendAfi_Controller_Action_Helper_ViewRenderer());
Zend_Controller_Action_HelperBroker::addPrefix('ZendAfi_Controller_Action_Helper');
return $this;
}
function setupHTTPClient()
function setupHTTPClient(): self
{
if ( (isset ($this->_config->proxy->host) ) && ($this->_config->proxy->host != '') ){
if ((isset($this->_config->proxy->host)) && ($this->_config->proxy->host != ''))
{
//set up HTTP Client to use proxy settings
$proxy_config = [
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
@@ -467,64 +489,71 @@ class Bokeh_Engine {
}
function setupMail()
function setupMail(): self
{
if (isset($this->_config->mail->transport->file)) {
if (isset($this->_config->mail->transport->file))
{
ZendAfi_Mail::setDefaultTransport(new ZendAfi_Mail_Transport_File($this->_config->mail->transport->file));
return $this;
}
if (isset($this->_config->mail->transport->smtp)) {
if (isset($this->_config->mail->transport->smtp))
{
ZendAfi_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($this->_config->mail->transport->smtp->host,
$this->_config->mail->transport->smtp->toArray()));
return $this;
}
if (defined('SMTP_HOST'))
ZendAfi_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp(SMTP_HOST));
return $this;
}
function newFrontController()
function newFrontController(): Zend_Controller_Front
{
return Zend_Controller_Front::getInstance()
->setDispatcher(new ZendAfi_Controller_Dispatcher_Standard())
->addModuleDirectory(MODULEDIRECTORY)
->setDefaultModule('opac')
->registerPlugin(new ZendAfi_Controller_Plugin_SetupDomain())
->registerPlugin(new ZendAfi_Controller_Plugin_AdminAuth())
->registerPlugin(new ZendAfi_Controller_Plugin_SetupLocale())
->registerPlugin(new ZendAfi_Controller_Plugin_DefineURLs())
->registerPlugin(new ZendAfi_Controller_Plugin_InitModule())
->registerPlugin(new ZendAfi_Controller_Plugin_System())
->registerPlugin(new ZendAfi_Controller_Plugin_Popup())
->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS())
->registerPlugin(new ZendAfi_Controller_Plugin_Lectura())
->registerPlugin(new ZendAfi_Controller_Plugin_InspectorGadget())
->registerPlugin(new ZendAfi_Controller_Plugin_CnilConsent())
->registerPlugin(new ZendAfi_Controller_Plugin_Redmine())
->registerPlugin(new ZendAfi_Controller_Plugin_FeaturesTracking())
->registerPlugin(new ZendAfi_Controller_Plugin_LastSearch())
->registerPlugin(new ZendAfi_Controller_Plugin_SetupDomain)
->registerPlugin(new ZendAfi_Controller_Plugin_AdminAuth)
->registerPlugin(new ZendAfi_Controller_Plugin_SetupLocale)
->registerPlugin(new ZendAfi_Controller_Plugin_DefineURLs)
->registerPlugin(new ZendAfi_Controller_Plugin_InitModule)
->registerPlugin(new ZendAfi_Controller_Plugin_System)
->registerPlugin(new ZendAfi_Controller_Plugin_Popup)
->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS)
->registerPlugin(new ZendAfi_Controller_Plugin_Lectura)
->registerPlugin(new ZendAfi_Controller_Plugin_InspectorGadget)
->registerPlugin(new ZendAfi_Controller_Plugin_CnilConsent)
->registerPlugin(new ZendAfi_Controller_Plugin_Redmine)
->registerPlugin(new ZendAfi_Controller_Plugin_FeaturesTracking)
->registerPlugin(new ZendAfi_Controller_Plugin_LastSearch)
->registerPlugin(new ZendAfi_Controller_Plugin_XHProfile($this->_config))
->setParam('useDefaultControllerAlways', false);
}
function setupFrontController()
function setupFrontController(): self
{
$this->_front_controller = $this
->newFrontController()
->setBaseURL(BASE_URL);
$this->setupRoutes($this->_front_controller, $this->_config);
return $this;
}
function setupRoutes($front_controller, $cfg)
function setupRoutes(Zend_Controller_Front $front_controller, $cfg): self
{
if ('1' == $cfg->get('enable_rewriting')) {
if ('1' == $cfg->get('enable_rewriting'))
{
$front_controller
->setBaseUrl('')
->setRouter(new ZendAfi_Controller_Router_RewriteWithoutBaseUrl());
@@ -555,36 +584,53 @@ class Bokeh_Engine {
new ZendAfi_Controller_Router_Route_QueryString('admin/file-manager',
['module' => 'admin',
'controller' => 'file-manager']));
return $this;
}
function setupPagination()
function setupPagination(): self
{
Zend_Paginator::setDefaultScrollingStyle('Sliding');
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
return $this;
}
function setupSearch()
function setupSearch(): self
{
defineConstant('MAX_SEARCH_RESULTS', '');
Class_CriteresRecherche::setMaxSearchResults(MAX_SEARCH_RESULTS);
return $this;
}
function setupDigitalResources()
function setupDigitalResources(): self
{
$this->_defaultToVolatile();
Class_DigitalResource::getInstance()->bootstrap($this->_front_controller);
return $this;
}
function setupCustomFields()
function setupCustomFields(): self
{
Class_CustomField_Model::registerDefault();
return $this;
}
protected function _defaultToVolatile(): self
{
if ($this->_for_test)
Storm_Model_Loader::defaultToVolatile();
$this->_for_test = false;
return $this;
}
}
@@ -622,8 +668,7 @@ class Bokeh_Session
/* for test */
protected static $_cookie_jar;
public function get($session_id)
public function get(string $session_id): Zend_Session_Namespace
{
$this->_getCookieJar()->session_set_cookie_params(['httponly' => true,
'secure' => Class_Url::isSecure()]);
@@ -648,7 +693,7 @@ class Bokeh_Session
}
protected function _isReadAndClose() : bool
protected function _isReadAndClose(): bool
{
$urls_read_only = ['/newsletter/send-progress',
'/noticeajax/'];
@@ -677,6 +722,7 @@ class Bokeh_Session
class Bokeh_Session_CookieJar
{
public function session_set_cookie_params(): bool
{
return call_user_func_array('session_set_cookie_params', func_get_args());
@@ -686,9 +732,9 @@ class Bokeh_Session_CookieJar
function setupOpac()
function setupOpac(bool $for_test = false)
{
return Bokeh_Engine::getInstance()
->powerOn()
->powerOn($for_test)
->getFrontController();
}