A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
fix deletion error
aminnausinb9c58724c77e
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.phpindex b00bc8ef..885379c4 100644--- a/app/Jobs/IndexFiles.php+++ b/app/Jobs/IndexFiles.php@@ -72,10 +72,16 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique#endregion$dbOut = "";+$categoryTransactions = array();$folderTransactions = array();$videoTransactions = array();+ $categoryDeletions = array();+ $folderDeletions = array();+ $videoDeletions = array();++foreach ($categories as $categoryChange){ // for each in stored, remove from new (delete)$changeID = $categoryChange['id'];$changeName = $categoryChange["name"];@@ -90,8 +96,8 @@ class IndexFiles implements ShouldQueue, ShouldBeUniquearray_push($categoryTransactions, $transaction);}else{- $dbOut .= "DELETE FROM [Categories] WHERE [Categories].[ID] = $changeID;\n";- Category::where('id', $changeID)->delete();+ $dbOut .= "DELETE FROM [Categories] WHERE [Categories].[ID] = {$changeID};\n";+ array_push($categoryDeletions, $changeID);}}@@ -110,8 +116,8 @@ class IndexFiles implements ShouldQueue, ShouldBeUniquearray_push($folderTransactions, $transaction);}else{- $dbOut .= "DELETE FROM [Folders] WHERE [Folder].[ID] = {$changeID};";- Folder::where('id', $changeID)->delete();+ $dbOut .= "DELETE FROM [Folders] WHERE [Folder].[ID] = {$changeID};\n";+ array_push($folderDeletions, $changeID);}}@@ -131,8 +137,8 @@ class IndexFiles implements ShouldQueue, ShouldBeUniquearray_push($videoTransactions, $transaction);}else{- $dbOut .= "DELETE FROM [Videos] WHERE [Categories].[ID] = {$changeID};\n";- Video::where('id', $changeID)->delete();+ $dbOut .= "DELETE FROM [Videos] WHERE [Video].[ID] = {$changeID};\n";+ array_push($videoDeletions, $changeID);}}@@ -144,10 +150,14 @@ class IndexFiles implements ShouldQueue, ShouldBeUniqueFolder::insert($folderTransactions);Video::insert($videoTransactions);+ Video::destroy($videoDeletions);+ Folder::destroy($folderDeletions);+ Category::destroy($categoryDeletions);+$data = array("categories"=>$categories,"folders"=>$folders,"videos"=>$videos);Storage::disk('public')->put('dataCache.json', json_encode($data, JSON_UNESCAPED_SLASHES));- dump($directories, $subDirectories, $files, $data, $dbOut);+ dump('Directories | Sub Directories | Files | Data | dbOut', $directories, $subDirectories, $files, $data, $dbOut);}private function generateCategories($path){@@ -213,12 +223,11 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique$changes = array(); // send to db$current = array(); // save into json into json- // foreach ($stored as $savedFolder){ // O(n) where n = number of already known categories- // $currentID = max($currentID, $savedFolder["id"] + 1); // gets max currently used id- // $cost ++;- // }-- /*+ /*+ foreach ($stored as $savedFolder){ // O(n) where n = number of already known categories+ $currentID = max($currentID, $savedFolder["id"] + 1); // gets max currently used id+ $cost ++;+Double Foreach loopo(M*N) where M = number of categories and N = number of files in each category@@ -238,7 +247,9 @@ class IndexFiles implements ShouldQueue, ShouldBeUniqueadd to current -> key, id, basename(folder) ?add to changes (insert)id += 1;+ }*/+foreach ($scannedCategories as $category) { // O(n) where n = number of folders * 2 (for scan)$cost++;@@ -265,18 +276,12 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique}}-- foreach ($stored as $remainingID){- $generated = array("id"=>$remainingID,"name"=>null,"path"=>null, "category_id"=>null, "action"=>"DELETE"); // delete by id+ foreach ($stored as $remainingFolder){+ $generated = array("id"=>$remainingFolder['id'],"name"=>null,"path"=>null, "category_id"=>null, "action"=>"DELETE"); // delete by id -> Used to store just ID -> Now store id and last_scanarray_push($changes, $generated); // add to new (delete)$cost++;}-- // if($current !== $storedCopy) {- // //Storage::disk('public')->put('folders.json', json_encode($current, JSON_UNESCAPED_SLASHES));- // }-$data["next_ID"] = $currentID;$data["folderStructure"] = $current;return array("folderChanges"=> $changes, "data" => $data, "cost"=>$cost);