2
0
forked from Wavyzz/dolibarr

Scrutinizer Auto-Fixes

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
Scrutinizer Auto-Fixer
2019-11-19 08:30:26 +00:00
parent 8fd327adbb
commit cd7523318d
4 changed files with 102 additions and 102 deletions

View File

@@ -321,7 +321,7 @@ print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">'; print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
$newcardbutton = ''; $newcardbutton = '';
//if ($user->rights->emailcollector->creer) //if ($user->rights->emailcollector->creer)

View File

@@ -30,22 +30,22 @@
// $backtopage may be defined // $backtopage may be defined
// $triggermodname may be defined // $triggermodname may be defined
if (! empty($permissionedit) && empty($permissiontoadd)) $permissiontoadd = $permissionedit; // For backward compatibility if (!empty($permissionedit) && empty($permissiontoadd)) $permissiontoadd = $permissionedit; // For backward compatibility
if ($cancel) if ($cancel)
{ {
/*var_dump($cancel); /*var_dump($cancel);
var_dump($backtopage);exit;*/ var_dump($backtopage);exit;*/
if (! empty($backtopage)) if (!empty($backtopage))
{ {
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
} }
$action=''; $action = '';
} }
// Action to add record // Action to add record
if ($action == 'add' && ! empty($permissiontoadd)) if ($action == 'add' && !empty($permissiontoadd))
{ {
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
@@ -66,17 +66,17 @@ if ($action == 'add' && ! empty($permissiontoadd))
} elseif ($object->fields[$key]['type'] == 'datetime') { } elseif ($object->fields[$key]['type'] == 'datetime') {
$value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'));
} elseif ($object->fields[$key]['type'] == 'duration') { } elseif ($object->fields[$key]['type'] == 'duration') {
$value = 60*60*GETPOST($key.'hour', 'int') + 60*GETPOST($key.'min', 'int'); $value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
} elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) { } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) {
$value = price2num(GETPOST($key, 'none')); // To fix decimal separator according to lang setup $value = price2num(GETPOST($key, 'none')); // To fix decimal separator according to lang setup
} else { } else {
$value = GETPOST($key, 'alpha'); $value = GETPOST($key, 'alpha');
} }
if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field
if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field
$object->$key=$value; $object->$key = $value;
if ($val['notnull'] > 0 && $object->$key == '' && ! is_null($val['default']) && $val['default'] == '(PROV)') if ($val['notnull'] > 0 && $object->$key == '' && !is_null($val['default']) && $val['default'] == '(PROV)')
{ {
$object->$key = '(PROV)'; $object->$key = '(PROV)';
} }
@@ -136,7 +136,7 @@ if ($action == 'update' && !empty($permissiontoadd))
$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
} elseif ($object->fields[$key]['type'] == 'duration') { } elseif ($object->fields[$key]['type'] == 'duration') {
if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') { if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') {
$value = 60*60*GETPOST($key.'hour', 'int') + 60*GETPOST($key.'min', 'int'); $value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');
} else { } else {
$value = ''; $value = '';
} }

View File

