From 0f52d80ca67a49258b235f5831163dd72fbd54cf Mon Sep 17 00:00:00 2001 From: Frankie B Date: Tue, 11 Jun 2024 18:02:01 +0100 Subject: Merge MVC rewrite into master (#21) * Just commit it all * Require auth * crap * Update homepage * Block AI scrapers * Update cache update script * Add dummy file * Remove unnecessary lastfm config var * Use withQueryParameters for LastFM API * Fix embeds * Update example env * Smard --- app/Http/Controllers/AdminImportController.php | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/Http/Controllers/AdminImportController.php (limited to 'app/Http/Controllers/AdminImportController.php') diff --git a/app/Http/Controllers/AdminImportController.php b/app/Http/Controllers/AdminImportController.php new file mode 100644 index 0000000..dc32cec --- /dev/null +++ b/app/Http/Controllers/AdminImportController.php @@ -0,0 +1,69 @@ +validate([ + 'data_file' => 'required|mimes:json', + ]); + + $file = $request->file('data_file'); + $jsonContent = file_get_contents($file->getRealPath()); + $data = json_decode($jsonContent, true); + $tables = []; + foreach($data as $item) { + if ($item['type'] !== "table") continue; + $tables[$item['name']] = [ + 'data' => $item['data'], + 'count' => count($item['data']) + ]; + + if ($item['name'] === "guestbook__entries") { + GuestbookEntry::importGuestbookEntry($item['data']); + } + $this->import($item['data'], $item['name']); + } + return view('admin.import-success', ['tables' => $tables]); + } + + /** + * Imports the given data to the specified table + * + * @param array $data The data to import + * @param string $table_name The name of the table to import to + * @return void + * @throws Exception Invalid table specified, to be replaced with custom exception + */ + public function import(array $data, string $table_name): void { + switch ($table_name) { + case 'guestbook__entries': + GuestbookEntry::importGuestbookEntry($data); + break; + case 'bookmark__categories' : + BookmarkCategory::importBookmarkCategory($data); + break; + case 'bookmark__sites': + BookmarkSite::importBookmark($data); + break; + case 'guestbook__bans': + break; + default: + // TODO: Replace with custom exception + throw new Exception("Invalid table specified ($table_name)"); + } + } +} -- cgit v1.2.3-54-g00ecf