dolibarr 19.0.4
regenerate-pages.php
Go to the documentation of this file.
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
25if (!defined('NOSESSION')) {
26 define('NOSESSION', '1');
27}
28
29$sapi_type = php_sapi_name();
30$script_file = basename(__FILE__);
31$path = __DIR__.'/';
32
33// Test if batch mode
34if (substr($sapi_type, 0, 3) == 'cgi') {
35 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36 exit(-1);
37}
38
39@set_time_limit(0); // No timeout for this script
40define('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".
41
42$error = 0;
43
44$mode = empty($argv[1]) ? '' : $argv[1];
45$websiteref = empty($argv[2]) ? '' : $argv[2];
46$max = (!isset($argv[3]) || (empty($argv[3]) && $argv[3] !== '0')) ? '10' : $argv[3];
47
48if (empty($argv[2]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) {
49 print '***** '.$script_file.' *****'."\n";
50 print "Usage: $script_file (test|confirm) website [nbmaxrecord]\n";
51 print "\n";
52 print "Regenerate all pages of a web site.\n";
53 exit(-1);
54}
55
56require $path."../../htdocs/master.inc.php";
57include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
58include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
59include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
60
61
62/*
63 * Main
64 */
65
66$langs->load('main');
67
68if (!empty($dolibarr_main_db_readonly)) {
69 print "Error: instance in read-onyl mode\n";
70 exit(-1);
71}
72
73$website = new Website($db);
74$result = $website->fetch(0, $websiteref);
75if ($result <= 0) {
76 print 'Error, web site '.$websiteref.' not found'."\n";
77 exit(-1);
78}
79
80$websitepagestatic = new WebsitePage($db);
81
82$db->begin();
83
84$listofpages = $websitepagestatic->fetchAll($website->id, '', '', $max);
85
86global $dolibarr_main_data_root;
87$pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref;
88
89$nbgenerated = 0;
90foreach ($listofpages as $websitepage) {
91 $filealias = $pathofwebsite.'/'.$websitepage->pageurl.'.php';
92 $filetpl = $pathofwebsite.'/page'.$websitepage->id.'.tpl.php';
93 if ($mode == 'confirm') {
94 dolSavePageAlias($filealias, $website, $websitepage);
95 dolSavePageContent($filetpl, $website, $websitepage);
96 }
97 print "Generation of page done - pageid = ".$websitepage->id." - ".$websitepage->pageurl."\n";
98 $nbgenerated++;
99
100 if ($max && $nbgenerated >= $max) {
101 print 'Nb max of record ('.$max.') reached. We stop now.'."\n";
102 break;
103 }
104}
105
106if ($mode == 'confirm') {
107 print $nbgenerated." page(s) generated into ".$pathofwebsite."\n";
108} else {
109 print $nbgenerated." page(s) found but not generated (test mode)\n";
110}
111
112exit($error);
Class Website.
Class Websitepage.
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).