|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Gedcom; |
|
4
|
|
|
|
|
5
|
|
|
use App\Event; |
|
6
|
|
|
use App\Family; |
|
7
|
|
|
use App\Http\Controllers\Controller; |
|
8
|
|
|
use App\Jobs\ImportGedcom; |
|
9
|
|
|
use App\Note; |
|
10
|
|
|
use App\Person; |
|
11
|
|
|
use App\Source; |
|
12
|
|
|
use App\Traits\ConnectionTrait; |
|
13
|
|
|
use Auth; |
|
14
|
|
|
use Illuminate\Http\Request; |
|
15
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
16
|
|
|
use LaravelEnso\Multitenancy\Enums\Connections; |
|
17
|
|
|
use ModularSoftware\LaravelGedcom\Facades\GedcomParserFacade; |
|
18
|
|
|
use ModularSoftware\LaravelGedcom\Utils\GedcomParser; |
|
19
|
|
|
|
|
20
|
|
|
class Store extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
use ConnectionTrait; |
|
23
|
|
|
/* |
|
24
|
|
|
* Api end-point for Gedcom api/gedcom/store |
|
25
|
|
|
* Saving uploaded file to storage and starting to read |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
public function __invoke(Request $request) |
|
29
|
|
|
{ |
|
30
|
|
|
$slug = $request->get('slug'); |
|
31
|
|
|
if ($request->hasFile('file')) { |
|
32
|
|
|
if ($request->file('file')->isValid()) { |
|
33
|
|
|
try { |
|
34
|
|
|
$conn = $this->getConnection(); |
|
35
|
|
|
$db = $this->getDB(); |
|
36
|
|
|
$currentUser = Auth::user(); |
|
37
|
|
|
$_name = uniqid().'.ged'; |
|
38
|
|
|
$request->file->storeAs('gedcom', $_name); |
|
39
|
|
|
define('STDIN', fopen('php://stdin', 'r')); |
|
40
|
|
|
// $parser = new GedcomParser(); |
|
41
|
|
|
// $parser->parse($request->file('file'), $slug, true); |
|
42
|
|
|
$filename = 'app/gedcom/'.$_name; |
|
43
|
|
|
ImportGedcom::dispatch($filename, $slug, $currentUser->id, $conn, $db); |
|
|
|
|
|
|
44
|
|
|
// Artisan::call('queue:work'); |
|
45
|
|
|
return ['File uploaded']; |
|
46
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
47
|
|
|
return ['Not uploaded']; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return ['File corrupted']; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return ['Not uploaded']; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|