From ec56ff59d642b55fd6318cb1a3cca47d54d9ecd1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 22 Aug 2017 15:32:45 +0200 Subject: [PATCH] Fix invalid link after renaming a website key. --- htdocs/admin/websites.php | 37 +++++++++++++++++++++++++++++---- htdocs/core/lib/website.lib.php | 3 +++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index bab1cc0f80f..4f829db31df 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -247,6 +247,8 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha')) if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } else { $rowidcol="rowid"; } + $db->begin(); + $website=new Website($db); $rowid=GETPOST('rowid','int'); $website->fetch($rowid); @@ -281,14 +283,41 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha')) $newname = dol_sanitizeFileName(GETPOST('ref','aZ09')); if ($newname != $website->ref) { - $srcfile=DOL_DATA_ROOT.'/websites/'.$website->ref; - $destfile=DOL_DATA_ROOT.'/websites/'.$newname; - @rename($srcfile, $destfile); + $srcfile=DOL_DATA_ROOT.'/websites/'.$website->ref; + $destfile=DOL_DATA_ROOT.'/websites/'.$newname; + + if (dol_is_dir($destfile)) + { + $error++; + setEventMessages($langs->trans('ErrorDirAlreadyExists', $destfile), null, 'errors'); + } + else + { + @rename($srcfile, $destfile); + + // We must now rename $website->ref into $newname inside files + $arrayreplacement = array($website->ref.'/htmlheader.html' => $newname.'/htmlheader.html'); + $listofilestochange = dol_dir_list($destfile, 'files', 0, '\.php$'); + foreach ($listofilestochange as $key => $value) + { + dolReplaceInFile($value['fullname'], $arrayreplacement); + } + } } } else { - setEventMessages($db->error(), null, 'errors'); + $error++; + setEventMessages($db->lasterror(), null, 'errors'); + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); } } //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 2de1bfb4ecd..ca690f492c5 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -166,7 +166,10 @@ function dolIncludeHtmlContent($contentfile) } // TODO Remove body and html if included //$content = file_get_contents($fullpathfile); + //print preg_replace(array('/^.*]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ + + print "\n".''."\n"; $res = include $fullpathfile; // Include because we want to execute code content if (! $res) {