dolibarr  13.0.2
regenerate-pages.php
1 #!/usr/bin/env php
2 <?php
3 /* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 if (!defined('NOSESSION')) define('NOSESSION', '1');
26 
27 $sapi_type = php_sapi_name();
28 $script_file = basename(__FILE__);
29 $path = __DIR__.'/';
30 
31 // Test if batch mode
32 if (substr($sapi_type, 0, 3) == 'cgi') {
33  echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34  exit(-1);
35 }
36 
37 @set_time_limit(0); // No timeout for this script
38 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".
39 
40 $error = 0;
41 
42 $mode = empty($argv[1]) ? '' : $argv[1];
43 $websiteref = empty($argv[2]) ? '' : $argv[2];
44 $max = (!isset($argv[3]) || (empty($argv[3]) && $argv[3] !== '0')) ? '10' : $argv[3];
45 
46 if (empty($argv[2]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) {
47  print '***** '.$script_file.' *****'."\n";
48  print "Usage: $script_file (test|confirm) website [nbmaxrecord]\n";
49  print "\n";
50  print "Regenerate all pages of a web site.\n";
51  exit(-1);
52 }
53 
54 require $path."../../htdocs/master.inc.php";
55 include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
56 include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
57 include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
58 
59 $langs->load('main');
60 
61 $website = new Website($db);
62 $result = $website->fetch(0, $websiteref);
63 if ($result <= 0) {
64  print 'Error, web site '.$websiteref.' not found'."\n";
65  exit(-1);
66 }
67 
68 $websitepagestatic = new WebsitePage($db);
69 
70 $db->begin();
71 
72 $listofpages = $websitepagestatic->fetchAll($website->id, '', '', $max);
73 
74 global $dolibarr_main_data_root;
75 $pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref;
76 
77 $nbgenerated = 0;
78 foreach ($listofpages as $websitepage) {
79  $filealias = $pathofwebsite.'/'.$websitepage->pageurl.'.php';
80  $filetpl = $pathofwebsite.'/page'.$websitepage->id.'.tpl.php';
81  if ($mode == 'confirm') {
82  dolSavePageAlias($filealias, $website, $websitepage);
83  dolSavePageContent($filetpl, $website, $websitepage);
84  }
85  print "Generation of page done - pageid = ".$websitepage->id." - ".$websitepage->pageurl."\n";
86  $nbgenerated++;
87 
88  if ($max && $nbgenerated >= $max) {
89  print 'Nb max of record ('.$max.') reached. We stop now.'."\n";
90  break;
91  }
92 }
93 
94 if ($mode == 'confirm') {
95  print $nbgenerated." page(s) generated into ".$pathofwebsite."\n";
96 } else {
97  print $nbgenerated." page(s) found but not generated (test mode)\n";
98 }
99 
100 exit($error);
Class Website.
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage)
Save content of a page on disk (page name is generally ID_of_page.php).
Class Websitepage.
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
print
Draft customers invoices.
Definition: index.php:89