Utils
class Utils (View source)
Class to manage utility methods
Properties
| DoliDB | $db | ||
| $error | |||
| string[] | $errors | ||
| string | $output | ||
| array{commandbackuplastdone: string, commandbackuptorun: string} | $result |
Methods
Constructor
Purge files into directory of data files.
Make a backup of database CAN BE A CRON TASK
Execute a CLI command.
Generate documentation of a Module
This saves syslog files and compresses older ones.
Backup the db OR just a table without mysqldump binary, with PHP only (does not require any exec permission) Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php) Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog Note about foreign keys constraints: for Dolibarr, since there are a lot of constraints and when imported the tables will be inserted in the dumped order, not in constraints order, then we ABSOLUTELY need to use SET FOREIGN_KEY_CHECKS=0; when importing the sql dump.
Make a send last backup of database or fil in param CAN BE A CRON TASK
Clean unfinished cronjob in processing when pid is no longer present in the system CAN BE A CRON TASK
Details
__construct($db)
Constructor
@param DoliDB $db Database handler
purgeFiles(string $choices = 'tempfilesold+logfiles', $nbsecondsold = 86400)
Purge files into directory of data files.
CAN BE A CRON TASK
dumpDatabase($compression = 'none', string $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0, $execmethod = 0, $lowmemorydump = 0)
Make a backup of database CAN BE A CRON TASK
@param string $compression 'gz' or 'bz' or 'none'
array{result: int, output: string, error: string}
executeCLI(string $command, string $outputfile, int<0, 2> $execmethod = 0, ?string $redirectionfile = null, int<0, 1> $noescapecommand = 0, ?string $redirectionfileerr = null)
Execute a CLI command.
int
generateDoc(string $module)
Generate documentation of a Module
int
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
int
backupTables(string $outputfile, string $tables = '*')
Backup the db OR just a table without mysqldump binary, with PHP only (does not require any exec permission) Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php) Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog Note about foreign keys constraints: for Dolibarr, since there are a lot of constraints and when imported the tables will be inserted in the dumped order, not in constraints order, then we ABSOLUTELY need to use SET FOREIGN_KEY_CHECKS=0; when importing the sql dump.
Note2: db2SQL by Howard Yeend can be an alternative, by using SHOW FIELDS FROM and SHOW KEYS FROM we could generate a more precise dump (eg: by getting the type of the field and then precisely outputting the right formatting - in quotes, numeric or null - instead of trying to guess like we are doing now).
sendBackup(string $sendto = '', string $from = '', string $subject = '', string $message = '', string $filename = '', $filter = '', $sizelimit = 100000000)
Make a send last backup of database or fil in param CAN BE A CRON TASK
int
cleanUnfinishedCronjob()
Clean unfinished cronjob in processing when pid is no longer present in the system CAN BE A CRON TASK