From 75f23fca524037892ea1f01f32a5cee6db7a0cd7 Mon Sep 17 00:00:00 2001 From: Mohamed DAOUD Date: Tue, 7 Jan 2025 12:27:56 +0100 Subject: [PATCH] fix website purge function --- htdocs/website/class/website.class.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index 2f59aa95bcb..66f3da97ced 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -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