diff --git a/htdocs/core/lib/website2.lib.php b/htdocs/core/lib/website2.lib.php index e8c7e7006e3..78b9923d82d 100644 --- a/htdocs/core/lib/website2.lib.php +++ b/htdocs/core/lib/website2.lib.php @@ -49,7 +49,8 @@ function dolSaveMasterFile($filemaster) } /** - * Save content of a page on disk + * Save content of a page on disk. + * It can save file into root directory or into language subdirectory. * * @param string $filealias Full path of filename to generate * @param Website $object Object website @@ -98,7 +99,8 @@ function dolSavePageAlias($filealias, $object, $objectpage) /** - * Save content of a page on disk + * Save content of a page on disk. + * Page contents are always saved into root directory. * * @param string $filetpl Full path of filename to generate * @param Website $object Object website diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index 275df563c53..ed82a4aa43e 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -353,7 +353,7 @@ class Website extends CommonObject /** - * Load object in memory from the database + * Load all object in memory ($this->records) from the database * * @param string $sortorder Sort Order * @param string $sortfield Sort field diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index 516640d15fb..7d1f345d8c2 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -282,7 +282,7 @@ class WebsitePage extends CommonObject } /** - * Load list of objects in memory from the database. + * Return array of all web site pages. * * @param string $websiteid Web site * @param string $sortorder Sort Order diff --git a/scripts/website/migrate_news_joomla2dolibarr.php b/scripts/website/migrate_news_joomla2dolibarr.php index ded2e6f1903..e9f6c3c2295 100755 --- a/scripts/website/migrate_news_joomla2dolibarr.php +++ b/scripts/website/migrate_news_joomla2dolibarr.php @@ -17,7 +17,7 @@ */ /** - * \file scripts/website/migrate_newsèjoomla2dolibarr.php + * \file scripts/website/migrate_news_joomla2dolibarr.php * \ingroup scripts * \brief Migrate news from a Joomla databse into a Dolibarr website */ @@ -42,7 +42,7 @@ $websiteref = empty($argv[2])?'':$argv[2]; $joomlaserverinfo = empty($argv[3])?'':$argv[3]; $image = 'image/__WEBSITE_KEY__/images/stories/dolibarr.png'; -$max = (empty($argv[4]) && $argv[4] !== '0')?'10':$argv[4]; +$max = (!isset($argv[4]) || (empty($argv[4]) && $argv[4] !== '0'))?'10':$argv[4]; if (empty($argv[3]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) { print '***** '.$script_file.' *****'."\n"; diff --git a/scripts/website/regenerate_pages.php b/scripts/website/regenerate_pages.php new file mode 100755 index 00000000000..8ce78e0082d --- /dev/null +++ b/scripts/website/regenerate_pages.php @@ -0,0 +1,97 @@ +#!/usr/bin/env php + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file scripts/website/regenerate_pages.php + * \ingroup scripts + * \brief Regenerate all pages of a web site + */ + +$sapi_type = php_sapi_name(); +$script_file = basename(__FILE__); +$path = __DIR__.'/'; + +// Test if batch mode +if (substr($sapi_type, 0, 3) == 'cgi') { + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit(-1); +} + +@set_time_limit(0); // No timeout for this script +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". + +$error = 0; + +$mode = empty($argv[1])?'':$argv[1]; +$websiteref = empty($argv[2])?'':$argv[2]; +$max = (!isset($argv[3]) || (empty($argv[3]) && $argv[3] !== '0'))?'10':$argv[3]; + +if (empty($argv[2]) || !in_array($argv[1], array('test', 'confirm')) || empty($websiteref)) { + print '***** '.$script_file.' *****'."\n"; + print "Usage: $script_file (test|confirm) website [nbmaxrecord]\n"; + print "\n"; + print "Regenerate all pages of a web site.\n"; + exit(-1); +} + +require $path."../../htdocs/master.inc.php"; +include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php'; +include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; +include_once DOL_DOCUMENT_ROOT.'/core/lib/website2.lib.php'; + +$langs->load('main'); + +$website = new Website($db); +$result = $website->fetch(0, $websiteref); +if ($result <= 0) { + print 'Error, web site '.$websiteref.' not found'."\n"; + exit(-1); +} + +$websitepagestatic = new WebsitePage($db); + +$db->begin(); + +$listofpages = $websitepagestatic->fetchAll($website->id, '', $max); + +$nbgenerated = 0; +foreach($listofpages as $websitepage) { + global $dolibarr_main_data_root; + $pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref; + $filealias = $pathofwebsite.'/'.$websitepage->pageurl.'.php'; + $filetpl = $pathofwebsite.'/page'.$websitepage->id.'.tpl.php'; + if ($mode == 'confirm') { + dolSavePageAlias($filealias, $website, $websitepage); + dolSavePageContent($filetpl, $website, $websitepage); + } + print "Generation of page done - pageid = ".$websitepage->id." - ".$websitepage->pageurl."\n"; + $nbgenerated++; + + if ($max && $nbgenerated >= $max) { + print 'Nb max of record ('.$max.') reached. We stop now.'."\n"; + break; + } +} + +if ($mode == 'confirm') { + print $nbgenerated." page(s) generated\n"; +} else { + print $nbgenerated." page(s) found but not generated (test mode)\n"; +} + +exit($error);