From aa1f60152898f4119366272ae3997579aa7f400a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Mar 2020 16:30:45 +0100 Subject: [PATCH] FIX Backto link --- htdocs/core/lib/website.lib.php | 1 - htdocs/core/lib/website2.lib.php | 1 + htdocs/website/index.php | 12 +++++++++++- .../website/migrate_news_joomla2dolibarr.php | 19 ++++++++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index bd46b975120..22c26b10b9b 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -21,7 +21,6 @@ * \brief Library for website module */ - /** * Remove PHP code part from a string. * diff --git a/htdocs/core/lib/website2.lib.php b/htdocs/core/lib/website2.lib.php index 89df263b026..e8c7e7006e3 100644 --- a/htdocs/core/lib/website2.lib.php +++ b/htdocs/core/lib/website2.lib.php @@ -113,6 +113,7 @@ function dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage) // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) dol_syslog("We regenerate the tpl page filetpl=".$filetpl); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; dol_delete_file($filetpl); $shortlangcode = ''; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index d514f3f9294..0ce0e2f1bbd 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -3642,10 +3642,20 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa // If mode WEBSITE_SUBCONTAINERSINLINE is on if (!empty($conf->global->WEBSITE_SUBCONTAINERSINLINE)) { + // TODO Check file $filephp exists, if not create it. + //var_dump($filetpl); $filephp = $filetpl; ob_start(); - include $filephp; + try { + $res = include $filephp; + if (empty($res)) { + print "ERROR: Failed to include file '".$filephp."'. Try to edit and save page."; + } + } catch(Exception $e) + { + print $e->getMessage(); + } $newcontent = ob_get_contents(); ob_end_clean(); } diff --git a/scripts/website/migrate_news_joomla2dolibarr.php b/scripts/website/migrate_news_joomla2dolibarr.php index 4c8b7c462fb..46721446d3b 100755 --- a/scripts/website/migrate_news_joomla2dolibarr.php +++ b/scripts/website/migrate_news_joomla2dolibarr.php @@ -54,6 +54,8 @@ if (empty($argv[3]) || !in_array($argv[1], array('test', 'confirm')) || empty($w 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'); @@ -95,7 +97,7 @@ if (! $resql) { $db->begin(); -$i = 0; +$i = 0; $nbimported = 0; $nbalreadyexists = 0; while ($obj = $dbjoomla->fetch_object($resql)) { if ($obj) { $i++; @@ -129,10 +131,23 @@ while ($obj = $dbjoomla->fetch_object($resql)) { print 'ERROR: '.$db->lasterrno.": ".$sqlinsert."\n"; if ($db->lasterrno != 'DB_ERROR_RECORD_ALREADY_EXISTS') { $error++; + } else { + $nbalreadyexists++; } } else { $pageid = $db->last_insert_id(MAIN_DB_PREFIX.'website_page'); + + if ($pageid > 0) { // We must also regenerate page on disk + global $dolibarr_main_data_root; + $pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteref; + $filetpl = $pathofwebsite.'/page'.$pageid.'.tpl.php'; + $websitepage = new WebsitePage($db); + $websitepage->fetch($pageid); + dolSavePageContent($filetpl, $website, $websitepage); + } + print "Insert done - pageid = ".$pageid."\n"; + $nbimported++; } if ($max && $i >= $max) { @@ -144,6 +159,8 @@ while ($obj = $dbjoomla->fetch_object($resql)) { if ($mode == 'confirm' && ! $error) { print "Commit\n"; + print $nbalreadyexists." page(s) already exists.\n"; + print $nbimported." page(s) imported with importid=".$importid."\n"; $db->commit(); } else { print "Rollback\n";