regenerate_docs.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /**
  20. * \file scripts/doc/regenerate_docs.php
  21. * \ingroup scripts
  22. * \brief Regenerated main documents into documents directory
  23. */
  24. if (!defined('NOSESSION')) {
  25. define('NOSESSION', '1');
  26. }
  27. $sapi_type = php_sapi_name();
  28. $script_file = basename(__FILE__);
  29. $path = __DIR__.'/';
  30. // Test if batch mode
  31. if (substr($sapi_type, 0, 3) == 'cgi') {
  32. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  33. exit(-1);
  34. }
  35. @set_time_limit(0); // No timeout for this script
  36. 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".
  37. // Include and load Dolibarr environment variables
  38. require_once $path."../../htdocs/master.inc.php";
  39. require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
  40. require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
  41. require_once DOL_DOCUMENT_ROOT."/core/lib/images.lib.php";
  42. // After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file).
  43. // $user is created but empty.
  44. // $langs->setDefaultLang('en_US'); // To change default language of $langs
  45. $langs->load("main"); // To load language file for default language
  46. // Global variables
  47. $version = DOL_VERSION;
  48. $error = 0;
  49. $forcecommit = 0;
  50. print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." - dir=".DOL_DATA_ROOT." *****\n";
  51. dol_syslog($script_file." launched with arg ".join(',', $argv));
  52. if (empty($argv[1])) {
  53. print "Usage: $script_file subdirtoscan (test|confirm)\n";
  54. print "Example: $script_file propale test\n";
  55. exit(-1);
  56. }
  57. print '--- start'."\n";
  58. $dir = DOL_DATA_ROOT;
  59. $subdir = $argv[1];
  60. if (empty($dir) || empty($subdir)) {
  61. dol_print_error('', 'dir not defined');
  62. exit(1);
  63. }
  64. if (!dol_is_dir($dir.'/'.$subdir)) {
  65. print 'Directory '.$dir.'/'.$subdir.' not found.'."\n";
  66. exit(2);
  67. }
  68. print 'Scan directory '.$dir.'/'.$subdir."\n";
  69. $filearray = dol_dir_list($dir.'/'.$subdir, "directories", 0, '', 'temp$');
  70. $nbok = $nbko = 0;
  71. $tmpobject = null;
  72. if ($subdir == 'propale' || $subdir == 'proposal') {
  73. if (isModEnabled('propal')) {
  74. require_once DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php";
  75. $tmpobject = new Propal($db);
  76. } else {
  77. print 'Error, module not enabled'."\n";
  78. }
  79. } elseif ($subdir == 'commande' || $subdir == 'order') {
  80. if (isModEnabled('commande')) {
  81. require_once DOL_DOCUMENT_ROOT."/commande/class/commande.class.php";
  82. $tmpobject = new Commande($db);
  83. } else {
  84. print 'Error, module not enabled'."\n";
  85. }
  86. } elseif ($subdir == 'facture' || $subdir == 'invoice') {
  87. if (isModEnabled('facture')) {
  88. require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
  89. $tmpobject = new Facture($db);
  90. } else {
  91. print 'Error, module not enabled'."\n";
  92. }
  93. } else {
  94. print 'Dir '.$subdir.' not yet supported'."\n";
  95. }
  96. if ($tmpobject) {
  97. foreach ($filearray as $keyf => $valf) {
  98. $ref = basename($valf['name']);
  99. print 'Process document for dir = '.$subdir.', ref '.$ref."\n";
  100. $ret1 = $tmpobject->fetch(0, $ref);
  101. $ret2 = $tmpobject->fetch_thirdparty();
  102. if ($ret1 > 0) {
  103. //$tmpobject->build
  104. //$tmpobject->setDocModel($user, GETPOST('model', 'alpha'));
  105. $outputlangs = $langs;
  106. $newlang = '';
  107. if (!empty($newlang)) {
  108. $outputlangs = new Translate("", $conf);
  109. $outputlangs->setDefaultLang($newlang);
  110. }
  111. $hidedetails = 0;
  112. $hidedesc = 0;
  113. $hideref = 0;
  114. $moreparams = null;
  115. $result = 0;
  116. if (!empty($argv[2]) && $argv[2] == 'confirm') {
  117. $result = $tmpobject->generateDocument($tmpobject->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  118. }
  119. if ($result < 0) {
  120. $nbko++;
  121. } if ($result == 0) {
  122. print 'File for ref '.$tmpobject->ref.' returned 0 during regeneration with template '.$tmpobject->model_pdf."\n";
  123. $nbok++;
  124. } else {
  125. print 'File for ref '.$tmpobject->ref.' regenerated with template '.$tmpobject->model_pdf."\n";
  126. $nbok++;
  127. }
  128. } else {
  129. $nbko++;
  130. }
  131. }
  132. }
  133. print $nbok." objects processed\n";
  134. print $nbko." objects with errors\n";
  135. $db->close(); // Close $db database opened handler
  136. exit($error);