Fix invalid link after renaming a website key.

This commit is contained in:
Laurent Destailleur 2017-08-22 15:32:45 +02:00
parent 109e0f7179
commit ec56ff59d6
2 changed files with 36 additions and 4 deletions

View File

@ -247,6 +247,8 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha'))
if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; } if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
else { $rowidcol="rowid"; } else { $rowidcol="rowid"; }
$db->begin();
$website=new Website($db); $website=new Website($db);
$rowid=GETPOST('rowid','int'); $rowid=GETPOST('rowid','int');
$website->fetch($rowid); $website->fetch($rowid);
@ -281,14 +283,41 @@ if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha'))
$newname = dol_sanitizeFileName(GETPOST('ref','aZ09')); $newname = dol_sanitizeFileName(GETPOST('ref','aZ09'));
if ($newname != $website->ref) if ($newname != $website->ref)
{ {
$srcfile=DOL_DATA_ROOT.'/websites/'.$website->ref; $srcfile=DOL_DATA_ROOT.'/websites/'.$website->ref;
$destfile=DOL_DATA_ROOT.'/websites/'.$newname; $destfile=DOL_DATA_ROOT.'/websites/'.$newname;
@rename($srcfile, $destfile);
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 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 //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition

View File

@ -166,7 +166,10 @@ function dolIncludeHtmlContent($contentfile)
} }
// TODO Remove body and html if included // TODO Remove body and html if included
//$content = file_get_contents($fullpathfile); //$content = file_get_contents($fullpathfile);
//print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
print "\n".'<!-- include '.$fullpathfile.' level = '.$includehtmlcontentopened.' -->'."\n";
$res = include $fullpathfile; // Include because we want to execute code content $res = include $fullpathfile; // Include because we want to execute code content
if (! $res) if (! $res)
{ {