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-22 14:13:30 +00:00
parent 31956d8912
commit 1eab97080c
6 changed files with 243 additions and 243 deletions

View File

@@ -79,7 +79,7 @@ class Documents extends DolibarrApi
}
//--- Finds and returns the document
$entity=$conf->entity;
$entity = $conf->entity;
$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, DolibarrApiAccess::$user, '', 'read');
$accessallowed = $check_access['accessallowed'];
@@ -94,16 +94,16 @@ class Documents extends DolibarrApi
}
$filename = basename($original_file);
$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset
$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
if (! file_exists($original_file_osencoded))
if (!file_exists($original_file_osencoded))
{
dol_syslog("Try to download not found file ".$original_file_osencoded, LOG_WARNING);
throw new RestException(404, 'File not found');
}
$file_content=file_get_contents($original_file_osencoded);
return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' );
$file_content = file_get_contents($original_file_osencoded);
return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64');
}
@@ -141,12 +141,12 @@ class Documents extends DolibarrApi
$outputlangs = $langs;
if ($langcode && $langs->defaultlang != $langcode)
{
$outputlangs=new Translate('', $conf);
$outputlangs = new Translate('', $conf);
$outputlangs->setDefaultLang($langcode);
}
//--- Finds and returns the document
$entity=$conf->entity;
$entity = $conf->entity;
$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, DolibarrApiAccess::$user, '', 'write');
$accessallowed = $check_access['accessallowed'];
@@ -165,20 +165,20 @@ class Documents extends DolibarrApi
$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
$templateused='';
$templateused = '';
if ($modulepart == 'facture' || $modulepart == 'invoice')
{
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$this->invoice = new Facture($this->db);
$result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
if( ! $result ) {
if (!$result) {
throw new RestException(404, 'Invoice not found');
}
$templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf;
$templateused = $doctemplate ? $doctemplate : $this->invoice->modelpdf;
$result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
if( $result <= 0 ) {
if ($result <= 0) {
throw new RestException(500, 'Error generating document');
}
}
@@ -187,12 +187,12 @@ class Documents extends DolibarrApi
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$this->order = new Commande($this->db);
$result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
if( ! $result ) {
if (!$result) {
throw new RestException(404, 'Order not found');
}
$templateused = $doctemplate?$doctemplate:$this->order->modelpdf;
$templateused = $doctemplate ? $doctemplate : $this->order->modelpdf;
$result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
if( $result <= 0 ) {
if ($result <= 0) {
throw new RestException(500, 'Error generating document');
}
}
@@ -201,12 +201,12 @@ class Documents extends DolibarrApi
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
$this->propal = new Propal($this->db);
$result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
if( ! $result ) {
if (!$result) {
throw new RestException(404, 'Proposal not found');
}
$templateused = $doctemplate?$doctemplate:$this->propal->modelpdf;
$templateused = $doctemplate ? $doctemplate : $this->propal->modelpdf;
$result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
if( $result <= 0 ) {
if ($result <= 0) {
throw new RestException(500, 'Error generating document');
}
}
@@ -216,15 +216,15 @@ class Documents extends DolibarrApi
}
$filename = basename($original_file);
$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset
$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
if (! file_exists($original_file_osencoded))
if (!file_exists($original_file_osencoded))
{
throw new RestException(404, 'File not found');
}
$file_content=file_get_contents($original_file_osencoded);
return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' );
$file_content = file_get_contents($original_file_osencoded);
return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64');
}
/**
@@ -257,7 +257,7 @@ class Documents extends DolibarrApi
throw new RestException(400, 'bad value for parameter id or ref');
}
$id = (empty($id)?0:$id);
$id = (empty($id) ? 0 : $id);
if ($modulepart == 'societe' || $modulepart == 'thirdparty')
{
@@ -268,12 +268,12 @@ class Documents extends DolibarrApi
}
$object = new Societe($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Thirdparty not found');
}
$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id;
$upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
}
elseif ($modulepart == 'adherent' || $modulepart == 'member')
{
@@ -284,12 +284,12 @@ class Documents extends DolibarrApi
}
$object = new Adherent($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Member not found');
}
$upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member');
$upload_dir = $conf->adherent->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'member');
}
elseif ($modulepart == 'propal' || $modulepart == 'proposal')
{
@@ -300,12 +300,12 @@ class Documents extends DolibarrApi
}
$object = new Propal($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Proposal not found');
}
$upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal');
$upload_dir = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
}
elseif ($modulepart == 'commande' || $modulepart == 'order')
{
@@ -316,12 +316,12 @@ class Documents extends DolibarrApi
}
$object = new Commande($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Order not found');
}
$upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande');
$upload_dir = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
}
elseif ($modulepart == 'shipment' || $modulepart == 'expedition')
{
@@ -332,12 +332,12 @@ class Documents extends DolibarrApi
}
$object = new Expedition($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Shipment not found');
}
$upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment');
$upload_dir = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
}
elseif ($modulepart == 'facture' || $modulepart == 'invoice')
{
@@ -348,12 +348,12 @@ class Documents extends DolibarrApi
}
$object = new Facture($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Invoice not found');
}
$upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice');
$upload_dir = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
}
elseif ($modulepart == 'produit' || $modulepart == 'product')
{
@@ -364,8 +364,8 @@ class Documents extends DolibarrApi
}
$object = new Product($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Product not found');
}
@@ -380,8 +380,8 @@ class Documents extends DolibarrApi
}
$object = new ActionComm($this->db);
$result=$object->fetch($id, $ref);
if ( ! $result ) {
$result = $object->fetch($id, $ref);
if (!$result) {
throw new RestException(404, 'Event not found');
}
@@ -392,9 +392,9 @@ class Documents extends DolibarrApi
throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
}
$filearray=dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC), 1);
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
if (empty($filearray)) {
throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.');
throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(!empty($object->Ref) ? ' or Ref '.$object->ref : '').' does not return any document.');
}
return $filearray;
@@ -447,7 +447,7 @@ class Documents extends DolibarrApi
var_dump($filecontent);
exit;*/
if(empty($modulepart))
if (empty($modulepart))
{
throw new RestException(400, 'Modulepart not provided.');
}
@@ -467,11 +467,11 @@ class Documents extends DolibarrApi
$entity = DolibarrApiAccess::$user->entity;
if ($ref)
{
$tmpreldir='';
$tmpreldir = '';
if ($modulepart == 'facture' || $modulepart == 'invoice')
{
$modulepart='facture';
$modulepart = 'facture';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$object = new Facture($this->db);
@@ -491,11 +491,11 @@ class Documents extends DolibarrApi
$task_result = $object->fetch('', $ref);
// Fetching the tasks project is required because its out_dir might be a sub-directory of the project
if($task_result > 0)
if ($task_result > 0)
{
$project_result = $object->fetch_projet();
if($project_result >= 0)
if ($project_result >= 0)
{
$tmpreldir = dol_sanitizeFileName($object->project->ref).'/';
}
@@ -516,11 +516,11 @@ class Documents extends DolibarrApi
throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
}
if(is_object($object))
if (is_object($object))
{
$result = $object->fetch('', $ref);
if($result == 0)
if ($result == 0)
{
throw new RestException(404, "Object with ref '".$ref."' was not found.");
}
@@ -530,7 +530,7 @@ class Documents extends DolibarrApi
}
}
if (! ($object->id > 0))
if (!($object->id > 0))
{
throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found.");
}
@@ -538,7 +538,7 @@ class Documents extends DolibarrApi
$relativefile = $tmpreldir.dol_sanitizeFileName($object->ref);
$tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write');
$upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
$upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
if (empty($upload_dir) || $upload_dir == '/')
{
@@ -547,12 +547,12 @@ class Documents extends DolibarrApi
}
else
{
if ($modulepart == 'invoice') $modulepart ='facture';
if ($modulepart == 'invoice') $modulepart = 'facture';
$relativefile = $subdir;
$tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
$upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
$upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
if (empty($upload_dir) || $upload_dir == '/')
{
@@ -568,8 +568,8 @@ class Documents extends DolibarrApi
throw new RestException(500, 'Error while trying to create directory.');
}
$destfile = $upload_dir . '/' . $original_file;
$destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
$destfile = $upload_dir.'/'.$original_file;
$destfiletmp = DOL_DATA_ROOT.'/admin/temp/'.$original_file;
dol_delete_file($destfiletmp);
//var_dump($original_file);exit;
@@ -577,7 +577,7 @@ class Documents extends DolibarrApi
throw new RestException(401, 'Directory not exists : '.dirname($destfile));
}
if (! $overwriteifexists && dol_is_file($destfile))
if (!$overwriteifexists && dol_is_file($destfile))
{
throw new RestException(500, "File with name '".$original_file."' already exists.");
}
@@ -595,7 +595,7 @@ class Documents extends DolibarrApi
}
$result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
if (! $result)
if (!$result)
{
throw new RestException(500, "Failed to move file into '".$destfile."'");
}
@@ -629,7 +629,7 @@ class Documents extends DolibarrApi
}
//--- Finds and returns the document
$entity=$conf->entity;
$entity = $conf->entity;
$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, DolibarrApiAccess::$user, '', 'read');
$accessallowed = $check_access['accessallowed'];
@@ -644,9 +644,9 @@ class Documents extends DolibarrApi
}
$filename = basename($original_file);
$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset
$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
if (! file_exists($original_file_osencoded))
if (!file_exists($original_file_osencoded))
{
dol_syslog("Try to download not found file ".$original_file_osencoded, LOG_WARNING);
throw new RestException(404, 'File not found');