Merge remote-tracking branch 'upstream/develop' into exportadmin

This commit is contained in:
Frédéric FRANCE 2017-11-06 21:41:09 +01:00
commit d39804e7b5
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
13 changed files with 367 additions and 152 deletions

View File

@ -280,6 +280,23 @@ Following changes may create regression for some external modules, but were nece
content by doing a print into function, sometimes by returning content into "resprint". This has been fixed to follow
hook specifications so you must return output into "resprint".
***** ChangeLog for 5.0.7 compared to 5.0.6 *****
FIX: #7000 Dashboard link for late pending payment supplier invoices do not work
FIX: #7148
FIX: #7325 Default VAT rate when editing template invoices is 0%
FIX: #7366 renaming table with pgsql
FIX: #7391
FIX: #7510 Bug: extrafield content disappear when generate pdf within intervention
FIX: Agenda events are not exported in the ICAL, VCAL if begin exactly with the same $datestart
FIX: Bad link to unpayed suppliers invoices
FIX: bankentries search conciliated if val 0
FIX: multicompany better accuracy in rounding and with revenue stamp.
FIX: PDF output was sharing 2 different currencies in same total
FIX: Upgrade missing on field
FIX: wrong key in selectarray
FIX: wrong personnal project time spent
***** ChangeLog for 5.0.6 compared to 5.0.5 *****
FIX: Removed a bad symbolic link into custom directory.
FIX: Renaming a resource ref rename also the directory of attached files.

View File

@ -3119,7 +3119,6 @@ class Commande extends CommonOrder
// End call triggers
}
//TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail
if (! $error)
{
// Delete order details
@ -3129,23 +3128,24 @@ class Commande extends CommonOrder
$error++;
$this->errors[]=$this->db->lasterror();
}
}
// Delete order
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
if (! $this->db->query($sql) )
{
$error++;
$this->errors[]=$this->db->lasterror();
}
if (! $error)
{
// Delete linked object
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
}
if (! $error)
{
// Delete linked contacts
$res = $this->delete_linked_contact();
if ($res < 0) $error++;
}
if (! $error)
{
// Remove extrafields
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
@ -3156,8 +3156,22 @@ class Commande extends CommonOrder
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
}
// On efface le repertoire de pdf provisoire
if (! $error)
{
// Delete object
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id;
if (! $this->db->query($sql) )
{
$error++;
$this->errors[]=$this->db->lasterror();
}
}
if (! $error)
{
// Remove directory with files
$comref = dol_sanitizeFileName($this->ref);
if ($conf->commande->dir_output && !empty($this->ref))
{
@ -3183,8 +3197,6 @@ class Commande extends CommonOrder
}
}
}
}
if (! $error)

View File

@ -197,8 +197,15 @@ if ($action == 'update')
$object->proprio = trim($_POST["proprio"]);
$object->owner_address = trim($_POST["owner_address"]);
$account_number = GETPOST('account_number', 'int');
if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; }
$account_number = GETPOST('account_number', 'alpha');
if (empty($account_number) || $account_number == '-1')
{
$object->account_number = '';
}
else
{
$object->account_number = $account_number;
}
$fk_accountancy_journal = GETPOST('fk_accountancy_journal','int');
if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
@ -213,7 +220,7 @@ if ($action == 'update')
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
{
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'error');
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
$action='edit'; // Force chargement page en mode creation
$error++;
}

View File

