fix website purge function

This commit is contained in:
Mohamed DAOUD
2025-01-07 12:27:56 +01:00
parent bd8a839d3e
commit 75f23fca52

View File

@@ -662,7 +662,7 @@ class Website extends CommonObject
*/
public function purge(User $user)
{
global $conf;
global $conf, $langs;
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -684,8 +684,22 @@ class Website extends CommonObject
if (!$error && !empty($this->ref)) {
$pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$this->ref;
// Delete content of website directory without deleting the website directory
dol_delete_dir_recursive($pathofwebsite, 0, 0, 1);
dol_delete_dir_recursive($pathofwebsite);
// Check symlink documents/website/mywebsite/medias to point to documents/medias and restore it if ko.
// Recreate also dir of website if not found.
$pathtomedias = DOL_DATA_ROOT.'/medias';
$pathtomediasinwebsite = $pathofwebsite.'/medias';
if (!is_link(dol_osencode($pathtomediasinwebsite))) {
dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure that the directory for website exists
$result = symlink($pathtomedias, $pathtomediasinwebsite);
if (!$result) {
$this->errors[] = $langs->trans("ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias);
$error++;
}
}
}
// Commit or rollback