Fix bug reported by scrutinizer

This commit is contained in:
Laurent Destailleur 2017-11-05 03:39:27 +01:00
parent 91950ccbc7
commit c78c06776b
6 changed files with 146 additions and 134 deletions

View File

@ -5340,8 +5340,9 @@ abstract class CommonObject
}
}
if ($key == 'ref') $value=$this->getNomUrl(1, '', 0, '', 1);
elseif ($key == 'status') $value=$this->getLibStatut(3);
// Format output value differently according to properties of field
if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1);
elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3);
elseif ($type == 'date')
{
$value=dol_print_date($value,'day');
@ -5382,11 +5383,11 @@ abstract class CommonObject
}
elseif ($type == 'select')
{
$value=$params['options'][$value];
$value=$param['options'][$value];
}
elseif ($type == 'sellist')
{
$param_list=array_keys($params['options']);
$param_list=array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
$selectkey="rowid";
@ -5463,7 +5464,7 @@ abstract class CommonObject
}
elseif ($type == 'radio')
{
$value=$params['options'][$value];
$value=$param['options'][$value];
}
elseif ($type == 'checkbox')
{
@ -5472,7 +5473,7 @@ abstract class CommonObject
if (is_array($value_arr))
{
foreach ($value_arr as $keyval=>$valueval) {
$toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$params['options'][$valueval].'</li>';
$toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>';
}
}
$value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
@ -5481,7 +5482,7 @@ abstract class CommonObject
{
$value_arr = explode(',', $value);
$param_list = array_keys($params['options']);
$param_list = array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
$selectkey = "rowid";
@ -6262,8 +6263,11 @@ abstract class CommonObject
unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update.
$keys=array();
$values = array();
foreach ($fieldvalues as $k => $v) {
$keys[$k] = $k;
$value = $this->fields[$k];
$values[$k] = $this->quote($v, $value);
$tmp[] = $k.'='.$this->quote($v, $this->fields[$k]);
}

View File

@ -975,6 +975,7 @@ class ExtraFields
$param_list=array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
$parentName='';
$parentField='';
// 0 : tableName
// 1 : label field name
// 2 : key fields name (if differ of rowid)
@ -1106,7 +1107,7 @@ class ExtraFields
$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
}
if (!empty($InfoFieldList[3]))
if (!empty($InfoFieldList[3]) && $parentField)
{
$parent = $parentName.':'.$obj->{$parentField};
}
@ -1156,6 +1157,8 @@ class ExtraFields
if (is_array($param['options'])) {
$param_list = array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
$parentName='';
$parentField='';
// 0 : tableName
// 1 : label field name
// 2 : key fields name (if differ of rowid)
@ -1229,6 +1232,7 @@ class ExtraFields
$labeltoshow = '';
$obj = $this->db->fetch_object($resql);
$notrans = false;
// Several field into label (eq table:code|libelle:rowid)
$fields_label = explode('|', $InfoFieldList[1]);
if (is_array($fields_label)) {
@ -1269,7 +1273,7 @@ class ExtraFields
$data[$obj->rowid]=$labeltoshow;
}
if (! empty($InfoFieldList[3])) {
if (! empty($InfoFieldList[3]) && $parentField) {
$parent = $parentName . ':' . $obj->{$parentField};
}
@ -1286,12 +1290,11 @@ class ExtraFields
print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
}
}
$out .= '</select>';
}
elseif ($type == 'link')
{
$param_list=array_keys($param['options']); // $param_list='ObjectName:classPath'
$showempty=(($val['notnull'] == 1 && $val['default'] != '')?0:1);
$showempty=(($required && $default != '')?0:1);
$out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty);
}
elseif ($type == 'password')
@ -1480,6 +1483,7 @@ class ExtraFields
{
$value_arr=explode(',',$value);
$value='';
$toprint=array();
if (is_array($value_arr))
{
foreach ($value_arr as $keyval=>$valueval) {

View File

@ -192,127 +192,6 @@ function dolIncludeHtmlContent($contentfile)
$includehtmlcontentopened--;
}
/**
* Generate a zip with all data of web site.
*
* @param Website $website Object website
* @return string Path to file with zip
*/
function exportWebSite($website)
{
global $db, $conf;
dol_mkdir($conf->website->dir_temp);
$srcdir = $conf->website->dir_output.'/'.$website->ref;
$destdir = $conf->website->dir_temp.'/'.$website->ref;
$arrayreplacement=array();
dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacement);
$srcdir = DOL_DATA_ROOT.'/medias/images/'.$website->ref;
$destdir = $conf->website->dir_temp.'/'.$website->ref.'/medias/images/'.$website->ref;
dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacement);
// Build sql file
dol_mkdir($conf->website->dir_temp.'/'.$website->ref.'/export');
$filesql = $conf->website->dir_temp.'/'.$website->ref.'/export/pages.sql';
$fp = fopen($filesql,"w");
$objectpages = new WebsitePage($db);
$listofpages = $objectpages->fetchAll($website->id);
// Assign ->newid and ->newfk_page
$i=1;
foreach($listofpages as $pageid => $objectpageold)
{
$objectpageold->newid=$i;
$i++;
}
$i=1;
foreach($listofpages as $pageid => $objectpageold)
{
// Search newid
$newfk_page=0;
foreach($listofpages as $pageid2 => $objectpageold2)
{
if ($pageid2 == $objectpageold->fk_page)
{
$newfk_page = $objectpageold2->newid;
break;
}
}
$objectpageold->newfk_page=$newfk_page;
$i++;
}
foreach($listofpages as $pageid => $objectpageold)
{
$line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, title, description, keyword, status, date_creation, tms, lang, import_key, grabbed_from, content)';
$line.= " VALUES(";
$line.= $objectpageold->newid."+__MAXROWID__, ";
$line.= ($objectpageold->newfk_page ? $db->escape($objectpageold->newfk_page)."+__MAXROWID__" : "null").", ";
$line.= "__WEBSITE_ID__, ";
$line.= "'".$db->escape($objectpageold->pageurl)."', ";
$line.= "'".$db->escape($objectpageold->title)."', ";
$line.= "'".$db->escape($objectpageold->description)."', ";
$line.= "'".$db->escape($objectpageold->keyword)."', ";
$line.= "'".$db->escape($objectpageold->status)."', ";
$line.= "'".$db->idate($objectpageold->date_creation)."', ";
$line.= "'".$db->idate($objectpageold->date_modification)."', ";
$line.= "'".$db->escape($objectpageold->lang)."', ";
$line.= ($objectpageold->import_key ? "'".$db->escape($objectpageold->import_key)."'" : "null").", ";
$line.= "'".$db->escape($objectpageold->grabbed_from)."', ";
$line.= "'".$db->escape($objectpageold->content)."'";
$line.= ");";
$line.= "\n";
fputs($fp, $line);
}
fclose($fp);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filesql, octdec($conf->global->MAIN_UMASK));
// Build zip file
$filedir = $conf->website->dir_temp.'/'.$website->ref;
$fileglob = $conf->website->dir_temp.'/'.$website->ref.'/export/website_'.$website->ref.'-*.zip';
$filename = $conf->website->dir_temp.'/'.$website->ref.'/export/website_'.$website->ref.'-'.dol_print_date(dol_now(),'dayhourlog').'.zip';
dol_delete_file($fileglob, 0);
dol_compress_file($filedir, $filename, 'zip');
return $filename;
}
/**
* Open a zip with all data of web site and load it into database.
*
* @param string $pathtofile Path of zip file
* @return int <0 if KO, >0 if OK
*/
function importWebSite($pathtofile)
{
global $db;
$result = 0;
$filename = basename($pathtofile);
if (! preg_match('/^website_(.*)-(.*)$/', $filename, $reg))
{
$this->errors[]='Bad format for filename '.$filename.'. Must be website_XXX-VERSION.';
return -1;
}
$websitecode = $reg[1];
$sql = "INSERT INTO ".MAIN_DB_PREFIX."website(ref, entity, description, status) values('".$websitecode."', ".$conf->entity.", 'Portal to sell your SaaS. Do not remove this entry.', 1)";
$resql = $db->query($sql);
return $result;
}
/**

View File

@ -1118,7 +1118,6 @@ class Cronjob extends CommonObject
$this->lastoutput = ''; // Will be filled later from $output_arr
$this->lastresult = $retval;
$retval = $this->lastresult;
$error++;
}
}
if ($execmethod == 2) // With this method, there is no way to get the return code, only output

View File

@ -758,5 +758,131 @@ class Website extends CommonObject
}
/**
* Generate a zip with all data of web site.
*
* @return string Path to file with zip
*/
function exportWebSite()
{
global $conf;
$website = $this;
dol_mkdir($conf->website->dir_temp);
$srcdir = $conf->website->dir_output.'/'.$website->ref;
$destdir = $conf->website->dir_temp.'/'.$website->ref;
$arrayreplacement=array();
dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacement);
$srcdir = DOL_DATA_ROOT.'/medias/images/'.$website->ref;
$destdir = $conf->website->dir_temp.'/'.$website->ref.'/medias/images/'.$website->ref;
dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacement);
// Build sql file
dol_mkdir($conf->website->dir_temp.'/'.$website->ref.'/export');
$filesql = $conf->website->dir_temp.'/'.$website->ref.'/export/pages.sql';
$fp = fopen($filesql,"w");
$objectpages = new WebsitePage($this->db);
$listofpages = $objectpages->fetchAll($website->id);
// Assign ->newid and ->newfk_page
$i=1;
foreach($listofpages as $pageid => $objectpageold)
{
$objectpageold->newid=$i;
$i++;
}
$i=1;
foreach($listofpages as $pageid => $objectpageold)
{
// Search newid
$newfk_page=0;
foreach($listofpages as $pageid2 => $objectpageold2)
{
if ($pageid2 == $objectpageold->fk_page)
{
$newfk_page = $objectpageold2->newid;
break;
}
}
$objectpageold->newfk_page=$newfk_page;
$i++;
}
foreach($listofpages as $pageid => $objectpageold)
{
$line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, title, description, keyword, status, date_creation, tms, lang, import_key, grabbed_from, content)';
$line.= " VALUES(";
$line.= $objectpageold->newid."+__MAXROWID__, ";
$line.= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page)."+__MAXROWID__" : "null").", ";
$line.= "__WEBSITE_ID__, ";
$line.= "'".$this->db->escape($objectpageold->pageurl)."', ";
$line.= "'".$this->db->escape($objectpageold->title)."', ";
$line.= "'".$this->db->escape($objectpageold->description)."', ";
$line.= "'".$this->db->escape($objectpageold->keyword)."', ";
$line.= "'".$this->db->escape($objectpageold->status)."', ";
$line.= "'".$this->db->idate($objectpageold->date_creation)."', ";
$line.= "'".$this->db->idate($objectpageold->date_modification)."', ";
$line.= "'".$this->db->escape($objectpageold->lang)."', ";
$line.= ($objectpageold->import_key ? "'".$this->db->escape($objectpageold->import_key)."'" : "null").", ";
$line.= "'".$this->db->escape($objectpageold->grabbed_from)."', ";
$line.= "'".$this->db->escape($objectpageold->content)."'";
$line.= ");";
$line.= "\n";
fputs($fp, $line);
}
fclose($fp);
if (! empty($conf->global->MAIN_UMASK))
@chmod($filesql, octdec($conf->global->MAIN_UMASK));
// Build zip file
$filedir = $conf->website->dir_temp.'/'.$website->ref;
$fileglob = $conf->website->dir_temp.'/'.$website->ref.'/export/website_'.$website->ref.'-*.zip';
$filename = $conf->website->dir_temp.'/'.$website->ref.'/export/website_'.$website->ref.'-'.dol_print_date(dol_now(),'dayhourlog').'.zip';
dol_delete_file($fileglob, 0);
dol_compress_file($filedir, $filename, 'zip');
return $filename;
}
/**
* Open a zip with all data of web site and load it into database.
*
* @param string $pathtofile Path of zip file
* @return int <0 if KO, Id of new website if OK
*/
function importWebSite($pathtofile)
{
global $conf;
$result = 0;
$object = new Website($this->db);
$filename = basename($pathtofile);
if (! preg_match('/^website_(.*)-(.*)$/', $filename, $reg))
{
$this->errors[]='Bad format for filename '.$filename.'. Must be website_XXX-VERSION.';
return -1;
}
$websitecode = $reg[1];
$sql = "INSERT INTO ".MAIN_DB_PREFIX."website(ref, entity, description, status) values('".$websitecode."', ".$conf->entity.", 'Portal to sell your SaaS. Do not remove this entry.', 1)";
$resql = $this->db->query($sql);
return $result;
}
}

View File

@ -1062,7 +1062,7 @@ if (($action == 'updatesource' || $action == 'updatecontent' || $action == 'conf
// Export site
if (GETPOST('exportsite'))
{
$fileofzip = exportWebSite($object);
$fileofzip = $object->exportWebSite();
$file_name = basename($fileofzip);