dolibarr 20.0.0
Utils Class Reference

Class to manage utility methods. More...

Public Member Functions

 __construct ($db)
 Constructor.
 
 purgeFiles ($choices='tempfilesold+logfiles', $nbsecondsold=86400)
 Purge files into directory of data files.
 
 dumpDatabase ($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0, $execmethod=0, $lowmemorydump=0)
 Make a backup of database CAN BE A CRON TASK.
 
 executeCLI ($command, $outputfile, $execmethod=0, $redirectionfile=null, $noescapecommand=0, $redirectionfileerr=null)
 Execute a CLI command.
 
 generateDoc ($module)
 Generate documentation of a Module.
 
 compressSyslogs ()
 This saves syslog files and compresses older ones.
 
 sendBackup ($sendto='', $from='', $subject='', $message='', $filename='', $filter='', $sizelimit=100000000)
 Make a send last backup of database or fil in param CAN BE A CRON TASK.
 
 cleanUnfinishedCronjob ()
 Clean unfinished cronjob in processing when pid is no longer present in the system CAN BE A CRON TASK.
 

Public Attributes

 $db
 

Detailed Description

Class to manage utility methods.

Definition at line 33 of file utils.class.php.

Constructor & Destructor Documentation

◆ __construct()

Utils::__construct ( $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 66 of file utils.class.php.

References $db.

Member Function Documentation

◆ cleanUnfinishedCronjob()

Utils::cleanUnfinishedCronjob ( )

Clean unfinished cronjob in processing when pid is no longer present in the system CAN BE A CRON TASK.

Returns
int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
Exceptions
Exception

Definition at line 1411 of file utils.class.php.

References $db, and dol_syslog().

◆ compressSyslogs()

Utils::compressSyslogs ( )

This saves syslog files and compresses older ones.

Nb of archive to keep is defined into $conf->global->SYSLOG_FILE_SAVES CAN BE A CRON TASK

Returns
int 0 if OK, < 0 if KO

Definition at line 998 of file utils.class.php.

References dol_delete_file(), dol_dir_list(), dol_filesize(), dol_is_file(), dol_move(), dolChmod(), and getDolGlobalString().

◆ dumpDatabase()

Utils::dumpDatabase ( $compression = 'none',
$type = 'auto',
$usedefault = 1,
$file = 'auto',
$keeplastnfiles = 0,
$execmethod = 0,
$lowmemorydump = 0 )

Make a backup of database CAN BE A CRON TASK.

Parameters
string$compression'gz' or 'bz' or 'none'
string$type'mysql', 'postgresql', ...
int$usedefault1=Use default backup profile (Set this to 1 when used as cron)
string$file'auto' or filename to build
int$keeplastnfilesKeep only last n files (not used yet)
int$execmethod0=Use default method (that is 1 by default), 1=Use the PHP 'exec' - need size of dump in memory, but low memory method is used if GETPOST('lowmemorydump') is set, 2=Use the 'popen' method (low memory method)
int$lowmemorydump1=Use the low memory method. If $lowmemorydump is set, it means we want to make the compression using an external pipe instead retrieving the content of the dump in PHP memory array $output_arr and then print it into the PHP pipe open with xopen().
Returns
int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)

Definition at line 246 of file utils.class.php.

References $db, dol_delete_file(), dol_dir_list(), dol_mkdir(), dol_move(), dol_now(), dol_print_date(), dol_sanitizeFileName(), dol_syslog(), dolChmod(), getDolGlobalString(), and GETPOST().

◆ executeCLI()

Utils::executeCLI ( $command,
$outputfile,
$execmethod = 0,
$redirectionfile = null,
$noescapecommand = 0,
$redirectionfileerr = null )

Execute a CLI command.

Parameters
string$commandCommand line to execute. Warning: The command line is sanitize by escapeshellcmd(), except if $noescapecommand set, so can't contains any redirection char '>'. Use param $redirectionfile if you need it.
string$outputfileA path for an output file (used only when method is 2). For example: $conf->admin->dir_temp.'/out.tmp';
int$execmethod0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
string$redirectionfileIf defined, a redirection of output to this file is added.
int$noescapecommand1=Do not escape command. Warning: Using this parameter needs you already have sanitized the $command parameter. If not, it will lead to security vulnerability. This parameter is provided for backward compatibility with external modules. Always use 0 in core.
string$redirectionfileerrIf defined, a redirection of error is added to this file instead of to channel 1.
Returns
array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK.

Definition at line 719 of file utils.class.php.

References dol_syslog(), dolChmod(), and getDolGlobalString().

◆ generateDoc()

Utils::generateDoc ( $module)

Generate documentation of a Module.

Parameters
string$moduleModule name
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 796 of file utils.class.php.

References dol_buildpath(), dol_copy(), dol_dir_list(), dol_include_once(), dol_is_dir(), dol_mkdir(), dol_now(), dol_print_date(), dol_print_error(), dolMd2Asciidoc(), dolReplaceInFile(), and getDolGlobalString().

◆ purgeFiles()

Utils::purgeFiles ( $choices = 'tempfilesold+logfiles',
$nbsecondsold = 86400 )

Purge files into directory of data files.

CAN BE A CRON TASK

Parameters
string$choicesChoice of purge mode ('tempfiles', 'tempfilesold' to purge temp older than $nbsecondsold seconds, 'logfiles', or mix of this). Note that 'allfiles' is also possible but very dangerous.
int$nbsecondsoldNb of seconds old to accept deletion of a directory if $choice is 'tempfilesold', or deletion of file if $choice is 'allfiles'
Returns
int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)

Definition at line 80 of file utils.class.php.

References dol_delete_dir_recursive(), dol_delete_file(), dol_dir_list(), dol_mkdir(), dol_now(), dol_syslog(), and getDolGlobalString().

◆ sendBackup()

Utils::sendBackup ( $sendto = '',
$from = '',
$subject = '',
$message = '',
$filename = '',
$filter = '',
$sizelimit = 100000000 )

Make a send last backup of database or fil in param CAN BE A CRON TASK.

Parameters
string$sendtoRecipients emails
string$fromSender email
string$subjectTopic/Subject of mail
string$messageMessage
string$filenameList of files to attach (full path of filename on file system)
string$filterFilter file send
int$sizelimitLimit size to send file
Returns
int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)

Definition at line 1301 of file utils.class.php.

References dol_escape_htmltag(), dol_filesize(), dol_is_file(), dol_most_recent_file(), dol_syslog(), and getDolGlobalString().

Member Data Documentation

◆ $db

Utils::$db

Definition at line 38 of file utils.class.php.

Referenced by __construct(), cleanUnfinishedCronjob(), and dumpDatabase().


The documentation for this class was generated from the following file: