|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FamilyTree365\LaravelGedcom\Utils; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
|
|
|
|
|
6
|
|
|
use FamilyTree365\LaravelGedcom\Models\Family; |
|
7
|
|
|
use FamilyTree365\LaravelGedcom\Models\Person; |
|
8
|
|
|
use Illuminate\Support\Str; |
|
|
|
|
|
|
9
|
|
|
use Throwable; |
|
10
|
|
|
|
|
11
|
|
|
class ParentData |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Array of persons ID |
|
15
|
|
|
* key - old GEDCOM ID |
|
16
|
|
|
* value - new autoincrement ID. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $persons_id = []; |
|
21
|
|
|
protected $subm_ids = []; |
|
22
|
|
|
protected $sour_ids = []; |
|
23
|
|
|
protected $obje_ids = []; |
|
24
|
|
|
protected $note_ids = []; |
|
25
|
|
|
protected $repo_ids = []; |
|
26
|
|
|
protected $conn = ''; |
|
27
|
|
|
|
|
28
|
|
|
public static function getPerson($conn, $individuals, $obje_ids = [], $sour_ids = []) |
|
29
|
|
|
{ |
|
30
|
|
|
$ParentData = []; |
|
|
|
|
|
|
31
|
|
|
$a = []; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
try { |
|
34
|
|
|
foreach ($individuals as $k => $individual) { |
|
35
|
|
|
$g_id = $individual->getId(); |
|
|
|
|
|
|
36
|
|
|
$name = ''; |
|
|
|
|
|
|
37
|
|
|
$givn = ''; |
|
|
|
|
|
|
38
|
|
|
$surn = ''; |
|
|
|
|
|
|
39
|
|
|
$name = ''; |
|
40
|
|
|
$npfx = ''; |
|
41
|
|
|
$givn = ''; |
|
42
|
|
|
$nick = ''; |
|
43
|
|
|
$spfx = ''; |
|
44
|
|
|
$surn = ''; |
|
45
|
|
|
$nsfx = ''; |
|
46
|
|
|
$type = ''; |
|
47
|
|
|
$fone = null; // Gedcom/ |
|
|
|
|
|
|
48
|
|
|
$romn = null; |
|
|
|
|
|
|
49
|
|
|
$names = $individual->getName(); |
|
50
|
|
|
$attr = $individual->getAllAttr(); |
|
51
|
|
|
$events = $individual->getAllEven(); |
|
|
|
|
|
|
52
|
|
|
$note = $individual->getNote(); |
|
|
|
|
|
|
53
|
|
|
$indv_sour = $individual->getSour(); |
|
|
|
|
|
|
54
|
|
|
$alia = $individual->getAlia(); // string array |
|
|
|
|
|
|
55
|
|
|
$asso = $individual->getAsso(); |
|
|
|
|
|
|
56
|
|
|
$subm = $individual->getSubm(); |
|
|
|
|
|
|
57
|
|
|
$anci = $individual->getAnci(); |
|
|
|
|
|
|
58
|
|
|
$refn = $individual->getRefn(); |
|
|
|
|
|
|
59
|
|
|
$obje = $individual->getObje(); |
|
|
|
|
|
|
60
|
|
|
// object |
|
61
|
|
|
$bapl = $individual->getBapl(); |
|
|
|
|
|
|
62
|
|
|
$conl = $individual->getConl(); |
|
|
|
|
|
|
63
|
|
|
$endl = $individual->getEndl(); |
|
|
|
|
|
|
64
|
|
|
$slgc = $individual->getSlgc(); |
|
|
|
|
|
|
65
|
|
|
$chan = $individual->getChan(); |
|
66
|
|
|
$g_id = $individual->getId(); |
|
67
|
|
|
|
|
68
|
|
|
if (!empty($names)) { |
|
69
|
|
|
$name = current($names)->getName() ?: ''; |
|
70
|
|
|
$npfx = current($names)->getNpfx() ?: ''; |
|
71
|
|
|
$givn = current($names)->getGivn() ?: ''; |
|
72
|
|
|
$nick = current($names)->getNick() ?: ''; |
|
73
|
|
|
$spfx = current($names)->getSpfx() ?: ''; |
|
74
|
|
|
$surn = current($names)->getSurn() ?: ''; |
|
75
|
|
|
$nsfx = current($names)->getNsfx() ?: ''; |
|
76
|
|
|
$type = current($names)->getType() ?: ''; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// array value |
|
80
|
|
|
$fams = $individual->getFams(); // self family, leave it now, note would be included in family |
|
81
|
|
|
$famc = $individual->getFamc(); // parent family , leave it now, note and pedi would be included in family |
|
82
|
|
|
|
|
83
|
|
|
// added to database |
|
84
|
|
|
// string value |
|
85
|
|
|
$sex = preg_replace('/[^MF]/', '', $individual->getSex()); |
|
86
|
|
|
$uid = $individual->getUid() ?? strtoupper(str_replace('-', '', Str::uuid())); |
|
87
|
|
|
$resn = $individual->getResn(); |
|
88
|
|
|
$rin = $individual->getRin(); |
|
89
|
|
|
$rfn = $individual->getRfn(); |
|
90
|
|
|
$afn = $individual->getAfn(); |
|
91
|
|
|
$titl = $individual->getAttr(); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$birt = $individual->getBirt(); |
|
94
|
|
|
$birthday = $birt->dateFormatted ?? null; |
|
95
|
|
|
|
|
96
|
|
|
$birth_month = $birt->month ?? null; |
|
97
|
|
|
$birth_year = $birt->year ?? null; |
|
98
|
|
|
$birthday_dati = $birt->dati ?? null; |
|
99
|
|
|
$birthday_plac = $birt->plac ?? null; |
|
100
|
|
|
|
|
101
|
|
|
$deat = $individual->getDeat(); |
|
102
|
|
|
$deathday = $deat->dateFormatted ?? null; |
|
103
|
|
|
$death_month = $deat->month ?? null; |
|
104
|
|
|
$death_year = $deat->year ?? null; |
|
105
|
|
|
$deathday_dati = $deat->dati ?? null; |
|
106
|
|
|
$deathday_plac = $deat->plac ?? null; |
|
107
|
|
|
$deathday_caus = $deat->caus ?? null; |
|
108
|
|
|
|
|
109
|
|
|
$buri = $individual->getBuri(); |
|
110
|
|
|
$burial_day = $buri->dateFormatted ?? null; |
|
111
|
|
|
$burial_month = $buri->month ?? null; |
|
112
|
|
|
$burial_year = $buri->year ?? null; |
|
113
|
|
|
$burial_day_dati = $buri->dati ?? null; |
|
114
|
|
|
$burial_day_plac = $buri->plac ?? null; |
|
115
|
|
|
|
|
116
|
|
|
$chr = $individual->getChr(); |
|
117
|
|
|
$chr = $chr->dateFormatted ?? null; |
|
118
|
|
|
|
|
119
|
|
|
if ($givn == '') { |
|
120
|
|
|
$givn = $name; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$config = json_encode(config('database.connections.'.$conn)); |
|
|
|
|
|
|
124
|
|
|
$value = [ |
|
125
|
|
|
'gid' => $g_id, |
|
126
|
|
|
'name' => utf8_encode($name), |
|
127
|
|
|
'givn' => utf8_encode($givn), |
|
128
|
|
|
'surn' => utf8_encode($surn), |
|
129
|
|
|
'sex' => $sex, |
|
130
|
|
|
'uid' => $uid, |
|
131
|
|
|
'rin' => $rin, |
|
132
|
|
|
'resn' => $resn, |
|
133
|
|
|
'rfn' => $rfn, |
|
134
|
|
|
'afn' => $afn, |
|
135
|
|
|
'nick' => $nick, |
|
136
|
|
|
'type' => $type, |
|
137
|
|
|
'chan' => $chan ? $chan->getDatetime() : null, |
|
138
|
|
|
'nsfx' => $nsfx, |
|
139
|
|
|
'npfx' => $npfx, |
|
140
|
|
|
'spfx' => $spfx, |
|
141
|
|
|
'birthday' => self::validateDate($birthday) ? $birthday : null, |
|
142
|
|
|
'birth_month' => $birth_month, |
|
143
|
|
|
'birth_year' => $birth_year, |
|
144
|
|
|
'birthday_dati' => utf8_encode($birthday_dati), |
|
|
|
|
|
|
145
|
|
|
'birthday_plac' => utf8_encode($birthday_plac), |
|
146
|
|
|
'deathday' => $deathday, |
|
147
|
|
|
'death_month' => $death_month, |
|
148
|
|
|
'death_year' => $death_year, |
|
149
|
|
|
'deathday_dati' => $deathday_dati, |
|
150
|
|
|
'deathday_plac' => utf8_encode($deathday_plac), |
|
151
|
|
|
'deathday_caus' => $deathday_caus, |
|
152
|
|
|
'burial_day' => $burial_day, |
|
153
|
|
|
'burial_month' => $burial_month, |
|
154
|
|
|
'burial_year' => $burial_year, |
|
155
|
|
|
'burial_day_dati' => $burial_day_dati, |
|
156
|
|
|
'burial_day_plac' => $burial_day_plac, |
|
157
|
|
|
'titl' => array_key_exists('TITL', $attr) ? $attr['TITL'][0]->getAttr('TITL') : null, |
|
158
|
|
|
'famc' => $famc ? $famc[0]->getFamc() : null, |
|
159
|
|
|
'fams' => $fams ? $fams[0]->getFams() : null, |
|
160
|
|
|
'chr' => $chr, |
|
161
|
|
|
]; |
|
162
|
|
|
|
|
163
|
|
|
$parentData[] = $value; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$chunk = array_chunk($parentData, 500); |
|
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
foreach ($chunk as $item) { |
|
169
|
|
|
// it's take only 1 second for 3010 record |
|
170
|
|
|
$a = Person::on($conn)->upsert($item, ['uid']); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
otherFields::insertOtherFields($conn, $individuals, $obje_ids, $sour_ids); |
|
174
|
|
|
|
|
175
|
|
|
return $parentData; |
|
176
|
|
|
} catch (\Exception $e) { |
|
177
|
|
|
return \Log::error($e); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
private static function validateDate($date, $format = 'Y-m-d') |
|
182
|
|
|
{ |
|
183
|
|
|
$d = \DateTime::createFromFormat($format, $date); |
|
184
|
|
|
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue. |
|
185
|
|
|
return $d && $d->format($format) === $date; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths