NEW Reduce memory usage by removing deprecated constant loading.

This commit is contained in:
Laurent Destailleur 2017-04-14 12:38:52 +02:00
parent 4e021c123b
commit e6e9b65594
9 changed files with 50 additions and 65 deletions

View File

@ -42,50 +42,59 @@ abstract class CommonObject
* @var DoliDb Database handler (result of a new DoliDB) * @var DoliDb Database handler (result of a new DoliDB)
*/ */
public $db; public $db;
/** /**
* @var int The object identifier * @var int The object identifier
*/ */
public $id; public $id;
/** /**
* @var string Error string * @var string Error string
* @deprecated Use instead the array of error strings * @deprecated Use instead the array of error strings
* @see errors * @see errors
*/ */
public $error; public $error;
/** /**
* @var string[] Array of error strings * @var string[] Array of error strings
*/ */
public $errors=array(); public $errors=array();
/**
* @var string
*/
public $element;
/**
* @var string
*/
public $table_element;
/**
* @var
*/
public $table_element_line;
/** /**
* @var string Key value used to track if data is coming from import wizard * @var string Key value used to track if data is coming from import wizard
*/ */
public $import_key; public $import_key;
/** /**
* @var mixed Contains data to manage extrafields * @var mixed Contains data to manage extrafields
*/ */
public $array_options=array(); public $array_options=array();
/** /**
* @var int[] Array of linked objects ids. Loaded by ->fetchObjectLinked * @var int[] Array of linked objects ids. Loaded by ->fetchObjectLinked
*/ */
public $linkedObjectsIds; public $linkedObjectsIds;
/** /**
* @var mixed Array of linked objects. Loaded by ->fetchObjectLinked * @var mixed Array of linked objects. Loaded by ->fetchObjectLinked
*/ */
public $linkedObjects; public $linkedObjects;
/**
* @var Object To store a cloned copy of object before to edit it and keep track of old properties
*/
public $oldcopy;
/** /**
* @var string Column name of the ref field. * @var string Column name of the ref field.
*/ */
protected $table_ref_field = ''; protected $table_ref_field = '';
// Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them.
@ -166,19 +175,6 @@ abstract class CommonObject
*/ */
public $ref_ext; public $ref_ext;
/**
* @var string
*/
public $element;
/**
* @var string
*/
public $table_element;
/**
* @var
*/
public $table_element_line;
/** /**
* @var int The object's status * @var int The object's status
* @see setStatut() * @see setStatut()
@ -332,8 +328,10 @@ abstract class CommonObject
public $firstname; public $firstname;
public $civility_id; public $civility_id;
// No constructor as it is an abstract class // No constructor as it is an abstract class
/** /**
* Check an object id/ref exists * Check an object id/ref exists
* If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch

View File

@ -128,11 +128,7 @@ class Conf
dol_syslog(get_class($this)."::setValues"); dol_syslog(get_class($this)."::setValues");
/* //Define all global constants into $this->global->key=value
* Definition de toutes les constantes globales d'environnement
* - En constante php (TODO a virer)
* - En $this->global->key=value
*/
$sql = "SELECT ".$db->decrypt('name')." as name,"; $sql = "SELECT ".$db->decrypt('name')." as name,";
$sql.= " ".$db->decrypt('value')." as value, entity"; $sql.= " ".$db->decrypt('value')." as value, entity";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
@ -158,7 +154,7 @@ class Conf
$value=$objp->value; $value=$objp->value;
if ($key) if ($key)
{ {
if (! defined("$key")) define("$key", $value); // In some cases, the constant might be already forced (Example: SYSLOG_HANDLERS during install) //if (! defined("$key")) define("$key", $value); // In some cases, the constant might be already forced (Example: SYSLOG_HANDLERS during install)
$this->global->$key=$value; $this->global->$key=$value;
if ($value && preg_match('/^MAIN_MODULE_/',$key)) if ($value && preg_match('/^MAIN_MODULE_/',$key))
@ -207,7 +203,7 @@ class Conf
$db->free($resql); $db->free($resql);
} }
// Include other local consts.php files and fetch their values to the corresponding database constants // Include other local consts.php files and fetch their values to the corresponding database constants.
if (! empty($this->global->LOCAL_CONSTS_FILES)) { if (! empty($this->global->LOCAL_CONSTS_FILES)) {
$filesList = explode(":", $this->global->LOCAL_CONSTS_FILES); $filesList = explode(":", $this->global->LOCAL_CONSTS_FILES);
foreach ($filesList as $file) { foreach ($filesList as $file) {
@ -333,13 +329,12 @@ class Conf
$this->propal->dir_output=$rootfordata."/propale"; $this->propal->dir_output=$rootfordata."/propale";
$this->propal->dir_temp=$rootfordata."/propale/temp"; $this->propal->dir_temp=$rootfordata."/propale/temp";
// Exception: Some dir are not the name of module. So we keep exception here // Exception: Some dir are not the name of module. So we keep exception here for backward compatibility.
// for backward compatibility.
// Sous module bons d'expedition // Sous module bons d'expedition
$this->expedition_bon->enabled= defined("MAIN_SUBMODULE_EXPEDITION")?MAIN_SUBMODULE_EXPEDITION:0; $this->expedition_bon->enabled=$this->global->MAIN_SUBMODULE_EXPEDITION?$this->global->MAIN_SUBMODULE_EXPEDITION:0;
// Sous module bons de livraison // Sous module bons de livraison
$this->livraison_bon->enabled=defined("MAIN_SUBMODULE_LIVRAISON")?MAIN_SUBMODULE_LIVRAISON:0; $this->livraison_bon->enabled=$this->global->MAIN_SUBMODULE_LIVRAISON?$this->global->MAIN_SUBMODULE_LIVRAISON:0;
// Module fournisseur // Module fournisseur
if (! empty($this->fournisseur)) if (! empty($this->fournisseur))
@ -599,8 +594,8 @@ class Conf
} }
// We init log handlers // We init log handlers
if (defined('SYSLOG_HANDLERS')) { if (! empty($this->global->SYSLOG_HANDLERS)) {
$handlers = json_decode(constant('SYSLOG_HANDLERS')); $handlers = json_decode($this->global->SYSLOG_HANDLERS);
} else { } else {
$handlers = array(); $handlers = array();
} }
@ -632,6 +627,7 @@ class Conf
$this->loghandlers[$handler] = $loghandlerinstance; $this->loghandlers[$handler] = $loghandlerinstance;
} }
} }
} }
} }

