dolibarr 21.0.0-alpha
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";
57require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
58include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
59include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
60include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
61
62$hookmanager->initHooks(array('cli'));
63
64
65/*
66 * Main
67 */
68
69$langs->load('main');
70
71if (!empty($dolibarr_main_db_readonly)) {
72 print "Error: instance in read-onyl mode\n";
73 exit(1);
74}
75
76$website = new Website($db);
77$result = $website->fetch(0, $websiteref);
78if ($result <= 0) {
79 print 'Error, web site '.$websiteref.' not found'."\n";
80 exit(1);
81}
82
83$websitepagestatic = new WebsitePage($db);
84
85$listofpages = $websitepagestatic->fetchAll($website->id, '', '', $max);
86
87global $dolibarr_main_data_root;
88$pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref;
89
90$nbgenerated = 0;
91foreach ($listofpages as $websitepage) {
92 $filealias = $pathofwebsite.'/'.$websitepage->pageurl.'.php';
93 $filetpl = $pathofwebsite.'/page'.$websitepage->id.'.tpl.php';
94 if ($mode == 'confirm') {
95 dolSavePageAlias($filealias, $website, $websitepage);
96 dolSavePageContent($filetpl, $website, $websitepage);
97 }
98 print "Generation of page done - pageid = ".$websitepage->id." - ".$websitepage->pageurl."\n";
99 $nbgenerated++;
100
101 if ($max && $nbgenerated >= $max) {
102 print 'Nb max of record ('.$max.') reached. We stop now.'."\n";
103 break;
104 }
105}
106
107if ($mode == 'confirm') {
108 print $nbgenerated." page(s) generated into ".$pathofwebsite."\n";
109} else {
110 print $nbgenerated." page(s) found but not generated (test mode)\n";
111}
112
113exit($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).