Passed
Branch beta (1b8e35)
by Jon
07:16
created

SyncProduction::UpdateMatchingVocabulary()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 33
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 29
nc 6
nop 3
1
<?php
2
3
namespace App\Jobs;
4
5
use App\Models\Access\User\User as betaUser;
6
use App\Models\Elementset;
7
use App\Models\ElementsetUser;
8
use App\Models\Import as betaImport;
9
use App\Models\Omr\Agent;
10
use App\Models\Omr\AgentUser;
11
use App\Models\Omr\Import as omrImport;
12
use App\Models\Omr\Schema;
13
use App\Models\Omr\SchemaUser;
14
use App\Models\Omr\User as omrUser;
15
use App\Models\Omr\Vocabulary as omrVocabulary;
16
use App\Models\Omr\VocabularyUser as omrVocabularyUser;
17
use App\Models\Project;
18
use App\Models\ProjectUser;
19
use App\Models\Vocabulary as betaVocabulary;
20
use App\Models\VocabularyUser as betaVocabularyUser;
21
use Illuminate\Bus\Queueable;
22
use Illuminate\Contracts\Queue\ShouldQueue;
23
use Illuminate\Foundation\Bus\Dispatchable;
24
use Illuminate\Queue\InteractsWithQueue;
25
use Illuminate\Queue\SerializesModels;
26
use Illuminate\Support\Carbon;
27
use Illuminate\Support\Facades\Cache;
28
29
class SyncProduction implements ShouldQueue
30
{
31
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
32
    private $firstRun;
33
    private $lastRunTimestamp;
34
35
    /**
36
     * Create a new job instance.
37
     *
38
     * @param $firstRun
39
     */
40
    public function __construct(bool $firstRun)
41
    {
42
        ob_implicit_flush(1);
43
44
        $this->firstRun = $firstRun;
45
        if (! $this->firstRun) {
46
            Cache::forget('last_run_timestamp');
47
        }
48
49
        //set last run to 0 if it wasn't cached
50
        $this->lastRunTimestamp = Cache::get('last_run_timestamp',
51
            function () {
1 ignored issue
show
Unused Code introduced by
The call to Illuminate\Cache\CacheManager::get() has too many arguments starting with function(...) { /* ... */ }. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        /** @scrutinizer ignore-call */ 
52
        $this->lastRunTimestamp = Cache::get('last_run_timestamp',

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
52
                return Carbon::createFromTimestamp(0)->toDateTimeString();
53
            });
54
    }
55
56
    /**
57
     * Execute the job.
58
     *
59
     * @return void
60
     */
61
    public function handle()
62
    {
63
        //for each table in the list:
64
        /*
65
         * user
66
         * reg_agent
67
         * reg_agent_has_user
68
         * reg_vocabulary_has_user
69
         * reg_schema
70
         * schema_has_user
71
         * reg_file_import_history
72
         * reg_vocabulary
73
         */
74
75
        //***************
76
        // MUST DO A ONE-WAY UPDATE OF BETA FROM PRODUCTION ONCE BEFORE RUNNING
77
        //***************
78
        $this->updateUsers();
79
        $this->updateAgents();
80
        $this->updateAgentUsers();
81
        $this->updateVocabularies();
82
        $this->updateVocabularyUsers();
83
        $this->updateSchema();
84
        $this->updateSchemaUsers();
85
        $this->updateImportHistory();
86
87
        /* for each history table
88
         * reg-concept_property_history
89
         * reg_schema_property_element_history
90
         * open the beta table and get the date of last created date
91
         * open the omr table and get everything created newer than the last beta update
92
         * step through the history and create or update the concept and schema_property tables
93
         * reg_concept
94
         * reg_schema_property
95
         *  ...and write it to beta
96
         * and then
97
         * reg_concept_property
98
         * reg_schema_property_element
99
         */
100
        Cache::rememberForever('last_run_timestamp',
101
            function () {
102
                return now()->toDateTimeString();
103
            });
104
    }
105
106
    private function updateUsers(): void
107
    {
108
        $betaUsers = betaUser::where('updated_at', '>', $this->lastRunTimestamp)->get();
109
        foreach ($betaUsers as $betaUser) {
110
            echo $betaUser->id . ', ';
111
            $omrUser = omrUser::withTrashed()->find($betaUser->id);
112
            if ($omrUser) {
113
                //if it's the first run, then we always update beta
114
                if ($this->firstRun || $omrUser->last_updated->gt($betaUser->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

114
                if ($this->firstRun || $omrUser->last_updated->/** @scrutinizer ignore-call */ gt($betaUser->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
115
                    $betaUser->deleted_at        = $omrUser->deleted_at;
116
                    $betaUser->nickname          = $omrUser->nickname;
117
                    $betaUser->name              = $omrUser->nickname;
118
                    $betaUser->salutation        = $omrUser->salutation;
119
                    $betaUser->first_name        = $omrUser->first_name;
120
                    $betaUser->last_name         = $omrUser->last_name;
121
                    $betaUser->email             = $omrUser->email;
122
                    $betaUser->confirmation_code = $betaUser->confirmation_code ?? md5($omrUser->sha1_password . $omrUser->salt);
123
                    if ($betaUser->isDirty()) {
124
                        $betaUser->updated_at = $omrUser->last_updated;
125
                        $betaUser->save();
126
                    }
127
                }
128
                if (! $this->firstRun && $betaUser->updated_at->gt($omrUser->last_updated)) {
129
                    $omrUser->deleted_at = $betaUser->deleted_at;
130
                    $omrUser->nickname   = $betaUser->nickname;
131
                    $omrUser->salutation = $betaUser->salutation;
132
                    $omrUser->first_name = $betaUser->first_name;
133
                    $omrUser->last_name  = $betaUser->last_name;
134
                    $omrUser->email      = $betaUser->email;
135
                    if ($omrUser->isDirty()) {
136
                        $omrUser->last_updated = $betaUser->updated_at;
137
                        $omrUser->save();
138
                    }
139
                }
140
            } else { //we have a betaUser that doesn't exist in the OMR
141
                $omrUser               = new omrUser();
142
                $omrUser->id           = $betaUser->id;
143
                $omrUser->created_at   = $betaUser->created_at;
144
                $omrUser->last_updated = $betaUser->updated_at;
145
                $omrUser->deleted_at   = $betaUser->deleted_at;
146
                $omrUser->nickname     = $betaUser->nickname;
147
                $omrUser->salutation   = $betaUser->salutation;
148
                $omrUser->first_name   = $betaUser->first_name;
149
                $omrUser->last_name    = $betaUser->last_name;
150
                $omrUser->email        = $betaUser->email;
151
                $omrUser->save();
152
            }
153
        }
154
        $betaId   = betaUser::latest()->first()->id;
155
        $omrUsers = omrUser::where('id', '>', $betaId)->get();
156
        foreach ($omrUsers as $omrUser) {
157
            $betaUser                    = new betaUser();
158
            $betaUser->id                = $omrUser->id;
159
            $betaUser->created_at        = $omrUser->created_at;
160
            $betaUser->updated_at        = $omrUser->last_updated;
161
            $betaUser->deleted_at        = $omrUser->deleted_at;
162
            $betaUser->nickname          = $omrUser->nickname;
163
            $betaUser->name              = $omrUser->nickname;
164
            $betaUser->salutation        = $omrUser->salutation;
165
            $betaUser->first_name        = $omrUser->first_name;
166
            $betaUser->last_name         = $omrUser->last_name;
167
            $betaUser->email             = $omrUser->email;
168
            $betaUser->confirmation_code = $betaUser->confirmation_code ?? md5($omrUser->sha1_password . $omrUser->salt);
169
            $betaUser->save();
170
        }
171
    }
172
173
    private function updateAgents(): void
174
    {
175
        $betaProjects = Project::where('updated_at', '>', $this->lastRunTimestamp)->get();
176
        foreach ($betaProjects as $betaProject) {
177
            echo $betaProject->id . ', ';
178
            $omrAgent = Agent::withTrashed()->find($betaProject->id);
179
            if ($omrAgent) {
180
                //if it's the first run, then we always update beta
181
                if ($this->firstRun || $omrAgent->last_updated->gt($betaProject->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

181
                if ($this->firstRun || $omrAgent->last_updated->/** @scrutinizer ignore-call */ gt($betaProject->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
182
                    $this->UpdateMatchingAgent($betaProject, $omrAgent);
183
                }
184
                if (! $this->firstRun && $betaProject->updated_at->gt($omrAgent->last_updated)) {
185
                    $this->UpdateMatchingAgent($omrAgent, $betaProject);
186
                }
187
            } else { //we have a betaProject that doesn't exist in the OMR
188
                $this->UpdateMatchingAgent(new Agent(), $betaProject, true);
189
            }
190
        }
191
        $betaId    = Project::latest()->first()->id;
192
        $omrAgents = Agent::where('id', '>', $betaId)->get();
193
        foreach ($omrAgents as $omrAgent) {
194
            $this->UpdateMatchingAgent(new Project(), $omrAgent, true);
195
        }
196
    }
197
198
    private function updateAgentUsers(): void
199
    {
200
        $betaProjectUsers = ProjectUser::where('updated_at', '>', $this->lastRunTimestamp)->get();
201
        foreach ($betaProjectUsers as $betaProjectUser) {
202
            echo $betaProjectUser->id . ', ';
203
            $omrAgentUser = AgentUser::withTrashed()->find($betaProjectUser->id);
204
            if ($omrAgentUser) {
205
                //if it's the first run, then we always update beta
206
                if ($this->firstRun || $omrAgentUser->updated_at->gt($betaProjectUser->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

206
                if ($this->firstRun || $omrAgentUser->updated_at->/** @scrutinizer ignore-call */ gt($betaProjectUser->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
207
                    $this->UpdateMatchingAgentUser($betaProjectUser, $omrAgentUser);
208
                }
209
                if (! $this->firstRun && $betaProjectUser->updated_at->gt($omrAgentUser->updated_at)) {
210
                    $this->UpdateMatchingAgentUser($omrAgentUser, $betaProjectUser);
211
                }
212
            } else { //we have a betaProject that doesn't exist in the OMR
213
                $this->UpdateMatchingAgentUser(new AgentUser(), $betaProjectUser, true);
214
            }
215
        }
216
        $betaId        = ProjectUser::latest()->first()->id;
217
        $omrAgentUsers = AgentUser::where('id', '>', $betaId)->get();
218
        foreach ($omrAgentUsers as $omrAgentUser) {
219
            $this->UpdateMatchingAgentUser(new ProjectUser(), $omrAgentUser, true);
220
        }
221
    }
222
223
    private function updateVocabularies(): void
224
    {
225
        $betaVocabularies = betaVocabulary::where('updated_at', '>', $this->lastRunTimestamp)->get();
226
        foreach ($betaVocabularies as $betaVocabulary) {
227
            echo $betaVocabulary->id . ', ';
228
            $omrVocabulary = omrVocabulary::withTrashed()->find($betaVocabulary->id);
229
            if ($omrVocabulary) {
230
                //if it's the first run, then we always update beta
231
                if ($this->firstRun || $omrVocabulary->last_updated->gt($betaVocabulary->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

231
                if ($this->firstRun || $omrVocabulary->last_updated->/** @scrutinizer ignore-call */ gt($betaVocabulary->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
232
                    $this->UpdateMatchingVocabulary($betaVocabulary, $omrVocabulary);
233
                }
234
                if (! $this->firstRun && $betaVocabulary->updated_at->gt($omrVocabulary->last_updated)) {
235
                    $this->UpdateMatchingVocabulary($omrVocabulary, $betaVocabulary);
236
                }
237
            } else { //we have a betaProject that doesn't exist in the OMR
238
                $this->UpdateMatchingVocabulary(new omrVocabulary(), $betaVocabulary, true);
239
            }
240
        }
241
        $betaId          = betaVocabulary::latest()->first()->id;
242
        $omrVocabularies = omrVocabulary::where('id', '>', $betaId)->get();
243
        foreach ($omrVocabularies as $omrVocabulary) {
244
            $this->UpdateMatchingVocabulary(new betaVocabulary(), $omrVocabulary, true);
245
        }
246
    }
247
248
    private function updateVocabularyUsers(): void
249
    {
250
        $betaVocabularyUsers = betaVocabularyUser::where('updated_at', '>', $this->lastRunTimestamp)->get();
251
        foreach ($betaVocabularyUsers as $betaVocabularyUser) {
252
            echo $betaVocabularyUser->id . ', ';
253
            $omrVocabularyUser = omrVocabularyUser::withTrashed()->find($betaVocabularyUser->id);
254
            if ($omrVocabularyUser) {
255
                //if it's the first run, then we always update beta
256
                if ($this->firstRun || $omrVocabularyUser->updated_at->gt($betaVocabularyUser->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

256
                if ($this->firstRun || $omrVocabularyUser->updated_at->/** @scrutinizer ignore-call */ gt($betaVocabularyUser->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
257
                    $this->UpdateMatchingVocabularyUser($betaVocabularyUser, $omrVocabularyUser);
258
                }
259
                if (! $this->firstRun && $betaVocabularyUser->updated_at->gt($omrVocabularyUser->updated_at)) {
260
                    $this->UpdateMatchingVocabularyUser($omrVocabularyUser, $betaVocabularyUser);
261
                }
262
            } else { //we have a betaProject that doesn't exist in the OMR
263
                $this->UpdateMatchingVocabularyUser(new omrVocabularyUser(), $betaVocabularyUser, true);
264
            }
265
        }
266
        $betaId             = betaVocabularyUser::latest()->first()->id;
267
        $omrVocabularyUsers = omrVocabularyUser::where('id', '>', $betaId)->get();
268
        foreach ($omrVocabularyUsers as $omrVocabularyUser) {
269
            $this->UpdateMatchingVocabularyUser(new betaVocabularyUser(), $omrVocabularyUser, true);
270
        }
271
    }
272
273
    private function updateSchema(): void
274
    {
275
        $elementsets = Elementset::where('updated_at', '>', $this->lastRunTimestamp)->get();
276
        foreach ($elementsets as $elementset) {
277
            echo $elementset->id . ', ';
278
            $schema = Schema::withTrashed()->find($elementset->id);
279
            if ($schema) {
280
                //if it's the first run, then we always update beta
281
                if ($this->firstRun || $schema->updated_at->gt($elementset->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

281
                if ($this->firstRun || $schema->updated_at->/** @scrutinizer ignore-call */ gt($elementset->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
282
                    $this->UpdateMatchingSchema($elementset, $schema);
283
                }
284
                if (! $this->firstRun && $elementset->updated_at->gt($schema->updated_at)) {
285
                    $this->UpdateMatchingSchema($schema, $elementset);
286
                }
287
            } else { //we have a betaProject that doesn't exist in the OMR
288
                $this->UpdateMatchingSchema(new Schema(), $elementset, true);
289
            }
290
        }
291
        $betaId  = Elementset::latest()->first()->id;
292
        $schemas = Schema::where('id', '>', $betaId)->get();
293
        foreach ($schemas as $schema) {
294
            $this->UpdateMatchingSchema(new Elementset(), $schema, true);
295
        }
296
    }
297
298
    private function updateSchemaUsers(): void
299
    {
300
        $elementsetUsers = ElementsetUser::where('updated_at', '>', $this->lastRunTimestamp)->get();
301
        foreach ($elementsetUsers as $elementsetUser) {
302
            echo $elementsetUser->id . ', ';
303
            $schemaUser = SchemaUser::withTrashed()->find($elementsetUser->id);
304
            if ($schemaUser) {
305
                //if it's the first run, then we always update beta
306
                if ($this->firstRun || $schemaUser->updated_at->gt($elementsetUser->updated_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

306
                if ($this->firstRun || $schemaUser->updated_at->/** @scrutinizer ignore-call */ gt($elementsetUser->updated_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
307
                    $this->UpdateMatchingSchemaUser($elementsetUser, $schemaUser);
308
                }
309
                if (! $this->firstRun && $elementsetUser->updated_at->gt($schemaUser->updated_at)) {
310
                    $this->UpdateMatchingSchemaUser($schemaUser, $elementsetUser);
311
                }
312
            } else { //we have a betaProject that doesn't exist in the OMR
313
                $this->UpdateMatchingSchemaUser(new SchemaUser(), $elementsetUser, true);
314
            }
315
        }
316
        $betaId             = ElementsetUser::latest()->first()->id;
317
        $omrVocabularyUsers = SchemaUser::where('id', '>', $betaId)->get();
318
        foreach ($omrVocabularyUsers as $schemaUser) {
319
            $this->UpdateMatchingSchemaUser(new ElementsetUser(), $schemaUser, true);
320
        }
321
    }
322
323
    private function updateImportHistory(): void
324
    {
325
        $betaImports = betaImport::where('created_at', '>', $this->lastRunTimestamp)->get();
326
        foreach ($betaImports as $betaImport) {
327
            echo $betaImport->id . ', ';
328
            $omrImport = omrImport::withTrashed()->find($betaImport->id);
329
            if ($omrImport) {
330
                //if it's the first run, then we always update beta
331
                if ($this->firstRun || $omrImport->created_at->gt($betaImport->created_at)) {
0 ignored issues
show
Bug introduced by
The method gt() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

331
                if ($this->firstRun || $omrImport->created_at->/** @scrutinizer ignore-call */ gt($betaImport->created_at)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
332
                    $this->UpdateMatchingImport($betaImport, $omrImport);
333
                }
334
                if (! $this->firstRun && $betaImport->created_at->gt($omrImport->created_at)) {
335
                    $this->UpdateMatchingImport($omrImport, $betaImport);
336
                }
337
            } else { //we have a betaProject that doesn't exist in the OMR
338
                $this->UpdateMatchingImport(new omrImport(), $betaImport, true);
339
            }
340
        }
341
        $betaId     = betaImport::latest()->first()->id;
342
        $omrImports = omrImport::where('id', '>', $betaId)->get();
343
        foreach ($omrImports as $omrImport) {
344
            $this->UpdateMatchingImport(new betaImport(), $omrImport, true);
345
        }
346
    }
347
348
    private function UpdateMatchingAgent($toModel, $fromModel, $create = false): void
349
    {
350
        if ($create) {
351
            $toModel->id         = $fromModel->id;
352
            $toModel->created_at = $fromModel->created_at;
353
        }
354
        $toModel->deleted_at      = $fromModel->deleted_at;
355
        $toModel->org_email       = $fromModel->org_email;
356
        $toModel->org_name        = $fromModel->org_name;
357
        $toModel->ind_affiliation = $fromModel->ind_affiliation;
358
        $toModel->ind_role        = $fromModel->ind_role;
359
        $toModel->address1        = $fromModel->address1;
360
        $toModel->address2        = $fromModel->address2;
361
        $toModel->city            = $fromModel->city;
362
        $toModel->state           = $fromModel->state;
363
        $toModel->postal_code     = $fromModel->postal_code;
364
        $toModel->country         = $fromModel->country;
365
        $toModel->phone           = $fromModel->phone;
366
        $toModel->web_address     = $fromModel->web_address;
367
        $toModel->type            = $fromModel->type;
368
        if ($toModel->isDirty()) {
369
            if ($toModel instanceof Agent) {
370
                $toModel->updated_at = $fromModel->last_updated;
0 ignored issues
show
Bug introduced by
The property updated_at does not seem to exist on App\Models\Omr\Agent. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
371
            } else {
372
                $toModel->last_updated = $fromModel->updated_at;
373
            }
374
            $toModel->save();
375
        }
376
    }
377
378
    private function UpdateMatchingAgentUser($toModel, $fromModel, $create = false): void
379
    {
380
        if ($create) {
381
            $toModel->id         = $fromModel->id;
382
            $toModel->created_at = $fromModel->created_at;
383
        }
384
        $toModel->deleted_at       = $fromModel->deleted_at;
385
        $toModel->user_id          = $fromModel->user_id;
386
        $toModel->agent_id         = $fromModel->agent_id;
387
        $toModel->is_registrar_for = $fromModel->is_registrar_for;
388
        $toModel->is_admin_for     = $fromModel->is_admin_for;
389
        if ($toModel->isDirty()) {
390
            $toModel->updated_at = $fromModel->updated_at;
391
            $toModel->save();
392
        }
393
    }
394
395
    private function UpdateMatchingVocabulary($toModel, $fromModel, $create = false): void
396
    {
397
        if ($create) {
398
            $toModel->id         = $fromModel->id;
399
            $toModel->created_at = $fromModel->created_at;
400
        }
401
        $toModel->deleted_at            = $fromModel->deleted_at;
402
        $toModel->agent_id              = $fromModel->agent_id;
403
        $toModel->name                  = $fromModel->name;
404
        $toModel->note                  = $fromModel->note;
405
        $toModel->uri                   = $fromModel->uri;
406
        $toModel->url                   = $fromModel->url;
407
        $toModel->base_domain           = $fromModel->base_domain;
408
        $toModel->token                 = $fromModel->token;
409
        $toModel->status_id             = $fromModel->status_id;
410
        $toModel->language              = $fromModel->language;
411
        $toModel->languages             = $fromModel->languages;
412
        $toModel->profile_id            = $fromModel->profile_id;
413
        $toModel->ns_type               = $fromModel->ns_type;
414
        $toModel->prefixes              = $fromModel->prefixes;
415
        $toModel->repo                  = $fromModel->repo;
416
        $toModel->prefix                = $fromModel->prefix;
417
        $toModel->created_user_id       = $fromModel->created_user_id;
418
        $toModel->updated_user_id       = $fromModel->updated_user_id;
419
        $toModel->child_updated_at      = $fromModel->child_updated_at;
420
        $toModel->child_updated_user_id = $fromModel->child_updated_user_id;
421
        if ($toModel->isDirty()) {
422
            if ($toModel instanceof omrVocabulary) {
423
                $toModel->updated_at = $fromModel->last_updated;
0 ignored issues
show
Bug introduced by
The property updated_at does not exist on App\Models\Omr\Vocabulary. Did you mean child_updated_at?
Loading history...
424
            } else {
425
                $toModel->last_updated = $fromModel->updated_at;
426
            }
427
            $toModel->save();
428
        }
429
    }
430
431
    private function UpdateMatchingVocabularyUser($toModel, $fromModel, $create = false): void
432
    {
433
        if ($create) {
434
            $toModel->id         = $fromModel->id;
435
            $toModel->created_at = $fromModel->created_at;
436
        }
437
        $toModel->deleted_at        = $fromModel->deleted_at;
438
        $toModel->vocabulary_id     = $fromModel->vocabulary_id;
439
        $toModel->user_id           = $fromModel->user_id;
440
        $toModel->is_maintainer_for = $fromModel->is_maintainer_for;
441
        $toModel->is_registrar_for  = $fromModel->is_registrar_for;
442
        $toModel->is_admin_for      = $fromModel->is_admin_for;
443
        $toModel->languages         = $fromModel->languages;
444
        $toModel->default_language  = $fromModel->default_language;
445
        $toModel->current_language  = $fromModel->current_language;
446
        if ($toModel->isDirty()) {
447
            $toModel->updated_at = $fromModel->updated_at;
448
            $toModel->save();
449
        }
450
    }
451
452
    private function UpdateMatchingSchema($toModel, $fromModel, $create = false): void
453
    {
454
        if ($create) {
455
            $toModel->id         = $fromModel->id;
456
            $toModel->created_at = $fromModel->created_at;
457
        }
458
        $toModel->deleted_at            = $fromModel->deleted_at;
459
        $toModel->agent_id              = $fromModel->agent_id;
460
        $toModel->created_user_id       = $fromModel->created_user_id;
461
        $toModel->updated_user_id       = $fromModel->updated_user_id;
462
        $toModel->child_updated_at      = $fromModel->child_updated_at;
463
        $toModel->child_updated_user_id = $fromModel->child_updated_user_id;
464
        $toModel->name                  = $fromModel->name;
465
        $toModel->note                  = $fromModel->note;
466
        $toModel->uri                   = $fromModel->uri;
467
        $toModel->url                   = $fromModel->url;
468
        $toModel->base_domain           = $fromModel->base_domain;
469
        $toModel->token                 = $fromModel->token;
470
        $toModel->community             = $fromModel->community;
471
        $toModel->last_uri_id           = $fromModel->last_uri_id;
472
        $toModel->status_id             = $fromModel->status_id;
473
        $toModel->language              = $fromModel->language;
474
        $toModel->profile_id            = $fromModel->profile_id;
475
        $toModel->ns_type               = $fromModel->ns_type;
476
        $toModel->prefixes              = $fromModel->prefixes;
477
        $toModel->languages             = $fromModel->languages;
478
        $toModel->repo                  = $fromModel->repo;
479
        if ($toModel->isDirty()) {
480
            $toModel->updated_at = $fromModel->updated_at;
481
            $toModel->save();
482
        }
483
    }
484
485
    private function UpdateMatchingSchemaUser($toModel, $fromModel, $create = false): void
486
    {
487
        if ($create) {
488
            $toModel->id         = $fromModel->id;
489
            $toModel->created_at = $fromModel->created_at;
490
        }
491
        $toModel->deleted_at        = $fromModel->deleted_at;
492
        $toModel->schema_id         = $fromModel->schema_id;
493
        $toModel->user_id           = $fromModel->user_id;
494
        $toModel->is_maintainer_for = $fromModel->is_maintainer_for;
495
        $toModel->is_registrar_for  = $fromModel->is_registrar_for;
496
        $toModel->is_admin_for      = $fromModel->is_admin_for;
497
        $toModel->languages         = $fromModel->languages;
498
        $toModel->default_language  = $fromModel->default_language;
499
        $toModel->current_language  = $fromModel->current_language;
500
        if ($toModel->isDirty()) {
501
            $toModel->updated_at = $fromModel->updated_at;
502
            $toModel->save();
503
        }
504
    }
505
506
    private function UpdateMatchingImport($toModel, $fromModel, $create = false): void
507
    {
508
        if ($create) {
509
            $toModel->id         = $fromModel->id;
510
            $toModel->created_at = $fromModel->created_at;
511
        }
512
        $toModel->map                   = $fromModel->map;
513
        $toModel->user_id               = $fromModel->user_id;
514
        $toModel->vocabulary_id         = $fromModel->vocabulary_id;
515
        $toModel->schema_id             = $fromModel->schema_id;
516
        $toModel->file_name             = $fromModel->file_name;
517
        $toModel->source_file_name      = $fromModel->source_file_name;
518
        $toModel->file_type             = $fromModel->file_type;
519
        $toModel->batch_id              = $fromModel->batch_id;
520
        $toModel->results               = $fromModel->results;
521
        $toModel->total_processed_count = $fromModel->total_processed_count;
522
        $toModel->error_count           = $fromModel->error_count;
523
        $toModel->success_count         = $fromModel->success_count;
524
        if ($toModel->isDirty()) {
525
            $toModel->save();
526
        }
527
    }
528
}
529