dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
26if (!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
35if (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
41define('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$error = 0;
44
45$mode = empty($argv[1]) ? '' : $argv[1];
46$websiteref = empty($argv[2]) ? '' : $argv[2];
47$max = (!isset($argv[3]) || (empty($argv[3]) && $argv[3] !== '0')) ? '10' : $argv[3];
48
49if (empty($argv[2]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) {
50 print '***** '.$script_file.' *****'."\n";
51 print "Usage: $script_file (test|confirm) website [nbmaxrecord]\n";
52 print "\n";
53 print "Regenerate all pages of a web site.\n";
54 exit(1);
55}
56
57require $path."../../htdocs/master.inc.php";
58require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
59include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
60include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
61include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
68$hookmanager->initHooks(array('cli'));
69
70
71/*
72 * Main
73 */
74
75$langs->load('main');
76
77if (!empty($dolibarr_main_db_readonly)) {
78 print "Error: instance in read-onyl mode\n";
79 exit(1);
80}
81
82$website = new Website($db);
83$result = $website->fetch(0, $websiteref);
84if ($result <= 0) {
85 print 'Error, web site '.$websiteref.' not found'."\n";
86 exit(1);
87}
88
89$websitepagestatic = new WebsitePage($db);
90
91$listofpages = $websitepagestatic->fetchAll($website->id, '', '', $max);
92
93global $dolibarr_main_data_root;
94$pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref;
95
96$nbgenerated = 0;
97foreach ($listofpages as $websitepage) {
98 $filealias = $pathofwebsite.'/'.$websitepage->pageurl.'.php';
99 $filetpl = $pathofwebsite.'/page'.$websitepage->id.'.tpl.php';
100 if ($mode == 'confirm') {
101 dolSavePageAlias($filealias, $website, $websitepage);
102 dolSavePageContent($filetpl, $website, $websitepage);
103 }
104 print "Generation of page done - pageid = ".$websitepage->id." - ".$websitepage->pageurl."\n";
105 $nbgenerated++;
106
107 if ($max && $nbgenerated >= $max) {
108 print 'Nb max of record ('.$max.') reached. We stop now.'."\n";
109 break;
110 }
111}
112
113if ($mode == 'confirm') {
114 print $nbgenerated." page(s) generated into ".$pathofwebsite."\n";
115} else {
116 print $nbgenerated." page(s) found but not generated (test mode)\n";
117}
118
119exit($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).