forked from Wavyzz/dolibarr
code syntax core directory
This commit is contained in:
@@ -41,31 +41,30 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
{
|
||||
global $db, $langs;
|
||||
|
||||
if (empty($objectname)) return -1;
|
||||
if (empty($readdir)) $readdir = $destdir;
|
||||
if (empty($objectname)) {
|
||||
return -1;
|
||||
}
|
||||
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.');
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (count($addfieldentry) > 0)
|
||||
{
|
||||
if (empty($addfieldentry['name']))
|
||||
{
|
||||
if (count($addfieldentry) > 0) {
|
||||
if (empty($addfieldentry['name'])) {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors');
|
||||
return -2;
|
||||
}
|
||||
if (empty($addfieldentry['label']))
|
||||
{
|
||||
if (empty($addfieldentry['label'])) {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors');
|
||||
return -2;
|
||||
}
|
||||
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');
|
||||
return -2;
|
||||
}
|
||||
@@ -73,8 +72,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
|
||||
$pathoffiletoeditsrc = $readdir.'/class/'.strtolower($objectname).'.class.php';
|
||||
$pathoffiletoedittarget = $destdir.'/class/'.strtolower($objectname).'.class.php'.($readdir != $destdir ? '.new' : '');
|
||||
if (!dol_is_file($pathoffiletoeditsrc))
|
||||
{
|
||||
if (!dol_is_file($pathoffiletoeditsrc)) {
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
|
||||
return -3;
|
||||
@@ -85,8 +83,11 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
|
||||
try {
|
||||
include_once $pathoffiletoeditsrc;
|
||||
if (class_exists($objectname)) $object = new $objectname($db);
|
||||
else return -4;
|
||||
if (class_exists($objectname)) {
|
||||
$object = new $objectname($db);
|
||||
} else {
|
||||
return -4;
|
||||
}
|
||||
|
||||
// Backup old file
|
||||
dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1);
|
||||
@@ -95,17 +96,14 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
$contentclass = file_get_contents(dol_osencode($pathoffiletoeditsrc), 'r');
|
||||
|
||||
// Update ->fields (add or remove entries)
|
||||
if (count($object->fields))
|
||||
{
|
||||
if (is_array($addfieldentry) && count($addfieldentry))
|
||||
{
|
||||
if (count($object->fields)) {
|
||||
if (is_array($addfieldentry) && count($addfieldentry)) {
|
||||
$name = $addfieldentry['name'];
|
||||
unset($addfieldentry['name']);
|
||||
|
||||
$object->fields[$name] = $addfieldentry;
|
||||
}
|
||||
if (!empty($delfieldentry))
|
||||
{
|
||||
if (!empty($delfieldentry)) {
|
||||
$name = $delfieldentry;
|
||||
unset($object->fields[$name]);
|
||||
}
|
||||
@@ -120,40 +118,62 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
$texttoinsert .= "\t".' */'."\n";
|
||||
$texttoinsert .= "\t".'public $fields=array('."\n";
|
||||
|
||||
if (count($object->fields))
|
||||
{
|
||||
foreach ($object->fields as $key => $val)
|
||||
{
|
||||
if (count($object->fields)) {
|
||||
foreach ($object->fields as $key => $val) {
|
||||
$i++;
|
||||
$texttoinsert .= "\t\t'".$key."' => array('type'=>'".$val['type']."', 'label'=>'".$val['label']."',";
|
||||
$texttoinsert .= " 'enabled'=>'".($val['enabled'] !== '' ? $val['enabled'] : 1)."',";
|
||||
$texttoinsert .= " 'position'=>".($val['position'] !== '' ? $val['position'] : 50).",";
|
||||
$texttoinsert .= " 'notnull'=>".(empty($val['notnull']) ? 0 : $val['notnull']).",";
|
||||
$texttoinsert .= " 'visible'=>".($val['visible'] !== '' ? $val['visible'] : -1).",";
|
||||
if ($val['noteditable']) $texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',";
|
||||
if ($val['default'] || $val['default'] === '0') $texttoinsert .= " 'default'=>'".$val['default']."',";
|
||||
if ($val['index']) $texttoinsert .= " 'index'=>".$val['index'].",";
|
||||
if ($val['foreignkey']) $texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',";
|
||||
if ($val['searchall']) $texttoinsert .= " 'searchall'=>".$val['searchall'].",";
|
||||
if ($val['isameasure']) $texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',";
|
||||
if ($val['css']) $texttoinsert .= " 'css'=>'".$val['css']."',";
|
||||
if ($val['help']) $texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\",";
|
||||
if ($val['showoncombobox']) $texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',";
|
||||
if ($val['disabled']) $texttoinsert .= " 'disabled'=>'".$val['disabled']."',";
|
||||
if ($val['autofocusoncreate']) $texttoinsert .= " 'autofocusoncreate'=>'".$val['autofocusoncreate']."',";
|
||||
if ($val['arrayofkeyval'])
|
||||
{
|
||||
if ($val['noteditable']) {
|
||||
$texttoinsert .= " 'noteditable'=>'".$val['noteditable']."',";
|
||||
}
|
||||
if ($val['default'] || $val['default'] === '0') {
|
||||
$texttoinsert .= " 'default'=>'".$val['default']."',";
|
||||
}
|
||||
if ($val['index']) {
|
||||
$texttoinsert .= " 'index'=>".$val['index'].",";
|
||||
}
|
||||
if ($val['foreignkey']) {
|
||||
$texttoinsert .= " 'foreignkey'=>'".$val['foreignkey']."',";
|
||||
}
|
||||
if ($val['searchall']) {
|
||||
$texttoinsert .= " 'searchall'=>".$val['searchall'].",";
|
||||
}
|
||||
if ($val['isameasure']) {
|
||||
$texttoinsert .= " 'isameasure'=>'".$val['isameasure']."',";
|
||||
}
|
||||
if ($val['css']) {
|
||||
$texttoinsert .= " 'css'=>'".$val['css']."',";
|
||||
}
|
||||
if ($val['help']) {
|
||||
$texttoinsert .= " 'help'=>\"".preg_replace('/"/', '', $val['help'])."\",";
|
||||
}
|
||||
if ($val['showoncombobox']) {
|
||||
$texttoinsert .= " 'showoncombobox'=>'".$val['showoncombobox']."',";
|
||||
}
|
||||
if ($val['disabled']) {
|
||||
$texttoinsert .= " 'disabled'=>'".$val['disabled']."',";
|
||||
}
|
||||
if ($val['autofocusoncreate']) {
|
||||
$texttoinsert .= " 'autofocusoncreate'=>'".$val['autofocusoncreate']."',";
|
||||
}
|
||||
if ($val['arrayofkeyval']) {
|
||||
$texttoinsert .= " 'arrayofkeyval'=>array(";
|
||||
$i = 0;
|
||||
foreach ($val['arrayofkeyval'] as $key2 => $val2)
|
||||
{
|
||||
if ($i) $texttoinsert .= ", ";
|
||||
foreach ($val['arrayofkeyval'] as $key2 => $val2) {
|
||||
if ($i) {
|
||||
$texttoinsert .= ", ";
|
||||
}
|
||||
$texttoinsert .= "'".$key2."'=>'".$val2."'";
|
||||
$i++;
|
||||
}
|
||||
$texttoinsert .= "),";
|
||||
}
|
||||
if ($val['comment']) $texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\"";
|
||||
if ($val['comment']) {
|
||||
$texttoinsert .= " 'comment'=>\"".preg_replace('/"/', '', $val['comment'])."\"";
|
||||
}
|
||||
|
||||
$texttoinsert .= "),\n";
|
||||
}
|
||||
@@ -162,12 +182,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
$texttoinsert .= "\t".');'."\n";
|
||||
//print ($texttoinsert);exit;
|
||||
|
||||
if (count($object->fields))
|
||||
{
|
||||
if (count($object->fields)) {
|
||||
//$typetotypephp=array('integer'=>'integer', 'duration'=>'integer', 'varchar'=>'string');
|
||||
|
||||
foreach ($object->fields as $key => $val)
|
||||
{
|
||||
foreach ($object->fields as $key => $val) {
|
||||
$i++;
|
||||
//$typephp=$typetotypephp[$val['type']];
|
||||
$texttoinsert .= "\t".'public $'.$key.";";
|
||||
@@ -192,8 +210,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir =
|
||||
@chmod($pathoffiletoedittarget, octdec($newmask));
|
||||
|
||||
return $object;
|
||||
} catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage();
|
||||
return -5;
|
||||
}
|
||||
@@ -218,8 +235,12 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
|
||||
$error = 0;
|
||||
|
||||
if (empty($objectname)) return -1;
|
||||
if (empty($readdir)) $readdir = $destdir;
|
||||
if (empty($objectname)) {
|
||||
return -1;
|
||||
}
|
||||
if (empty($readdir)) {
|
||||
$readdir = $destdir;
|
||||
}
|
||||
|
||||
$pathoffiletoclasssrc = $readdir.'/class/'.strtolower($objectname).'.class.php';
|
||||
|
||||
@@ -232,8 +253,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
$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");
|
||||
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
|
||||
return -1;
|
||||
@@ -241,14 +261,15 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
|
||||
// Load object from myobject.class.php
|
||||
try {
|
||||
if (!is_object($object))
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
include_once $pathoffiletoclasssrc;
|
||||
if (class_exists($objectname)) $object = new $objectname($db);
|
||||
else return -1;
|
||||
if (class_exists($objectname)) {
|
||||
$object = new $objectname($db);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
print $e->getMessage();
|
||||
}
|
||||
|
||||
@@ -259,31 +280,41 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
|
||||
$i = 0;
|
||||
$texttoinsert = '-- BEGIN MODULEBUILDER FIELDS'."\n";
|
||||
if (count($object->fields))
|
||||
{
|
||||
foreach ($object->fields as $key => $val)
|
||||
{
|
||||
if (count($object->fields)) {
|
||||
foreach ($object->fields as $key => $val) {
|
||||
$i++;
|
||||
|
||||
$type = $val['type'];
|
||||
$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
|
||||
elseif ($type == 'price') $type = 'double'; // html modulebuilder type is a text type in database
|
||||
elseif (in_array($type, array('link', 'sellist', 'duration'))) $type = 'integer';
|
||||
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 (in_array($type, array('link', 'sellist', 'duration'))) {
|
||||
$type = 'integer';
|
||||
}
|
||||
$texttoinsert .= "\t".$key." ".$type;
|
||||
if ($key == 'rowid') $texttoinsert .= ' AUTO_INCREMENT PRIMARY KEY';
|
||||
if ($key == 'entity') $texttoinsert .= ' DEFAULT 1';
|
||||
else {
|
||||
if ($val['default'] != '')
|
||||
{
|
||||
if (preg_match('/^null$/i', $val['default'])) $texttoinsert .= " DEFAULT NULL";
|
||||
elseif (preg_match('/varchar/', $type)) $texttoinsert .= " DEFAULT '".$db->escape($val['default'])."'";
|
||||
else $texttoinsert .= (($val['default'] > 0) ? ' DEFAULT '.$val['default'] : '');
|
||||
if ($key == 'rowid') {
|
||||
$texttoinsert .= ' AUTO_INCREMENT PRIMARY KEY';
|
||||
}
|
||||
if ($key == 'entity') {
|
||||
$texttoinsert .= ' DEFAULT 1';
|
||||
} else {
|
||||
if ($val['default'] != '') {
|
||||
if (preg_match('/^null$/i', $val['default'])) {
|
||||
$texttoinsert .= " DEFAULT NULL";
|
||||
} elseif (preg_match('/varchar/', $type)) {
|
||||
$texttoinsert .= " DEFAULT '".$db->escape($val['default'])."'";
|
||||
} else {
|
||||
$texttoinsert .= (($val['default'] > 0) ? ' DEFAULT '.$val['default'] : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
$texttoinsert .= (($val['notnull'] > 0) ? ' NOT NULL' : '');
|
||||
if ($i < count($object->fields)) $texttoinsert .= ", ";
|
||||
if ($i < count($object->fields)) {
|
||||
$texttoinsert .= ", ";
|
||||
}
|
||||
$texttoinsert .= "\n";
|
||||
}
|
||||
}
|
||||
@@ -292,8 +323,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
$contentsql = preg_replace('/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsql);
|
||||
|
||||
$result = file_put_contents($pathoffiletoedittarget, $contentsql);
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
@chmod($pathoffiletoedittarget, octdec($newmask));
|
||||
} else {
|
||||
$error++;
|
||||
@@ -312,21 +342,16 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
|
||||
$i = 0;
|
||||
$texttoinsert = '-- BEGIN MODULEBUILDER INDEXES'."\n";
|
||||
if (count($object->fields))
|
||||
{
|
||||
foreach ($object->fields as $key => $val)
|
||||
{
|
||||
if (count($object->fields)) {
|
||||
foreach ($object->fields as $key => $val) {
|
||||
$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 .= "\n";
|
||||
}
|
||||
if (!empty($val['foreignkey']))
|
||||
{
|
||||
if (!empty($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 llx_".preg_replace('/^llx_/', '', $tmp[0])."(".$tmp[1].");";
|
||||
$texttoinsert .= "\n";
|
||||
}
|
||||
@@ -340,8 +365,7 @@ function rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir = '
|
||||
dol_mkdir(dirname($pathoffiletoedittarget));
|
||||
|
||||
$result2 = file_put_contents($pathoffiletoedittarget, $contentsql);
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
@chmod($pathoffiletoedittarget, octdec($newmask));
|
||||
} else {
|
||||
$error++;
|
||||
|
||||
Reference in New Issue
Block a user