dolibarr 22.0.5
regenerate_docs.php
Go to the documentation of this file.
1#!/usr/bin/env php
2<?php
3/* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2015 Jean Heimburger <http://tiaris.eu>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28if (!defined('NOSESSION')) {
29 define('NOSESSION', '1');
30}
31
32$sapi_type = php_sapi_name();
33$script_file = basename(__FILE__);
34$path = __DIR__.'/';
35
36// Test if batch mode
37if (substr($sapi_type, 0, 3) == 'cgi') {
38 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
39 exit(1);
40}
41
42@set_time_limit(0); // No timeout for this script
43define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only".
44
45// Include and load Dolibarr environment variables
46require_once $path."../../htdocs/master.inc.php";
47require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
48require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
49require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
50require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
59// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
60// $user is created but empty.
61
62// $langs->setDefaultLang('en_US'); // To change default language of $langs
63$langs->load("main"); // To load language file for default language
64
65// Global variables
66$version = DOL_VERSION;
67$error = 0;
68$forcecommit = 0;
69
70$hookmanager->initHooks(array('cli'));
71
72
73/*
74 * Main
75 */
76
77print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." - dir=".DOL_DATA_ROOT." *****\n";
78dol_syslog($script_file." launched with arg ".implode(',', $argv));
79
80if (empty($argv[1])) {
81 print "Usage: $script_file subdirtoscan (test|confirm)\n";
82 print "Example: $script_file propale test\n";
83 exit(1);
84}
85
86print '--- start'."\n";
87
88$dir = DOL_DATA_ROOT;
89$subdir = $argv[1];
90if (empty($dir) || empty($subdir)) {
91 dol_print_error(null, 'dir not defined');
92 exit(1);
93}
94if (!dol_is_dir($dir.'/'.$subdir)) {
95 print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
96 exit(2);
97}
98
99print 'Scan directory '.$dir.'/'.$subdir."\n";
100
101$filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
102
103$nbok = $nbko = 0;
104
105$tmpobject = null;
106if ($subdir == 'propale' || $subdir == 'proposal') {
107 if (isModEnabled('propal')) {
108 require_once DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php";
109 $tmpobject = new Propal($db);
110 } else {
111 print 'Error, module not enabled'."\n";
112 }
113} elseif ($subdir == 'commande' || $subdir == 'order') {
114 if (isModEnabled('order')) {
115 require_once DOL_DOCUMENT_ROOT."/commande/class/commande.class.php";
116 $tmpobject = new Commande($db);
117 } else {
118 print 'Error, module not enabled'."\n";
119 }
120} elseif ($subdir == 'facture' || $subdir == 'invoice') {
121 if (isModEnabled('invoice')) {
122 require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
123 $tmpobject = new Facture($db);
124 } else {
125 print 'Error, module not enabled'."\n";
126 }
127} else {
128 print 'Dir '.$subdir.' not yet supported'."\n";
129}
130
131if ($tmpobject) {
132 foreach ($filearray as $keyf => $valf) {
133 $ref = basename($valf['name']);
134 print 'Process document for dir = '.$subdir.', ref '.$ref."\n";
135
136 $ret1 = $tmpobject->fetch(0, $ref);
137 $ret2 = $tmpobject->fetch_thirdparty();
138
139 if ($ret1 > 0) {
140 //$tmpobject->build
141 //$tmpobject->setDocModel($user, GETPOST('model', 'alpha'));
142 $outputlangs = $langs;
143 $newlang = '';
144
145 if (!empty($newlang)) {
146 $outputlangs = new Translate("", $conf);
147 $outputlangs->setDefaultLang($newlang);
148 }
149
150 $hidedetails = 0;
151 $hidedesc = 0;
152 $hideref = 0;
153 $moreparams = null;
154
155 $result = 0;
156 if (!empty($argv[2]) && $argv[2] == 'confirm') {
157 $result = $tmpobject->generateDocument($tmpobject->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
158 }
159 if ($result < 0) {
160 $nbko++;
161 }
162 if ($result == 0) {
163 print 'File for ref '.$tmpobject->ref.' returned 0 during regeneration with template '.$tmpobject->model_pdf."\n";
164 $nbok++;
165 } else {
166 print 'File for ref '.$tmpobject->ref.' regenerated with template '.$tmpobject->model_pdf."\n";
167 $nbok++;
168 }
169 } else {
170 $nbko++;
171 }
172 }
173}
174
175print $nbok." objects processed\n";
176print $nbko." objects with errors\n";
177
178$db->close(); // Close $db database opened handler
179
180exit($error);
Class to manage customers orders.
Class to manage invoices.
Class to manage proposals.
Class to manage translations.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_is_dir($folder)
Test if filename is a directory.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79