@ -82,9 +82,12 @@ if ($action == 'add')
$accountto=new Account($db);
$accountto->fetch(GETPOST('account_to','int'));
if ($accountto->currency_code == $accountfrom->currency_code) {
if ($accountto->currency_code == $accountfrom->currency_code)
{
$amountto=$amount;
} else {
}
else
{
if (! $amountto)
{
$error++;

View File

@ -56,7 +56,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->id)
{
$urlfile = GETPOST('urlfile', 'alpha'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
if (GETPOST('section', 'alpha')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir
else // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
{

View File

@ -449,4 +449,78 @@ class Utils
return 0;
}
/**
* Execute a CLI command.
*
* @param string $command Command line to execute.
* @param string $outputfile Output file (used only when method is 2). For exemple $conf->admin->dir_temp.'/out.tmp';
* @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
* @return array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK.
*/
function executeCLI($command, $outputfile, $execmethod=0)
{
global $conf, $langs;
$result = 0;
$output = '';
$error = '';
$command=escapeshellcmd($command);
$command.=" 2>&1";
if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN;
if (empty($execmethod)) $execmethod=1;
//$execmethod=1;
dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG);
$output_arr=array();
if ($execmethod == 1)
{
exec($command, $output_arr, $retval);
$result = $retval;
if ($retval != 0)
{
$langs->load("errors");
dol_syslog("Utils::executeCLI retval after exec=".$retval, LOG_ERR);
$error = 'Error '.$retval;
}
}
if ($execmethod == 2) // With this method, there is no way to get the return code, only output
{
$ok=0;
$handle = fopen($outputfile, 'w+b');
if ($handle)
{
dol_syslog("Utils::executeCLI run command ".$command);
$handlein = popen($command, 'r');
while (!feof($handlein))
{
$read = fgets($handlein);
fwrite($handle,$read);
$output_arr[]=$read;
}
pclose($handlein);
fclose($handle);
}
if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
}
// Update with result
if (is_array($output_arr) && count($output_arr)>0)
{
foreach($output_arr as $val)
{
$output.=$val.($execmethod == 2 ? '' : "\n");
}
}
dol_syslog("Utils::executeCLI result=".$result." output=".$output." error=".$error, LOG_DEBUG);
return array('result'=>$result, 'output'=>$output, 'error'=>$error);
}
}

View File

@ -1052,7 +1052,11 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
$file_name_osencoded=dol_osencode($file_name);
// Check if destination dir is writable
// TODO
if (! is_writable(dirname($file_name_osencoded)))
{
dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
return 'ErrorDirNotWritable';
}
// Check if destination file already exists
if (! $allowoverwrite)

View File

@ -270,10 +270,11 @@ function GETPOSTISSET($paramname)
* 'custom'= custom filter specify $filter and $options)
* @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get, 4 = post then get then cookie)
* @param int $filter Filter to apply when $check is set to 'custom'. (See http://php.net/manual/en/filter.filters.php for détails)
* @param mixed $options Options to pass to filter_var when $check is set to 'custom'.
* @param mixed $options Options to pass to filter_var when $check is set to 'custom'
* @param string $noreplace Force disable of replacement of __xxx__ strings.
* @return string|string[] Value found (string or array), or '' if check fails
*/
function GETPOST($paramname, $check='alpha', $method=0, $filter=NULL, $options=NULL)
function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
{
global $mysoc,$user,$conf;
@ -467,7 +468,7 @@ function GETPOST($paramname, $check='alpha', $method=0, $filter=NULL, $options=N
// Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters)
// Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ...
// We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text.
if (! is_array($out) && empty($_POST[$paramname]))
if (! is_array($out) && empty($_POST[$paramname]) && empty($noreplace))
{
$maxloop=20; $loopnb=0; // Protection against infinite loop
while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
@ -3650,7 +3651,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
$return.= "\n";
$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle" id="pictotitle"', $pictoisfullpath).'</td>';
if ($picto) $return.= '<td class="nobordernopadding widthpictotitle" valign="middle">'.img_picto('',$picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).'</td>';
$return.= '<td class="nobordernopadding" valign="middle">';
$return.= '<div class="titre">'.$titre.'</div>';
$return.= '</td>';

View File

@ -1060,7 +1060,14 @@ class Cronjob extends CommonObject
$outputfile=$outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
// Execute a CLI
$retval = $this->executeCLI($this->command, $outputfile);
include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
$utils = new Utils($db);
$arrayresult = $utils->executeCLI($this->command, $outputfile);
$retval = $arrayresult['result'];
$this->error = $arrayresult['error'];
$this->lastoutput = $arrayresult['output'];
$this->lastresult = $arrayresult['result'];
}
}
@ -1082,81 +1089,6 @@ class Cronjob extends CommonObject
}
/**
* Execute a CLI command.
* this->error, this->lastoutput, this->lastresult are also set.
*
* @param string $command Command line
* @param string $outputfile Output file
* @param int $execmethod 0=Use default method, 1=Use the PHP 'exec', 2=Use the 'popen' method
* @return int Retval
*/
function executeCLI($command, $outputfile, $execmethod=0)
{
global $conf, $langs;
$retval = 0;
$command=escapeshellcmd($command);
$command.=" 2>&1";
if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN;
if (empty($execmethod)) $execmethod=1;
//$execmethod=1;
dol_syslog(get_class($this)."::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG);
$output_arr=array();
if ($execmethod == 1)
{
exec($command, $output_arr, $retval);
if ($retval != 0)
{
$langs->load("errors");
dol_syslog(get_class($this)."::executeCLI retval after exec=".$retval, LOG_ERR);
$this->error = 'Error '.$retval;
$this->lastoutput = ''; // Will be filled later from $output_arr
$this->lastresult = $retval;
$retval = $this->lastresult;
}
}
if ($execmethod == 2) // With this method, there is no way to get the return code, only output
{
$ok=0;
$handle = fopen($outputfile, 'w+b');
if ($handle)
{
dol_syslog(get_class($this)."::executeCLI run command ".$command);
$handlein = popen($command, 'r');
while (!feof($handlein))
{
$read = fgets($handlein);
fwrite($handle,$read);
$output_arr[]=$read;
}
pclose($handlein);
fclose($handle);
}
if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
}
// Update with result
if (is_array($output_arr) && count($output_arr)>0)
{
foreach($output_arr as $val)
{
$this->lastoutput.=$val.($execmethod == 2 ? '' : "\n");
}
}
$this->lastresult=$retval;
dol_syslog(get_class($this)."::executeCLI output_arr:".var_export($output_arr,true)." lastoutput=".$this->lastoutput." lastresult=".$this->lastresult, LOG_DEBUG);
return $retval;
}
/**
* Reprogram a job
*

View File

@ -840,85 +840,96 @@ class Fichinter extends CommonObject
$this->db->begin();
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('FICHINTER_DELETE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers
}
// Delete linked object
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
if (! $error)
{
$res = $this->deleteObjectLinked();
if ($res < 0) $error++;
}
// Delete linked contacts
$res = $this->delete_linked_contact();
if ($res < 0)
if (! $error)
{
$this->error='ErrorFailToDeleteLinkedContact';
$error++;
$res = $this->delete_linked_contact();
if ($res < 0)
{
$this->error='ErrorFailToDeleteLinkedContact';
$error++;
}
}
if ($error)
if (! $error)
{
$this->db->rollback();
return -1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
$sql.= " WHERE fk_fichinter = ".$this->id;
$resql = $this->db->query($sql);
if (! $resql) $error++;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
$sql.= " WHERE fk_fichinter = ".$this->id;
dol_syslog("Fichinter::delete", LOG_DEBUG);
if ( $this->db->query($sql) )
if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
// Remove extrafields
$res = $this->deleteExtraFields();
if ($res < 0) $error++;
}
if (! $error)
{
// Delete object
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
dol_syslog("Fichinter::delete", LOG_DEBUG);
if ( $this->db->query($sql) )
$resql = $this->db->query($sql);
if (! $resql) $error++;
}
if (! $error)
{
// Remove directory with files
$fichinterref = dol_sanitizeFileName($this->ref);
if ($conf->ficheinter->dir_output)
{
// Remove directory with files
$fichinterref = dol_sanitizeFileName($this->ref);
if ($conf->ficheinter->dir_output)
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
if (file_exists($file))
{
$dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
$file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
if (file_exists($file))
{
dol_delete_preview($this);
dol_delete_preview($this);
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
}
}
if (file_exists($dir))
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
if (! dol_delete_dir_recursive($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
}
}
if (! $notrigger)
if (file_exists($dir))
{
// Call trigger
$result=$this->call_trigger('FICHINTER_DELETE',$user);
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
// End call triggers
if (! dol_delete_dir_recursive($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
}
}
}
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -2;
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}

View File

@ -251,7 +251,7 @@ else
if ($search_type != '' && $search_type != '-1')
{
if ($search_type==1)
if ($search_type == 1)
{
$texte = $langs->trans("Services");
}

View File

@ -85,6 +85,8 @@ class AllTests
$suite->addTestSuite('CompanyLibTest');
require_once dirname(__FILE__).'/DateLibTest.php';
$suite->addTestSuite('DateLibTest');
require_once dirname(__FILE__).'/UtilsTest.php';
$suite->addTestSuite('UtilsTest');
//require_once dirname(__FILE__).'/DateLibTzFranceTest.php';
//$suite->addTestSuite('DateLibTzFranceTest');
require_once dirname(__FILE__).'/MarginsLibTest.php';

152
test/phpunit/UtilsTest.php Normal file
View File

@ -0,0 +1,152 @@
<?php
/* Copyright (C) 2010-2015 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file test/phpunit/UtilsTest.php
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/class/utils.class.php';
if (empty($user->id)) {
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class UtilsTest extends PHPUnit_Framework_TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return UserTest
*/
function __construct()
{
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
// Static methods
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
print __METHOD__."\n";
}
// tear down after class
public static function tearDownAfterClass()
{
global $conf,$user,$langs,$db;
$db->rollback();
print __METHOD__."\n";
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
print __METHOD__."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{
print __METHOD__."\n";
}
/**
* testExecuteCLI
*
* @return void
*/
public function testExecuteCLI()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new Utils($this->savdb);
$result = $localobject->executeCLI('ls', $conf->admin->dir_temp.'/out.tmp', 1);
print var_export($result, true);
$this->assertEquals($result['result'], 0);
$this->assertEquals($result['error'], '');
//$this->assertEquals(preg_match('/phpunit/', $result['output']), 1);
$localobject=new Utils($this->savdb);
$result = $localobject->executeCLI('ls', $conf->admin->dir_temp.'/out.tmp', 2);
print var_export($result, true);
$this->assertEquals($result['result'], 0);
$this->assertEquals($result['error'], '');
//$this->assertEquals(preg_match('/phpunit/', $result['output']), 1);
print __METHOD__." result=".$result."\n";
return $result;
}
}