Skip to content

Commit

Permalink
Several fixes in project creation, cache of dolGetIfFromCode, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Nov 15, 2018
1 parent e94b545 commit 85cdc44
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 47 deletions.
46 changes: 30 additions & 16 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -2837,35 +2837,50 @@ function isValidPhone($phone)
* @param string $stringencoding Encoding of string
* @return int Length of string
*/
function dol_strlen($string,$stringencoding='UTF-8')
function dol_strlen($string, $stringencoding='UTF-8')
{
if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
else return strlen($string);
}

/**
* Make a substring. Works even in mbstring module is not enabled.
* Make a substring. Works even if mbstring module is not enabled for better compatibility.
*
* @param string $string String to scan
* @param string $start Start position
* @param int $length Length
* @param int $length Length (in nb of characters or nb of bytes depending on trunconbytes param)
* @param string $stringencoding Page code used for input string encoding
* @param int $trunconbytes 1=Length is max of bytes instead of max of characters
* @return string substring
*/
function dol_substr($string,$start,$length,$stringencoding='')
function dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
{
global $langs;

if (empty($stringencoding)) $stringencoding=$langs->charset_output;

$ret='';
if (function_exists('mb_substr'))
if (empty($trunconbytes))
{
$ret=mb_substr($string,$start,$length,$stringencoding);
if (function_exists('mb_substr'))
{
$ret=mb_substr($string, $start, $length, $stringencoding);
}
else
{
$ret=substr($string, $start, $length);
}
}
else
{
$ret=substr($string,$start,$length);
if (function_exists('mb_strcut'))
{
$ret=mb_strcut($string, $start, $length, $stringencoding);
}
else
{
$ret=substr($string, $start, $length);
}
}
return $ret;
}
Expand Down Expand Up @@ -3063,7 +3078,7 @@ function plotWithOptions() {
* @param string $trunc Where to trunc: right, left, middle (size must be a 2 power), wrap
* @param string $stringencoding Tell what is source string encoding
* @param int $nodot Truncation do not add ... after truncation. So it's an exact truncation.
* @param int $display Trunc is use to display and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
* @param int $display Trunc is used to display data and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
* @return string Truncated string. WARNING: length is never higher than $size if $nodot is set, but can be 3 chars higher otherwise.
*/
function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodot=0, $display=0)
Expand Down Expand Up @@ -6782,26 +6797,27 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id
if ($key == '') return '';

// Check in cache
if (isset($cache_codes[$tablename][$key])) // Can be defined to 0 or ''
if (isset($cache_codes[$tablename][$key][$fieldid])) // Can be defined to 0 or ''
{
return $cache_codes[$tablename][$key]; // Found in cache
return $cache_codes[$tablename][$key][$fieldid]; // Found in cache
}

dol_syslog('dol_getIdFromCode (value not found into cache)', LOG_DEBUG);

$sql = "SELECT ".$fieldid." as valuetoget";
$sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
$sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
if (! empty($entityfilter))
$sql.= " AND entity IN (" . getEntity($tablename) . ")";

dol_syslog('dol_getIdFromCode', LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $cache_codes[$tablename][$key]=$obj->valuetoget;
else $cache_codes[$tablename][$key]='';
if ($obj) $cache_codes[$tablename][$key][$fieldid]=$obj->valuetoget;
else $cache_codes[$tablename][$key][$fieldid]='';
$db->free($resql);
return $cache_codes[$tablename][$key];
return $cache_codes[$tablename][$key][$fieldid];
}
else
{
Expand Down Expand Up @@ -6889,8 +6905,6 @@ function picto_from_langcode($codelang, $moreatt = '')

if (empty($codelang)) return '';

if (empty($codelang)) return '';

if ($codelang == 'auto')
{
return '<span class="fa fa-globe"></span>';
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/project/mod_project_simple.php
Expand Up @@ -122,7 +122,7 @@ function canBeActivated()
* @param Project $project Object project
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$project)
function getNextValue($objsoc, $project)
{
global $db,$conf;

Expand Down Expand Up @@ -167,9 +167,9 @@ function getNextValue($objsoc,$project)
* @param Project $project Object project
* @return string Next not used reference
*/
function project_get_num($objsoc=0,$project='')
function project_get_num($objsoc=0, $project='')
{
// phpcs:enable
return $this->getNextValue($objsoc,$project);
return $this->getNextValue($objsoc, $project);
}
}
8 changes: 4 additions & 4 deletions htdocs/core/modules/project/mod_project_universal.php
Expand Up @@ -123,7 +123,7 @@ function getExample()
* @param Project $project Object project
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$project)
function getNextValue($objsoc, $project)
{
global $db,$conf;

Expand All @@ -139,7 +139,7 @@ function getNextValue($objsoc,$project)
}

$date=empty($project->date_c)?dol_now():$project->date_c;
$numFinal=get_next_value($db,$mask,'projet','ref','',$objsoc->code_client,$date);
$numFinal=get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc->code_client : ''), $date);

return $numFinal;
}
Expand All @@ -153,9 +153,9 @@ function getNextValue($objsoc,$project)
* @param Project $project Object project
* @return string Next not used reference
*/
function project_get_num($objsoc=0,$project='')
function project_get_num($objsoc=0, $project='')
{
// phpcs:enable
return $this->getNextValue($objsoc,$project);
return $this->getNextValue($objsoc, $project);
}
}

0 comments on commit 85cdc44

Please sign in to comment.