Przeglądaj źródła

NEW Reduce memory usage by removing deprecated constant loading.

Laurent Destailleur 8 lat temu
rodzic
commit
e6e9b65594

+ 20 - 22
htdocs/core/class/commonobject.class.php

@@ -42,50 +42,59 @@ abstract class CommonObject
      * @var DoliDb		Database handler (result of a new DoliDB)
      */
 	public $db;
-
 	/**
 	 * @var int The object identifier
 	 */
 	public $id;
-
     /**
      * @var string 		Error string
      * @deprecated		Use instead the array of error strings
      * @see             errors
      */
     public $error;
-
 	/**
      * @var string[]	Array of error strings
      */
     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
      */
     public $import_key;
-
     /**
      * @var mixed		Contains data to manage extrafields
      */
     public $array_options=array();
-
     /**
      * @var int[]		Array of linked objects ids. Loaded by ->fetchObjectLinked
      */
     public $linkedObjectsIds;
-
     /**
      * @var mixed		Array of linked objects. Loaded by ->fetchObjectLinked
      */
     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.
      */
     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.
 
@@ -166,19 +175,6 @@ abstract class CommonObject
 	 */
 	public $ref_ext;
 
-	/**
-	 * @var string
-	 */
-	public $element;
-	/**
-	 * @var string
-	 */
-	public $table_element;
-	/**
-	 * @var
-	 */
-	public $table_element_line;
-
 	/**
 	 * @var int The object's status
 	 * @see setStatut()
@@ -332,8 +328,10 @@ abstract class CommonObject
     public $firstname;
     public $civility_id;
 
+    
     // No constructor as it is an abstract class
 
+    
     /**
      * 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

+ 9 - 13
htdocs/core/class/conf.class.php

@@ -128,11 +128,7 @@ class Conf
 
 		dol_syslog(get_class($this)."::setValues");
 
-		/*
-		 * Definition de toutes les constantes globales d'environnement
-		 * - En constante php (TODO a virer)
-		 * - En $this->global->key=value
-		 */
+		//Define all global constants into $this->global->key=value
 		$sql = "SELECT ".$db->decrypt('name')." as name,";
 		$sql.= " ".$db->decrypt('value')." as value, entity";
 		$sql.= " FROM ".MAIN_DB_PREFIX."const";
@@ -158,7 +154,7 @@ class Conf
 				$value=$objp->value;
 				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;
 
 					if ($value && preg_match('/^MAIN_MODULE_/',$key))
@@ -207,7 +203,7 @@ class Conf
 		    $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)) {
             $filesList = explode(":", $this->global->LOCAL_CONSTS_FILES);
             foreach ($filesList as $file) {
@@ -333,13 +329,12 @@ class Conf
 		$this->propal->dir_output=$rootfordata."/propale";
 		$this->propal->dir_temp=$rootfordata."/propale/temp";
 
-		// Exception: Some dir are not the name of module. So we keep exception here
-		// for backward compatibility.
+		// Exception: Some dir are not the name of module. So we keep exception here for backward compatibility.
 
 		// 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
-		$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
 		if (! empty($this->fournisseur))
@@ -599,8 +594,8 @@ class Conf
         }
 
 		// We init log handlers
-		if (defined('SYSLOG_HANDLERS')) {
-			$handlers = json_decode(constant('SYSLOG_HANDLERS'));
+		if (! empty($this->global->SYSLOG_HANDLERS)) {
+			$handlers = json_decode($this->global->SYSLOG_HANDLERS);
 		} else {
 			$handlers = array();
 		}
@@ -632,6 +627,7 @@ class Conf
 				$this->loghandlers[$handler] = $loghandlerinstance;
 			}
 		}
+		
 	}
 }
 

+ 0 - 1
htdocs/core/class/extrafields.class.php

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

+ 4 - 3
htdocs/core/modules/syslog/mod_syslog_file.php

@@ -103,7 +103,8 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
 	 */
 	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;
 	}
 
@@ -122,12 +123,12 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
 
 		$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+');
 
 		if (! $filefd)
 		{
-			if (! defined("SYSLOG_FILE_NO_ERROR"))
+			if (empty($conf->global->SYSLOG_FILE_NO_ERROR))
 			{
 				// Do not break dolibarr usage if log fails
 				//throw new Exception('Failed to open log file '.basename($logfile));

+ 2 - 6
htdocs/core/modules/syslog/mod_syslog_syslog.php

@@ -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 (defined("SYSLOG_FACILITY") && constant("SYSLOG_FACILITY"))
+		if (! empty($conf->global->SYSLOG_FACILITY))
 		{
-			if (constant(constant('SYSLOG_FACILITY')))
-			{
-				$facility = constant(constant("SYSLOG_FACILITY"));
-			}
-			else $facility = LOG_USER;
+			$facility = constant($conf->global->SYSLOG_FACILITY);
 		}
 		else $facility = LOG_USER;
 

+ 6 - 2
htdocs/langs/en_US/admin.lang

@@ -427,6 +427,11 @@ WarningPHPMail=WARNING: Some email providers (like Yahoo) does not allow you to
 ClickToShowDescription=Click to show description
 DependsOn=This module need the 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
 Module0Name=Users & groups
 Module0Desc=Users / Employees and Groups management
@@ -1338,7 +1343,7 @@ CacheByServer=Cache by server
 CacheByClient=Cache by browser
 CompressionOfResources=Compression of HTTP responses
 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
 DefaultSearchFilters=Search filters
 DefaultSortOrder=Sort orders
@@ -1535,7 +1540,6 @@ BankOrderGlobalDesc=General display order
 BankOrderES=Spanish
 BankOrderESDesc=Spanish display order
 ChequeReceiptsNumberingModule=Cheque Receipts Numbering module
-
 ##### Multicompany #####
 MultiCompanySetup=Multi-company module setup
 ##### Suppliers #####

+ 0 - 4
htdocs/langs/en_US/main.lang

@@ -310,10 +310,6 @@ Paste=Paste
 Default=Default
 DefaultValue=Default value
 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
 UnitPrice=Unit price
 UnitPriceHT=Unit price (net)

+ 7 - 8
htdocs/main.inc.php

@@ -29,10 +29,10 @@
 /**
  *	\file       htdocs/main.inc.php
  *	\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.
 $micro_start_time=0;
@@ -48,7 +48,7 @@ if (! empty($_SERVER['MAIN_SHOW_TUNING_INFO']))
 }
 
 // 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())
     {
@@ -172,7 +172,7 @@ if (! empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6)
 // Include the conf.php and functions.lib.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"]))
 {
 	$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]);
 session_name($sessionname);
 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)
     {
@@ -206,8 +206,7 @@ if (ini_get('register_globals'))    // To solve bug in using $_SESSION
     }
 }
 
-// Init the 5 global objects
-// This include will make the new and set properties for: $conf, $db, $langs, $user, $mysoc objects
+// Init the 5 global objects, this include will make the new and set properties for: $conf, $db, $langs, $user, $mysoc
 require_once 'master.inc.php';
 
 // 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

+ 2 - 6
htdocs/master.inc.php

@@ -114,7 +114,7 @@ if (! defined('NOREQUIRESOC'))  require_once DOL_DOCUMENT_ROOT .'/societe/class/
  */
 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."'";
 
-	// 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);
 }
 
@@ -258,7 +258,3 @@ $hookmanager=new HookManager($db);
 
 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;
-