dolibarr 23.0.3
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 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27if (!defined('NOSESSION')) {
28 define('NOSESSION', '1');
29}
30
31$sapi_type = php_sapi_name();
32$script_file = basename(__FILE__);
33$path = __DIR__.'/';
34
35// Test if batch mode
36if (substr($sapi_type, 0, 3) == 'cgi') {
37 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
38 exit(1);
39}
40
41@set_time_limit(0); // No timeout for this script
42define('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".
43
44$error = 0;
45
46$mode = empty($argv[1]) ? '' : $argv[1];
47$websiteref = empty($argv[2]) ? '' : $argv[2];
48$max = (int) ((!isset($argv[3]) || (empty($argv[3]) && $argv[3] !== '0')) ? '10' : $argv[3]);
49
50if (empty($argv[2]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) {
51 print '***** '.$script_file.' *****'."\n";
52 print "Usage: $script_file (test|confirm) website [nbmaxrecord]\n";
53 print "\n";
54 print "Regenerate all pages of a web site.\n";
55 exit(1);
56}
57
58require $path."../../htdocs/master.inc.php";
59require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
60include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
61include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
62include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php';
69$hookmanager->initHooks(array('cli'));
70
71
72/*
73 * Main
74 */
75
76$langs->load('main');
77
78if (!empty($dolibarr_main_db_readonly)) {
79 print "Error: instance in read-onyl mode\n";
80 exit(1);
81}
82
83$website = new Website($db);
84$result = $website->fetch(0, $websiteref);
85if ($result <= 0) {
86 print 'Error, web site '.$websiteref.' not found'."\n";
87 exit(1);
88}
89
90$websitepagestatic = new WebsitePage($db);
91
92$listofpages = $websitepagestatic->fetchAll($website->id, '', '', $max);
93
94global $dolibarr_main_data_root;
95$pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref;
96
97$nbgenerated = 0;
98foreach ($listofpages as $websitepage) {
99 $filealias = $pathofwebsite.'/'.$websitepage->pageurl.'.php';
100 $filetpl = $pathofwebsite.'/page'.$websitepage->id.'.tpl.php';
101 if ($mode == 'confirm') {
102 dolSavePageAlias($filealias, $website, $websitepage);
103 dolSavePageContent($filetpl, $website, $websitepage);
104 }
105 print "Generation of page done - pageid = ".$websitepage->id." - ".$websitepage->pageurl."\n";
106 $nbgenerated++;
107
108 if ($max && $nbgenerated >= $max) {
109 print 'Nb max of record ('.$max.') reached. We stop now.'."\n";
110 break;
111 }
112}
113
114if ($mode == 'confirm') {
115 print $nbgenerated." page(s) generated into ".$pathofwebsite."\n";
116} else {
117 print $nbgenerated." page(s) found but not generated (test mode)\n";
118}
119
120exit($error);
Class Website.
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).