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