Start to move function for CLI mode into a dedicated file

This commit is contained in:
Laurent Destailleur 2024-10-04 12:10:25 +02:00
parent b188e397fb
commit 40f2830714
26 changed files with 74 additions and 11 deletions

View File

@ -0,0 +1,50 @@
<?php
/* Copyright (C) 2024 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 <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/lib/functionscli.lib.php
* \brief A set of functions for CLI scripts of Dolibarr
* This file contains only functions used by script run on command line.
*/
// Define ANSI color constant to use colors and bold in CLI script
define('DOL_COLOR_RESET', "\033[0m"); // Restore color
define('DOL_COLOR_BOLD', "\033[1m"); // Bold
define('DOL_COLOR_RED', "\033[31m");
define('DOL_COLOR_GREEN', "\033[32m");
define('DOL_COLOR_YELLOW', "\033[33m");
define('DOL_COLOR_BLUE', "\033[34m");
define('DOL_COLOR_MAGENTA', "\033[35m");
define('DOL_COLOR_CYAN', "\033[36m");
define('DOL_COLOR_WHITE', "\033[37m");
/**
* Output text in color or bold
*
* @param string $text Text to show
* @param string $color Color code
* @param boolean $bold Bold or not
* @return string Text enhanced with colors
*/
function coloredText($text, $color, $bold = false)
{
$boldCode = $bold ? DOL_COLOR_BOLD : '';
return $boldCode . $color . $text . DOL_COLOR_RESET;
}

View File

@ -265,14 +265,3 @@ if (!defined('NOREQUIRETRAN')) {
}
$langs->setDefaultLang($langcode);
}
// Define ANSI color constant to use colors and bold in CLI script
define('DOL_COLOR_RESET', "\033[0m"); // Restore color
define('DOL_COLOR_BOLD', "\033[1m"); // Bold
define('DOL_COLOR_RED', "\033[31m");
define('DOL_COLOR_GREEN', "\033[32m");
define('DOL_COLOR_YELLOW', "\033[33m");
define('DOL_COLOR_BLUE', "\033[34m");
define('DOL_COLOR_MAGENTA', "\033[35m");
define('DOL_COLOR_CYAN', "\033[36m");
define('DOL_COLOR_WHITE', "\033[37m");

View File

@ -39,6 +39,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';

View File

@ -39,6 +39,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/contact/class/contact.class.php";
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";

View File

@ -55,6 +55,7 @@ $mode = $argv[1];
$targettype = $argv[2];
require $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
$langs->loadLangs(array('main', 'contracts'));

View File

@ -53,6 +53,7 @@ if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm'
$mode = $argv[1];
require $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
$langs->loadLangs(array('main', 'contracts'));

View File

@ -60,6 +60,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';

View File

@ -42,6 +42,7 @@ define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to
// Include and load Dolibarr environment variables
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";

View File

@ -62,6 +62,7 @@ if (isset($argv[3]) || !empty($argv[3])) {
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php";

View File

@ -50,6 +50,7 @@ $type = $argv[2];
$mode = $argv[3];
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php";

View File

@ -55,6 +55,7 @@ $mode = $argv[1];
$targettype = $argv[2];
require $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
$langs->load('main');

View File

@ -53,6 +53,7 @@ if (!isset($argv[1]) || !$argv[1] || !in_array($argv[1], array('test', 'confirm'
$mode = $argv[1];
require $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
$langs->load('main');

View File

@ -40,6 +40,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
// Include Dolibarr environment
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
// After this $db is an opened handler to database. We close it at end of file.
require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
require_once DOL_DOCUMENT_ROOT."/core/modules/facture/modules_facture.php";

View File

@ -39,6 +39,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php";

View File

@ -40,6 +40,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php";

View File

@ -47,6 +47,7 @@ if (!isset($argv[1]) || !$argv[1]) {
$now = $argv[1];
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php";

View File

@ -41,6 +41,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php";

View File

@ -43,6 +43,7 @@ define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to
// Include and load Dolibarr environment variables
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).

View File

@ -42,6 +42,7 @@ define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to
// Include and load Dolibarr environment variables
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";

View File

@ -43,6 +43,7 @@ define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to
// Include and load Dolibarr environment variables
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).

View File

@ -45,6 +45,7 @@ if (!isset($argv[1]) || !$argv[1]) {
$now = $argv[1];
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";

View File

@ -40,6 +40,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";

View File

@ -45,6 +45,7 @@ if (!isset($argv[1]) || !$argv[1]) {
$now = $argv[1];
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";

View File

@ -39,6 +39,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
require_once DOL_DOCUMENT_ROOT."/user/class/user.class.php";

View File

@ -54,6 +54,7 @@ if (empty($argv[2]) || !in_array($argv[1], array('test', 'confirm')) || empty($w
}
require $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';

View File

@ -38,6 +38,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
}
require_once $path."../../htdocs/master.inc.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
require_once DOL_DOCUMENT_ROOT."/compta/prelevement/class/bonprelevement.class.php";
require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";