@@ -5689,7 +5689,7 @@ abstract class CommonObject
} }
elseif (in_array($type, array('duration'))) elseif (in_array($type, array('duration')))
{ {
$out=$form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1); $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1);
} }
elseif (in_array($type, array('int', 'integer'))) elseif (in_array($type, array('int', 'integer')))
{ {
@@ -6317,13 +6317,13 @@ abstract class CommonObject
elseif ($type == 'duration') elseif ($type == 'duration')
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (! is_null($value) && $value !== '') { if (!is_null($value) && $value !== '') {
$value = convertSecondToTime($value, 'allhourmin'); $value = convertSecondToTime($value, 'allhourmin');
} }
} }
elseif ($type == 'double' || $type == 'real') elseif ($type == 'double' || $type == 'real')
{ {
if (! is_null($value) && $value !== '') { if (!is_null($value) && $value !== '') {
$value = price($value); $value = price($value);
} }
} }
@@ -6349,7 +6349,7 @@ abstract class CommonObject
} }
elseif ($type == 'price') elseif ($type == 'price')
{ {
if (! is_null($value) && $value !== '') { if (!is_null($value) && $value !== '') {
$value = price($value, 0, $langs, 0, 0, -1, $conf->currency); $value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
} }
} }
@@ -7366,7 +7366,7 @@ abstract class CommonObject
} }
if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]);
if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; // May force 0 to null if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; // May force 0 to null
} }
return $queryarray; return $queryarray;
@@ -7409,7 +7409,7 @@ abstract class CommonObject
} }
else else
{ {
if (! is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) { if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
$this->{$field} = (int) $obj->{$field}; $this->{$field} = (int) $obj->{$field};
} else { } else {
$this->{$field} = null; $this->{$field} = null;
@@ -7426,7 +7426,7 @@ abstract class CommonObject
} }
else else
{ {
if (! is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) { if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
$this->{$field} = (double) $obj->{$field}; $this->{$field} = (double) $obj->{$field};
} else { } else {
$this->{$field} = null; $this->{$field} = null;

View File

@@ -42,9 +42,9 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
global $db, $langs; global $db, $langs;
if (empty($objectname)) return -1; if (empty($objectname)) return -1;
if (empty($readdir)) $readdir=$destdir; if (empty($readdir)) $readdir = $destdir;
if (! empty($addfieldentry['arrayofkeyval']) && ! is_array($addfieldentry['arrayofkeyval'])) if (!empty($addfieldentry['arrayofkeyval']) && !is_array($addfieldentry['arrayofkeyval']))
{ {
dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.'); dol_print_error('', 'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.');
return -1; return -1;
@@ -63,17 +63,17 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors');
return -2; return -2;
} }
if (! preg_match('/^(integer|price|sellist|varchar|double|text|html|duration)/', $addfieldentry['type']) if (!preg_match('/^(integer|price|sellist|varchar|double|text|html|duration)/', $addfieldentry['type'])
&& ! preg_match('/^(boolean|real|date|datetime|timestamp)$/', $addfieldentry['type'])) && !preg_match('/^(boolean|real|date|datetime|timestamp)$/', $addfieldentry['type']))
{ {
setEventMessages($langs->trans('BadValueForType', $objectname), null, 'errors'); setEventMessages($langs->trans('BadValueForType', $objectname), null, 'errors');
return -2; return -2;
} }
} }
$pathoffiletoeditsrc=$readdir.'/class/'.strtolower($objectname).'.class.php'; $pathoffiletoeditsrc = $readdir.'/class/'.strtolower($objectname).'.class.php';
$pathoffiletoedittarget=$destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : ''); $pathoffiletoedittarget = $destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : '');
if (! dol_is_file($pathoffiletoeditsrc)) if (!dol_is_file($pathoffiletoeditsrc))
{ {
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
@@ -86,7 +86,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
try try
{ {
include_once $pathoffiletoeditsrc; include_once $pathoffiletoeditsrc;
if (class_exists($objectname)) $object=new $objectname($db); if (class_exists($objectname)) $object = new $objectname($db);
else return -4; else return -4;
// Backup old file // Backup old file
@@ -100,86 +100,86 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
{ {
if (is_array($addfieldentry) && count($addfieldentry)) if (is_array($addfieldentry) && count($addfieldentry))
{ {
$name=$addfieldentry['name']; $name = $addfieldentry['name'];
unset($addfieldentry['name']); unset($addfieldentry['name']);
$object->fields[$name]=$addfieldentry; $object->fields[$name] = $addfieldentry;
} }
if (! empty($delfieldentry)) if (!empty($delfieldentry))
{ {
$name=$delfieldentry; $name = $delfieldentry;
unset($object->fields[$name]); unset($object->fields[$name]);
} }
} }
dol_sort_array($object->fields, 'position'); dol_sort_array($object->fields, 'position');
$i=0; $i = 0;
$texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n"; $texttoinsert = '// BEGIN MODULEBUILDER PROPERTIES'."\n";
$texttoinsert.= "\t".'/**'."\n"; $texttoinsert .= "\t".'/**'."\n";
$texttoinsert.= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n"; $texttoinsert .= "\t".' * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.'."\n";
$texttoinsert.= "\t".' */'."\n"; $texttoinsert .= "\t".' */'."\n";
$texttoinsert.= "\t".'public $fields=array('."\n"; $texttoinsert .= "\t".'public $fields=array('."\n";
if (count($object->fields)) if (count($object->fields))
{ {
foreach($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$i++; $i++;
$texttoinsert.= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',"; $texttoinsert .= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',";
$texttoinsert.= " 'enabled'=>".($val['enabled']!=''?$val['enabled']:1).","; $texttoinsert .= " 'enabled'=>".($val['enabled'] != '' ? $val['enabled'] : 1).",";
$texttoinsert.= " 'position'=>".($val['position']!=''?$val['position']:50).","; $texttoinsert .= " 'position'=>".($val['position'] != '' ? $val['position'] : 50).",";
$texttoinsert.= " 'notnull'=>".(empty($val['notnull'])?0:$val['notnull']).","; $texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : $val['notnull']).",";
$texttoinsert.= " 'visible'=>".($val['visible']!=''?$val['visible']:-1).","; $texttoinsert .= " 'visible'=>".($val['visible'] != '' ? $val['visible'] : -1).",";
if ($val['noteditable']) $texttoinsert.= " 'noteditable'=>'".$val['noteditable']."',"; if ($val['noteditable']) $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',";
if ($val['default']) $texttoinsert.= " 'default'=>'".$val['default']."',"; if ($val['default']) $texttoinsert .= " 'default'=>'".$val['default']."',";
if ($val['index']) $texttoinsert.= " 'index'=>".$val['index'].","; if ($val['index']) $texttoinsert .= " 'index'=>".$val['index'].",";
if ($val['foreignkey']) $texttoinsert.= " 'foreignkey'=>'".$val['foreignkey']."',"; if ($val['foreignkey']) $texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',";
if ($val['searchall']) $texttoinsert.= " 'searchall'=>".$val['searchall'].","; if ($val['searchall']) $texttoinsert .= " 'searchall'=>".$val['searchall'].",";
if ($val['isameasure']) $texttoinsert.= " 'isameasure'=>'".$val['isameasure']."',"; if ($val['isameasure']) $texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',";
if ($val['css']) $texttoinsert.= " 'css'=>'".$val['css']."',"; if ($val['css']) $texttoinsert .= " 'css'=>'".$val['css']."',";
if ($val['help']) $texttoinsert.= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\","; if ($val['help']) $texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\",";
if ($val['showoncombobox']) $texttoinsert.= " 'showoncombobox'=>'".$val['showoncombobox']."',"; if ($val['showoncombobox']) $texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',";
if ($val['disabled']) $texttoinsert.= " 'disabled'=>'".$val['disabled']."',"; if ($val['disabled']) $texttoinsert .= " 'disabled'=>'".$val['disabled']."',";
if ($val['arrayofkeyval']) if ($val['arrayofkeyval'])
{ {
$texttoinsert.= " 'arrayofkeyval'=>array("; $texttoinsert .= " 'arrayofkeyval'=>array(";
$i=0; $i = 0;
foreach($val['arrayofkeyval'] as $key2 => $val2) foreach ($val['arrayofkeyval'] as $key2 => $val2)
{ {
if ($i) $texttoinsert.=", "; if ($i) $texttoinsert .= ", ";
$texttoinsert.="'".$key2."'=>'".$val2."'"; $texttoinsert .= "'".$key2."'=>'".$val2."'";
$i++; $i++;
} }
$texttoinsert.= "),"; $texttoinsert .= "),";
} }
if ($val['comment']) $texttoinsert.= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\""; if ($val['comment']) $texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\"";
$texttoinsert.= "),\n"; $texttoinsert .= "),\n";
} }
} }
$texttoinsert.= "\t".');'."\n"; $texttoinsert .= "\t".');'."\n";
//print ($texttoinsert);exit; //print ($texttoinsert);exit;
if (count($object->fields)) if (count($object->fields))
{ {
//$typetotypephp=array('integer'=>'integer', 'duration'=>'integer', 'varchar'=>'string'); //$typetotypephp=array('integer'=>'integer', 'duration'=>'integer', 'varchar'=>'string');
foreach($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$i++; $i++;
//$typephp=$typetotypephp[$val['type']]; //$typephp=$typetotypephp[$val['type']];
$texttoinsert.= "\t".'public $'.$key.";"; $texttoinsert .= "\t".'public $'.$key.";";
//if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; //if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY';
//if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; //if ($key == 'entity') $texttoinsert.= ' DEFAULT 1';
//$texttoinsert.= ($val['notnull']?' NOT NULL':''); //$texttoinsert.= ($val['notnull']?' NOT NULL':'');
//if ($i < count($object->fields)) $texttoinsert.=";"; //if ($i < count($object->fields)) $texttoinsert.=";";
$texttoinsert.= "\n"; $texttoinsert .= "\n";
} }
} }
$texttoinsert.= "\t".'// END MODULEBUILDER PROPERTIES'; $texttoinsert .= "\t".'// END MODULEBUILDER PROPERTIES';
//print($texttoinsert);exit; //print($texttoinsert);exit;
@@ -193,7 +193,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
return $object; return $object;
} }
catch(Exception $e) catch (Exception $e)
{ {
print $e->getMessage(); print $e->getMessage();
return -5; return -5;
@@ -219,14 +219,14 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
$error = 0; $error = 0;
if (empty($objectname)) return -1; if (empty($objectname)) return -1;
if (empty($readdir)) $readdir=$destdir; if (empty($readdir)) $readdir = $destdir;
$pathoffiletoclasssrc=$readdir.'/class/'.strtolower($objectname).'.class.php'; $pathoffiletoclasssrc = $readdir.'/class/'.strtolower($objectname).'.class.php';
// Edit .sql file // Edit .sql file
$pathoffiletoeditsrc=$readdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'; $pathoffiletoeditsrc = $readdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql';
$pathoffiletoedittarget=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : ''); $pathoffiletoedittarget = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql'.($readdir != $destdir ? '.new' : '');
if (! dol_is_file($pathoffiletoeditsrc)) if (!dol_is_file($pathoffiletoeditsrc))
{ {
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors'); setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
@@ -236,14 +236,14 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
// Load object from myobject.class.php // Load object from myobject.class.php
try try
{ {
if (! is_object($object)) if (!is_object($object))
{ {
include_once $pathoffiletoclasssrc; include_once $pathoffiletoclasssrc;
if (class_exists($objectname)) $object=new $objectname($db); if (class_exists($objectname)) $object = new $objectname($db);
else return -1; else return -1;
} }
} }
catch(Exception $e) catch (Exception $e)
{ {
print $e->getMessage(); print $e->getMessage();
} }
@@ -253,38 +253,38 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
$contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); $contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
$i=0; $i = 0;
$texttoinsert = '-- BEGIN MODULEBUILDER FIELDS'."\n"; $texttoinsert = '-- BEGIN MODULEBUILDER FIELDS'."\n";
if (count($object->fields)) if (count($object->fields))
{ {
foreach($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$i++; $i++;
$type = $val['type']; $type = $val['type'];
$type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php' $type = preg_replace('/:.*$/', '', $type); // For case type = 'integer:Societe:societe/class/societe.class.php'
if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database if ($type == 'html') $type = 'text'; // html modulebuilder type is a text type in database
elseif ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database elseif ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database
elseif (in_array($type, array('link', 'sellist', 'duration'))) $type = 'integer'; elseif (in_array($type, array('link', 'sellist', 'duration'))) $type = 'integer';
$texttoinsert.= "\t".$key." ".$type; $texttoinsert .= "\t".$key." ".$type;
if ($key == 'rowid') $texttoinsert.= ' AUTO_INCREMENT PRIMARY KEY'; if ($key == 'rowid') $texttoinsert .= ' AUTO_INCREMENT PRIMARY KEY';
if ($key == 'entity') $texttoinsert.= ' DEFAULT 1'; if ($key == 'entity') $texttoinsert .= ' DEFAULT 1';
else else
{ {
if ($val['default'] != '') if ($val['default'] != '')
{ {
if (preg_match('/^null$/i', $val['default'])) $texttoinsert.= " DEFAULT NULL"; if (preg_match('/^null$/i', $val['default'])) $texttoinsert .= " DEFAULT NULL";
elseif (preg_match('/varchar/', $type)) $texttoinsert.= " DEFAULT '".$db->escape($val['default'])."'"; elseif (preg_match('/varchar/', $type)) $texttoinsert .= " DEFAULT '".$db->escape($val['default'])."'";
else $texttoinsert.= (($val['default'] > 0)?' DEFAULT '.$val['default']:''); else $texttoinsert .= (($val['default'] > 0) ? ' DEFAULT '.$val['default'] : '');
} }
} }
$texttoinsert.= (($val['notnull'] > 0)?' NOT NULL':''); $texttoinsert .= (($val['notnull'] > 0) ? ' NOT NULL' : '');
if ($i < count($object->fields)) $texttoinsert.=", "; if ($i < count($object->fields)) $texttoinsert .= ", ";
$texttoinsert.= "\n"; $texttoinsert .= "\n";
} }
} }
$texttoinsert.= "\t".'-- END MODULEBUILDER FIELDS'; $texttoinsert .= "\t".'-- END MODULEBUILDER FIELDS';
$contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql); $contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql);
@@ -299,35 +299,35 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
} }
// Edit .key.sql file // Edit .key.sql file
$pathoffiletoeditsrc=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'; $pathoffiletoeditsrc = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql';
$pathoffiletoedittarget=$destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'.($readdir != $destdir ? '.new' : ''); $pathoffiletoedittarget = $destdir.'/sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql'.($readdir != $destdir ? '.new' : '');
$contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r'); $contentsql = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
$i=0; $i = 0;
$texttoinsert = '-- BEGIN MODULEBUILDER INDEXES'."\n"; $texttoinsert = '-- BEGIN MODULEBUILDER INDEXES'."\n";
if (count($object->fields)) if (count($object->fields))
{ {
foreach($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$i++; $i++;
if (! empty($val['index'])) if (!empty($val['index']))
{ {
$texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD INDEX idx_".strtolower($module).'_'.strtolower($objectname)."_".$key." (".$key.");"; $texttoinsert .= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD INDEX idx_".strtolower($module).'_'.strtolower($objectname)."_".$key." (".$key.");";
$texttoinsert.= "\n"; $texttoinsert .= "\n";
} }
if (! empty($val['foreignkey'])) if (!empty($val['foreignkey']))
{ {
$tmp=explode('.', $val['foreignkey']); $tmp = explode('.', $val['foreignkey']);
if (! empty($tmp[0]) && ! empty($tmp[1])) if (!empty($tmp[0]) && !empty($tmp[1]))
{ {
$texttoinsert.= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");"; $texttoinsert .= "ALTER TABLE llx_".strtolower($module).'_'.strtolower($objectname)." ADD CONSTRAINT llx_".strtolower($module).'_'.strtolower($objectname)."_".$key." FOREIGN KEY (".$key.") REFERENCES ".$tmp[0]."(".$tmp[1].");";
$texttoinsert.= "\n"; $texttoinsert .= "\n";
} }
} }
} }
} }
$texttoinsert.= '-- END MODULEBUILDER INDEXES'; $texttoinsert .= '-- END MODULEBUILDER INDEXES';
$contentsql = preg_replace('/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql); $contentsql = preg_replace('/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsql);