dolibarr 21.0.0-beta
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27if (!defined('NOSESSION')) {
28 define('NOSESSION', '1');
29}
30
31$sapi_type = php_sapi_name();
32$script_file = basename(__FILE__);
33$path = __DIR__.'/';
34
35// Test if batch mode
36if (substr($sapi_type, 0, 3) == 'cgi') {
37 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
38 exit(1);
39}
40
41@set_time_limit(0); // No timeout for this script
42define('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".
43
44// Include and load Dolibarr environment variables
45require_once $path."../../htdocs/master.inc.php";
46require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
47require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
48require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
49require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
58// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
59// $user is created but empty.
60
61// $langs->setDefaultLang('en_US'); // To change default language of $langs
62$langs->load("main"); // To load language file for default language
63
64// Global variables
65$version = DOL_VERSION;
66$error = 0;
67$forcecommit = 0;
68
69$hookmanager->initHooks(array('cli'));
70
71
72/*
73 * Main
74 */
75
76print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." - dir=".DOL_DATA_ROOT." *****\n";
77dol_syslog($script_file." launched with arg ".join(',', $argv));
78
79if (empty($argv[1])) {
80 print "Usage: $script_file subdirtoscan (test|confirm)\n";
81 print "Example: $script_file propale test\n";
82 exit(1);
83}
84
85print '--- start'."\n";
86
87$dir = DOL_DATA_ROOT;
88$subdir = $argv[1];
89if (empty($dir) || empty($subdir)) {
90 dol_print_error(null, 'dir not defined');
91 exit(1);
92}
93if (!dol_is_dir($dir.'/'.$subdir)) {
94 print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
95 exit(2);
96}
97
98print 'Scan directory '.$dir.'/'.$subdir."\n";
99
100$filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
101
102$nbok = $nbko = 0;
103
104$tmpobject = null;
105if ($subdir == 'propale' || $subdir == 'proposal') {
106 if (isModEnabled('propal')) {
107 require_once DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php";
108 $tmpobject = new Propal($db);
109 } else {
110 print 'Error, module not enabled'."\n";
111 }
112} elseif ($subdir == 'commande' || $subdir == 'order') {
113 if (isModEnabled('commande')) {
114 require_once DOL_DOCUMENT_ROOT."/commande/class/commande.class.php";
115 $tmpobject = new Commande($db);
116 } else {
117 print 'Error, module not enabled'."\n";
118 }
119} elseif ($subdir == 'facture' || $subdir == 'invoice') {
120 if (isModEnabled('facture')) {
121 require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
122 $tmpobject = new Facture($db);
123 } else {
124 print 'Error, module not enabled'."\n";
125 }
126} else {
127 print 'Dir '.$subdir.' not yet supported'."\n";
128}
129
130if ($tmpobject) {
131 foreach ($filearray as $keyf => $valf) {
132 $ref = basename($valf['name']);
133 print 'Process document for dir = '.$subdir.', ref '.$ref."\n";
134
135 $ret1 = $tmpobject->fetch(0, $ref);
136 $ret2 = $tmpobject->fetch_thirdparty();
137
138 if ($ret1 > 0) {
139 //$tmpobject->build
140 //$tmpobject->setDocModel($user, GETPOST('model', 'alpha'));
141 $outputlangs = $langs;
142 $newlang = '';
143
144 if (!empty($newlang)) {
145 $outputlangs = new Translate("", $conf);
146 $outputlangs->setDefaultLang($newlang);
147 }
148
149 $hidedetails = 0;
150 $hidedesc = 0;
151 $hideref = 0;
152 $moreparams = null;
153
154 $result = 0;
155 if (!empty($argv[2]) && $argv[2] == 'confirm') {
156 $result = $tmpobject->generateDocument($tmpobject->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
157 }
158 if ($result < 0) {
159 $nbko++;
160 }
161 if ($result == 0) {
162 print 'File for ref '.$tmpobject->ref.' returned 0 during regeneration with template '.$tmpobject->model_pdf."\n";
163 $nbok++;
164 } else {
165 print 'File for ref '.$tmpobject->ref.' regenerated with template '.$tmpobject->model_pdf."\n";
166 $nbok++;
167 }
168 } else {
169 $nbko++;
170 }
171 }
172}
173
174print $nbok." objects processed\n";
175print $nbko." objects with errors\n";
176
177$db->close(); // Close $db database opened handler
178
179exit($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