diff --git a/app/Services/DictionaryImportService.php b/app/Services/DictionaryImportService.php index e280582c..124c9dd2 100644 --- a/app/Services/DictionaryImportService.php +++ b/app/Services/DictionaryImportService.php @@ -14,6 +14,7 @@ use App\Models\VocabularyJmdictReading; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\File; use League\Csv\Reader; class DictionaryImportService { @@ -21,6 +22,11 @@ class DictionaryImportService { public function __construct() { } + private function deleteTempDictionaryFiles() { + $tempDictionaryFiles = Storage::allFiles('temp/dictionaries'); + Storage::delete($tempDictionaryFiles); + } + /* Scans the /storage/app/dictionaries folder, and returns a list of importable dictionaries. @@ -28,13 +34,9 @@ public function __construct() { public function getImportableDictionaryList($supportedSourceLanguages, $dictCcLanguageCodes, $databaseLanguageCodes) { $dictionariesFound = []; $files = Storage::files('dictionaries'); - + // jmdict dictionary - if (Storage::exists('dictionaries/jmdict_processed.txt') && - Storage::exists('dictionaries/kanjidic2.xml') && - Storage::exists('dictionaries/radical-strokes.txt') && - Storage::exists('dictionaries/radicals.txt')) { - + if (Storage::exists('dictionaries/jmdict.zip')) { $dictionary = new \stdClass(); $dictionary->name = 'JMDict'; $dictionary->databaseName = 'dict_jp_jmdict'; @@ -44,7 +46,7 @@ public function getImportableDictionaryList($supportedSourceLanguages, $dictCcLa $dictionary->expectedRecordCount = 207690; $dictionary->firstUpdateInterval = 25000; $dictionary->updateInterval = 10000; - $dictionary->fileName = 'multiple files'; + $dictionary->fileName = 'jmdict.zip'; $dictionary->imported = false; // check if jmdict is imported @@ -675,7 +677,7 @@ public function importWiktionary($name, $language, $fileName, $databaseName) { public function kanjiRadicalImport() { // init DB::beginTransaction(); - $file = fopen(base_path() . '/storage/app/dictionaries/radicals.txt', 'r'); + $file = fopen(base_path() . '/storage/app/temp/dictionaries/radicals.txt', 'r'); $index = 0; // these kanjis has to be replaced with radicals @@ -710,7 +712,7 @@ public function kanjiRadicalImport() { DB::statement('DELETE FROM dict_jp_kanji_radicals'); // load radical stroke counts into an array - $radicalStrokesFiles = fopen(base_path() . '/storage/app/dictionaries/radical-strokes.txt', 'r'); + $radicalStrokesFiles = fopen(base_path() . '/storage/app/temp/dictionaries/radical-strokes.txt', 'r'); $radicalStrokeCountsData = []; while (($line = fgets($radicalStrokesFiles)) !== false) { @@ -759,6 +761,9 @@ public function kanjiRadicalImport() { // finish DB::commit(); + + // delete temp files + $this->deleteTempDictionaryFiles(); } /* @@ -776,7 +781,7 @@ public function kanjiImport() { $doc = new \DOMDocument(); $reader = new \XMLReader(); - $reader->open(base_path() . '/storage/app/dictionaries/kanjidic2.xml'); + $reader->open(base_path() . '/storage/app/temp/dictionaries/kanjidic2.xml'); $index = 0; DB::beginTransaction(); @@ -867,11 +872,29 @@ public function kanjiImport() { Imports jmdict dictionary file. */ public function jmdictImport() { - $file = fopen(base_path() . '/storage/app/dictionaries/jmdict_processed.txt', 'r'); DB::statement('DELETE FROM dict_jp_jmdict'); DB::statement('DELETE FROM dict_jp_jmdict_words'); DB::statement('DELETE FROM dict_jp_jmdict_readings'); + // extract zip file + $filePath = Storage::path('dictionaries/jmdict.zip'); + $extractPath = Storage::path('temp/dictionaries'); + + // delete all temp dictionary files + $this->deleteTempDictionaryFiles(); + + // extract jmdict.zip file + $zip = new \ZipArchive(); + $zipFile = $zip->open($filePath); + if ($zipFile === TRUE) { + $zip->extractTo($extractPath); + $zip->close(); + } else { + throw new \Exception('JMDict zip file could not be extracted.'); + } + + // import jmdict file + $file = fopen(base_path() . '/storage/app/temp/dictionaries/jmdict_processed.txt', 'r'); $index = 0; DB::beginTransaction(); while (($line = fgets($file)) !== false) { @@ -934,10 +957,10 @@ public function jmdictImport() { Converts jmdict to text. Should be moved to python. */ public function jmdictXmlToText() { - $file = fopen(base_path() . '/storage/app/dictionaries/jmdict.txt', 'w'); + $file = fopen(base_path() . '/storage/app/temp/dictionaries/jmdict.txt', 'w'); $doc = new \DOMDocument(); $reader = new \XMLReader(); - $reader->open(base_path() . '/storage/app/dictionaries/JMdict_e.xml'); + $reader->open(base_path() . '/storage/app/temp/dictionaries/JMdict_e.xml'); $index = 0; diff --git a/entrypoint-dev.sh b/entrypoint-dev.sh index 9a742611..b86bbb5b 100644 --- a/entrypoint-dev.sh +++ b/entrypoint-dev.sh @@ -6,7 +6,7 @@ folder_paths=" ./storage/app/fonts ./storage/app/images/book_images ./storage/app/public - ./storage/app/temp + ./storage/app/temp/dictionaries ./storage/framework/cache/data ./storage/framework/sessions ./storage/framework/testing diff --git a/entrypoint.sh b/entrypoint.sh index 396b85d8..0f954c86 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ folder_paths=" ./storage/app/fonts ./storage/app/images/book_images ./storage/app/public - ./storage/app/temp + ./storage/app/temp/dictionaries ./storage/framework/cache/data ./storage/framework/sessions ./storage/framework/testing diff --git a/resources/js/components/Admin/AdminDictionarySettings.vue b/resources/js/components/Admin/AdminDictionarySettings.vue index 6bd30a4f..5719f55c 100644 --- a/resources/js/components/Admin/AdminDictionarySettings.vue +++ b/resources/js/components/Admin/AdminDictionarySettings.vue @@ -59,6 +59,7 @@ :items="dictionaries" :loading="loading" :search="dictionaryTableFilter" + :items-per-page="9" > diff --git a/resources/js/components/Home/PatchNotes.vue b/resources/js/components/Home/PatchNotes.vue index c52ef158..a8a223bb 100644 --- a/resources/js/components/Home/PatchNotes.vue +++ b/resources/js/components/Home/PatchNotes.vue @@ -18,7 +18,7 @@ Bug fixes: