argument("path")); $service = new DirService(); $list = $service->recursiveScan($path); if (isset($list["files"]) && count($list["files"]) > 0) { $toInsert = []; $i = 0; foreach ($list["files"] as $file) { if (strstr($file, ".DS_Store")) { continue; } $fileInfo = pathinfo($file); try { $innerPath = str_replace($path, "", $fileInfo["dirname"]); $innerName = $fileInfo["basename"]; $toInsert[] = ["path" => $innerPath, "name" => $innerName, "type" => 2, "created_at" => date("Y-m-d h:i:s")]; if (count($toInsert) == 100) { DB::table("image_records")->insertOrIgnore($toInsert); $toInsert = []; } // ImageRecord::firstOrCreate(["path" => $innerPath, "name" => $innerName], // ["path" => $innerPath, // "name" => $innerName, // "type" => 2 // ] // ); } catch (QueryException $e) { if (!str_contains($e->getMessage(), "Duplicate entry")) { Log::error($e->getMessage()); } } unset($imageRecord); } if (count($toInsert) > 0) { DB::table("image_records")->insertOrIgnore($toInsert); } } foreach ($list["dirs"] as $dir) { if (strstr($dir, ".DS_Store") || $dir == ".." || $dir == "." || str_starts_with($dir, ".")) { continue; } try { ImageRecord::firstOrCreate(["path" => $path, "name" => $dir], ["path" => $path, "name" => $dir, "type" => 1 ] ); } catch (QueryException $e) { if (!str_contains($e->getMessage(), "Duplicate entry")) { Log::error($e->getMessage()); } } } } }