View File

@ -641,7 +641,6 @@ class ExtraFields
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
$sql.= " ORDER BY pos"; $sql.= " ORDER BY pos";
dol_syslog(get_class($this)."::fetch_name_optionals_label", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {

View File

@ -103,7 +103,8 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
*/ */
private function getFilename($suffixinfilename='') private function getFilename($suffixinfilename='')
{ {
$tmp=str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, SYSLOG_FILE); global $conf;
$tmp=str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE);
return $suffixinfilename?preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp):$tmp; return $suffixinfilename?preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp):$tmp;
} }
@ -122,12 +123,12 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
$logfile = $this->getFilename($suffixinfilename); $logfile = $this->getFilename($suffixinfilename);
if (defined("SYSLOG_FILE_NO_ERROR")) $filefd = @fopen($logfile, 'a+'); if (! empty($conf->global->SYSLOG_FILE_NO_ERROR)) $filefd = @fopen($logfile, 'a+');
else $filefd = fopen($logfile, 'a+'); else $filefd = fopen($logfile, 'a+');
if (! $filefd) if (! $filefd)
{ {
if (! defined("SYSLOG_FILE_NO_ERROR")) if (empty($conf->global->SYSLOG_FILE_NO_ERROR))
{ {
// Do not break dolibarr usage if log fails // Do not break dolibarr usage if log fails
//throw new Exception('Failed to open log file '.basename($logfile)); //throw new Exception('Failed to open log file '.basename($logfile));

View File

@ -111,13 +111,9 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
if (! empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) return; // Global option to disable output of this handler if (! empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) return; // Global option to disable output of this handler
if (defined("SYSLOG_FACILITY") && constant("SYSLOG_FACILITY")) if (! empty($conf->global->SYSLOG_FACILITY))
{ {
if (constant(constant('SYSLOG_FACILITY'))) $facility = constant($conf->global->SYSLOG_FACILITY);
{
$facility = constant(constant("SYSLOG_FACILITY"));
}
else $facility = LOG_USER;
} }
else $facility = LOG_USER; else $facility = LOG_USER;

View File

@ -427,6 +427,11 @@ WarningPHPMail=WARNING: Some email providers (like Yahoo) does not allow you to
ClickToShowDescription=Click to show description ClickToShowDescription=Click to show description
DependsOn=This module need the module(s) DependsOn=This module need the module(s)
RequiredBy=This module is required by module(s) RequiredBy=This module is required by module(s)
TheKeyIsTheNameOfHtmlField=The key is the name of the html field. This need to have technical knowledges to read the content of the HTML page to get the key name of a field.
PageUrlForDefaultValues=You must enter here the relative url of the page. Examples:
PageUrlForDefaultValuesCreate=<br>For form to create a new thirdparty, it is <strong>%s</strong>
PageUrlForDefaultValuesList=<br>For page that list thirdparties, it is <strong>%s</strong>
# Modules # Modules
Module0Name=Users & groups Module0Name=Users & groups
Module0Desc=Users / Employees and Groups management Module0Desc=Users / Employees and Groups management
@ -1338,7 +1343,7 @@ CacheByServer=Cache by server
CacheByClient=Cache by browser CacheByClient=Cache by browser
CompressionOfResources=Compression of HTTP responses CompressionOfResources=Compression of HTTP responses
TestNotPossibleWithCurrentBrowsers=Such an automatic detection is not possible with current browsers TestNotPossibleWithCurrentBrowsers=Such an automatic detection is not possible with current browsers
DefaultValuesDesc=You can define/force here the default value you want to get when your create a new record, and/or defaut filters or soting order when your list record. DefaultValuesDesc=You can define/force here the default value you want to get when your create a new record, and/or defaut filters or sort order when your list record.
DefaultCreateForm=Create forms DefaultCreateForm=Create forms
DefaultSearchFilters=Search filters DefaultSearchFilters=Search filters
DefaultSortOrder=Sort orders DefaultSortOrder=Sort orders
@ -1535,7 +1540,6 @@ BankOrderGlobalDesc=General display order
BankOrderES=Spanish BankOrderES=Spanish
BankOrderESDesc=Spanish display order BankOrderESDesc=Spanish display order
ChequeReceiptsNumberingModule=Cheque Receipts Numbering module ChequeReceiptsNumberingModule=Cheque Receipts Numbering module
##### Multicompany ##### ##### Multicompany #####
MultiCompanySetup=Multi-company module setup MultiCompanySetup=Multi-company module setup
##### Suppliers ##### ##### Suppliers #####

View File

@ -310,10 +310,6 @@ Paste=Paste
Default=Default Default=Default
DefaultValue=Default value DefaultValue=Default value
DefaultValues=Default values DefaultValues=Default values
TheKeyIsTheNameOfHtmlField=The key is the name of the html field. This need to have technical knowledges to read the content of the HTML page to get the key name of a field.
PageUrlForDefaultValues=You must enter here the relative url of the page. Examples:
PageUrlForDefaultValuesCreate=<br>For form to create a new thirdparty, it is <strong>%s</strong>.
PageUrlForDefaultValuesList=<br>For page that list thirdparties, it is <strong>%s</strong>.
Price=Price Price=Price
UnitPrice=Unit price UnitPrice=Unit price
UnitPriceHT=Unit price (net) UnitPriceHT=Unit price (net)

View File

@ -29,10 +29,10 @@
/** /**
* \file htdocs/main.inc.php * \file htdocs/main.inc.php
* \ingroup core * \ingroup core
* \brief File that defines environment for Dolibarr pages only (variables not required by scripts) * \brief File that defines environment for Dolibarr GUI pages only (file not required by scripts)
*/ */
//@ini_set('memory_limit', '64M'); // This may be useless if memory is hard limited by your PHP //@ini_set('memory_limit', '128M'); // This may be useless if memory is hard limited by your PHP
// For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined. // For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined.
$micro_start_time=0; $micro_start_time=0;
@ -48,7 +48,7 @@ if (! empty($_SERVER['MAIN_SHOW_TUNING_INFO']))
} }
// Removed magic_quotes // Removed magic_quotes
if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6 if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* deprecated in PHP 5.0 and removed in PHP 5.5
{ {
if (get_magic_quotes_gpc()) if (get_magic_quotes_gpc())
{ {
@ -172,7 +172,7 @@ if (! empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6)
// Include the conf.php and functions.lib.php // Include the conf.php and functions.lib.php
require_once 'filefunc.inc.php'; require_once 'filefunc.inc.php';
// If there is a POST parameter to tell to save automatically some POST parameters into a cookies, we do it // If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it
if (! empty($_POST["DOL_AUTOSET_COOKIE"])) if (! empty($_POST["DOL_AUTOSET_COOKIE"]))
{ {
$tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2); $tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2);
@ -198,7 +198,7 @@ $sessiontimeout='DOLSESSTIMEOUT_'.$prefix;
if (! empty($_COOKIE[$sessiontimeout])) ini_set('session.gc_maxlifetime',$_COOKIE[$sessiontimeout]); if (! empty($_COOKIE[$sessiontimeout])) ini_set('session.gc_maxlifetime',$_COOKIE[$sessiontimeout]);
session_name($sessionname); session_name($sessionname);
session_start(); session_start();
if (ini_get('register_globals')) // To solve bug in using $_SESSION if (ini_get('register_globals')) // Deprecated in 5.3 and removed in 5.4. To solve bug in using $_SESSION
{ {
foreach ($_SESSION as $key=>$value) foreach ($_SESSION as $key=>$value)
{ {
@ -206,8 +206,7 @@ if (ini_get('register_globals')) // To solve bug in using $_SESSION
} }
} }
// Init the 5 global objects // Init the 5 global objects, this include will make the new and set properties for: $conf, $db, $langs, $user, $mysoc
// This include will make the new and set properties for: $conf, $db, $langs, $user, $mysoc objects
require_once 'master.inc.php'; require_once 'master.inc.php';
// Activate end of page function // Activate end of page function
@ -735,7 +734,7 @@ if (! defined('NOLOGIN'))
} }
/* /*
* Overwrite configs global by personal configs * Overwrite configs global by personal configs (Note: Some conf->global personal vars were overwrote by the user->fetch)
*/ */
// Set liste_limit // Set liste_limit

View File

@ -114,7 +114,7 @@ if (! defined('NOREQUIRESOC')) require_once DOL_DOCUMENT_ROOT .'/societe/class/
*/ */
if (! defined('NOREQUIRETRAN')) if (! defined('NOREQUIRETRAN'))
{ {
$langs = new Translate('',$conf); // A mettre apres lecture de la conf $langs = new Translate('',$conf); // Must be after reading conf
} }
/* /*
@ -180,7 +180,7 @@ if (! defined('NOREQUIREDB'))
//print "Will work with data into entity instance number '".$conf->entity."'"; //print "Will work with data into entity instance number '".$conf->entity."'";
// Here we read database (llx_const table) and define $conf->global->XXX var. // Here we read database (llx_const table and llx_default_values) and define $conf->global->XXX var.
$conf->setValues($db); $conf->setValues($db);
} }
@ -258,7 +258,3 @@ $hookmanager=new HookManager($db);
if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR'); if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR');
// We force FPDF
if (! empty($dolibarr_pdf_force_fpdf)) $conf->global->MAIN_USE_FPDF=$dolibarr_pdf_force_fpdf;