familytree365 /
backend
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers; |
||
| 4 | |||
| 5 | use App\Jobs\ImportGedcom; |
||
| 6 | use App\Models\ImportJob; |
||
| 7 | use Illuminate\Http\Request; |
||
| 8 | use Spatie\Multitenancy\Models\Concerns\UsesLandlordConnection; |
||
| 9 | |||
| 10 | class GedcomController extends Controller |
||
| 11 | { |
||
| 12 | use UsesLandlordConnection; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Store a newly created resource in storage. |
||
| 16 | * |
||
| 17 | * @param \Illuminate\Http\Request $request |
||
| 18 | * @return \Illuminate\Http\Response |
||
| 19 | */ |
||
| 20 | public function store(Request $request) |
||
| 21 | { |
||
| 22 | $slug = ''; |
||
| 23 | if ($request->hasFile('file')) { |
||
| 24 | if ($request->file('file')->isValid()) { |
||
| 25 | try { |
||
| 26 | $conn = 'tenant'; |
||
| 27 | $currentTenant = app('currentTenant'); |
||
| 28 | $db = $currentTenant->database; |
||
| 29 | $currentUser = auth()->user(); |
||
| 30 | $_name = uniqid().'.ged'; |
||
| 31 | $request->file->storeAs('gedcom', $_name); |
||
| 32 | define('STDIN', fopen('php://stdin', 'r')); |
||
| 33 | // $parser = new GedcomParser(); |
||
| 34 | // $parser->parse($request->file('file'), $slug, true); |
||
| 35 | $filename = 'app/gedcom/'.$_name; |
||
| 36 | ImportGedcom::dispatch($filename, $slug, $currentUser->id, $conn, $db); |
||
| 37 | |||
| 38 | return ['File uploaded: conn:-'.$conn.'-']; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 39 | } catch (\Exception $e) { |
||
| 40 | return ['Not uploaded']; |
||
|
0 ignored issues
–
show
|
|||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | return ['File corrupted']; |
||
|
0 ignored issues
–
show
|
|||
| 45 | } |
||
| 46 | |||
| 47 | return ['Not uploaded']; |
||
|
0 ignored issues
–
show
|
|||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Display the specified progress. |
||
| 52 | */ |
||
| 53 | public function progress() |
||
| 54 | { |
||
| 55 | $user_id = Auth::user()->id; |
||
| 56 | $runningjob = ImportJob::orderby('id', 'DESC')->first(); |
||
| 57 | $slug = null; |
||
| 58 | if ($runningjob != null) { |
||
| 59 | $slug = $runningjob->slug; |
||
| 60 | } |
||
| 61 | $ret = []; |
||
| 62 | $ret['slug'] = $slug; |
||
| 63 | $ret['user'] = $user_id; |
||
| 64 | |||
| 65 | return $ret; |
||
| 66 | } |
||
| 67 | } |
||
| 68 |