From 2bf74a9ad03074c0f4866fe3d53c763370c454d8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 26 May 2018 15:33:37 +0200 Subject: [PATCH] Background image is deleted on account deletion. --- classes/components/AccountComponent.php | 5 +++ classes/components/BackgroundImage.php | 48 +++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/classes/components/AccountComponent.php b/classes/components/AccountComponent.php index 47c0e94..38c74af 100644 --- a/classes/components/AccountComponent.php +++ b/classes/components/AccountComponent.php @@ -433,6 +433,9 @@ class AccountComponent { //Delete user account image if(!components()->accountImage->delete($userID)) return FALSE; + + if(!components()->backgroundImage->delete($userID)) + return FALSE; //Delete connections to all the services if(!$this->deleteAllUserLoginTokens($userID)) @@ -441,6 +444,8 @@ class AccountComponent { //Delete user from the database //WILL BE IMPLEMENTED WHEN LEGACY VERSION WILL BE REMOVED + exit("Notice: Account deletion should be available soon..."); + //Success return FALSE; } diff --git a/classes/components/BackgroundImage.php b/classes/components/BackgroundImage.php index 4c79626..f922f85 100644 --- a/classes/components/BackgroundImage.php +++ b/classes/components/BackgroundImage.php @@ -33,12 +33,12 @@ class BackgroundImage { /** * Returns the path of a background image * - * @param Integer $userID The ID of the user on which we perform research - * @return String The URL pointing on the background image + * @param int $userID The ID of the user on which we perform research + * @return string The URL pointing on the background image */ public function getPath(int $userID) : string { //First, check if the background image exists - $backgroundImageRefFile = $this->files_path."adresse_imgfond/".$userID.".txt"; + $backgroundImageRefFile = $this->getPathMetadata($userID); if(file_exists($backgroundImageRefFile)){ //Get background image path and return it @@ -51,6 +51,48 @@ class BackgroundImage { } } + /** + * Delete the account image of a user (if any) + * + * @param int $userID The ID of the target user + * @return bool TRUE for a success / FALSE else + */ + public function delete(int $userID) : bool { + + //Get the path to the background image + $refFile = $this->getPathMetadata($userID); + + //Check if ref file exists or not + if(file_exists($refFile)){ + + $file_target = $this->files_path.file_get_contents($refFile); + + //Delete file + if(file_exists($file_target)){ + if(!unlink($file_target)) + return FALSE; + } + + //Unlink reference file + return unlink($refFile); + + } + + //Nothing to be done + else + return TRUE; + + } + + /** + * Get the path to the file containing the path to the background image + * + * @param int $userID Target user ID + * @return string The path to the file + */ + private function getPathMetadata(int $userID) : string { + return $this->files_path."adresse_imgfond/".$userID.".txt"; + } } //Register class