GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( b52382...825938 )
by
unknown
07:13
created

ModifierTrait::insertIfNotExists()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 4
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Models\Sql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class TraitModifier
20
 *
21
 * @package O2System\Framework\Models\Sql\Traits
22
 */
23
trait ModifierTrait
24
{
25
    /**
26
     * ModifierTrait::insert
27
     *
28
     * @param array $sets
29
     *
30
     * @return bool
31
     */
32
    public function insert(array $sets)
33
    {
34
        if (count($sets)) {
35
            if (method_exists($this, 'insertRecordSets')) {
36
                $this->insertRecordSets($sets);
37
            }
38
39
            if (method_exists($this, 'beforeInsert')) {
40
                $this->beforeInsert($sets);
41
            }
42
43
            if (method_exists($this, 'getRecordOrdering')) {
44
                if ($this->recordOrdering === true && empty($sets[ 'record_ordering' ])) {
45
                    $sets[ 'record_ordering' ] = $this->getRecordOrdering($this->table);
46
                }
47
            }
48
49
            if ($this->qb->table($this->table)->insert($sets)) {
50
                if (method_exists($this, 'afterInsert')) {
51
                    return $this->afterInsert();
52
                }
53
54
                return true;
55
            }
56
        }
57
58
        return false;
59
    }
60
61
    // ------------------------------------------------------------------------
62
63
    /**
64
     * ModifierTrait::insertOrUpdate
65
     *
66
     * @param array $sets
67
     *
68
     * @return bool
69
     */
70
    public function insertOrUpdate(array $sets)
71
    {
72
        if ($result = $this->qb->from($this->table)->getWhere($sets)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
73
            return $this->update($sets);
74
        } else {
75
            return $this->insert($sets);
76
        }
77
78
        return false;
0 ignored issues
show
Unused Code introduced by
return false is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
79
    }
80
81
    // ------------------------------------------------------------------------
82
83
    /**
84
     * ModifierTrait::insertMany
85
     *
86
     * @param array $sets
87
     *
88
     * @return bool|int
89
     */
90
    public function insertMany(array $sets)
91
    {
92
        if (count($sets)) {
93
            if (method_exists($this, 'insertRecordSets')) {
94
                foreach ($sets as $set) {
95
                    $this->insertRecordSets($set);
96
                    if ($this->recordOrdering === true && empty($sets[ 'record_ordering' ])) {
97
                        $set[ 'record_ordering' ] = $this->getRecordOrdering($this->table);
0 ignored issues
show
Bug introduced by
It seems like getRecordOrdering() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

97
                        /** @scrutinizer ignore-call */ 
98
                        $set[ 'record_ordering' ] = $this->getRecordOrdering($this->table);
Loading history...
98
                    }
99
                }
100
            }
101
102
            if (method_exists($this, 'beforeInsertMany')) {
103
                $this->beforeInsertMany($sets);
104
            }
105
106
            if ($this->qb->table($this->table)->insertBatch($sets)) {
107
                if (method_exists($this, 'afterInsertMany')) {
108
                    return $this->afterInsertMany();
109
                }
110
111
                return $this->db->getAffectedRows();
112
            }
113
        }
114
115
        return false;
116
    }
117
118
    // ------------------------------------------------------------------------
119
120
    /**
121
     * ModifierTrait::insertIfNotExists
122
     *
123
     * @param array $sets
124
     * @param array $conditions
125
     *
126
     * @return bool
127
     */
128
    public function insertIfNotExists(array $sets, array $conditions = [])
129
    {
130
        if (count($sets)) {
131
            if ($result = $this->qb->from($this->table)->getWhere($conditions)) {
132
                if ($result->count() == 0) {
133
                    return $this->insert($sets);
134
                }
135
            }
136
        }
137
138
        return false;
139
    }
140
141
    // ------------------------------------------------------------------------
142
143
    /**
144
     * ModifierTrait::update
145
     *
146
     * @param array $sets
147
     * @param array $conditions
148
     *
149
     * @return bool
150
     */
151
    public function update(array $sets, $conditions = [])
152
    {
153
        if (count($sets)) {
154
            $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
155
156
            if (empty($conditions)) {
157
                if (isset($sets[ $primaryKey ])) {
158
                    $conditions = [$primaryKey => $sets[ $primaryKey ]];
159
                }
160
            }
161
162
            if (method_exists($this, 'updateRecordSets')) {
163
                $this->updateRecordSets($sets);
164
            }
165
166
            if (method_exists($this, 'beforeUpdate')) {
167
                $sets = $this->beforeUpdate($sets);
168
            }
169
170
            if (method_exists($this, 'getRecordOrdering')) {
171
                if ($this->recordOrdering === true && empty($sets[ 'record_ordering' ])) {
172
                    $sets[ 'record_ordering' ] = $this->getRecordOrdering($this->table);
173
                }
174
            }
175
176
            if ($this->qb->table($this->table)->update($sets, $conditions)) {
177
178
                if (method_exists($this, 'afterUpdate')) {
179
                    return $this->afterUpdate();
180
                }
181
182
                return true;
183
            }
184
        }
185
186
        return false;
187
    }
188
189
    // ------------------------------------------------------------------------
190
191
    /**
192
     * ModifierTrait::updateOrInsert
193
     *
194
     * @param array $sets
195
     * @param array $conditions
196
     *
197
     * @return bool
198
     */
199
    public function updateOrInsert(array $sets, array $conditions = [])
200
    {
201
        if (count($sets)) {
202
            $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
203
204
            if (empty($conditions)) {
205
                if (isset($sets[ $primaryKey ])) {
206
                    $conditions = [$primaryKey => $sets[ $primaryKey ]];
207
                } else {
208
                    $conditions = $sets;
209
                }
210
            }
211
212
            // Try to find
213
            if ($result = $this->qb->from($this->table)->getWhere($conditions)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
214
                return $this->update($sets, $conditions);
215
            } else {
216
                return $this->insert($sets);
217
            }
218
        }
219
220
        return false;
221
    }
222
223
    // ------------------------------------------------------------------------
224
225
    /**
226
     * ModifierTrait::updateMany
227
     *
228
     * @param array $sets
229
     *
230
     * @return bool|int
231
     */
232
    public function updateMany(array $sets)
233
    {
234
        $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
235
236
        if (method_exists($this, 'updateRecordSets')) {
237
            foreach ($sets as $key => $set) {
238
                $this->updateRecordSets($sets[ $key ]);
239
            }
240
        }
241
242
        if (method_exists($this, 'beforeUpdateMany')) {
243
            $this->beforeUpdateMany($sets);
244
        }
245
246
        if ($this->qb->table($this->table)->updateBatch($sets, $primaryKey)) {
247
            if (method_exists($this, 'afterUpdateMany')) {
248
                return $this->afterUpdateMany();
249
            }
250
251
            return $this->db->getAffectedRows();
252
        }
253
254
        return false;
255
    }
256
257
    // ------------------------------------------------------------------------
258
259
    /**
260
     * ModifierTrait::delete
261
     *
262
     * @param int $id
263
     *
264
     * @return bool
265
     */
266
    public function delete($id)
267
    {
268
        $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
269
270
        if (method_exists($this, 'beforeDelete')) {
271
            $this->beforeDelete();
272
        }
273
274
        if ($this->qb->table($this->table)->limit(1)->delete([$primaryKey => $id])) {
275
            if (method_exists($this, 'afterDelete')) {
276
                return $this->afterDelete();
277
            }
278
279
            return true;
280
        }
281
282
        return false;
283
    }
284
285
    // ------------------------------------------------------------------------
286
287
    /**
288
     * ModifierTrait::deleteBy
289
     *
290
     * @param array $conditions
291
     *
292
     * @return bool
293
     */
294
    public function deleteBy($conditions = [])
295
    {
296
        if (count($conditions)) {
297
            if (method_exists($this, 'beforeDelete')) {
298
                $this->beforeDelete();
299
            }
300
301
            if (method_exists($this, 'beforeDelete')) {
302
                $this->beforeDelete();
303
            }
304
305
            if ($this->qb->table($this->table)->limit(1)->delete($conditions)) {
306
                if (method_exists($this, 'afterDelete')) {
307
                    return $this->afterDelete();
308
                }
309
310
                return $this->db->getAffectedRows();
311
            }
312
        }
313
314
        return false;
315
    }
316
317
    // ------------------------------------------------------------------------
318
319
    /**
320
     * ModifierTrait::deleteMany
321
     *
322
     * @param array $ids
323
     *
324
     * @return bool|int
325
     */
326
    public function deleteMany(array $ids)
327
    {
328
        $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
329
330
        if (method_exists($this, 'beforeDelete')) {
331
            $this->beforeDelete();
332
        }
333
334
        $this->qb->whereIn($primaryKey, $ids);
335
336
        if ($this->qb->table($this->table)->delete()) {
337
            if (method_exists($this, 'afterDelete')) {
338
                return $this->afterDelete();
339
            }
340
341
            return $this->db->getAffectedRows();
342
        }
343
344
        return false;
345
    }
346
347
    // ------------------------------------------------------------------------
348
349
    /**
350
     * ModifierTrait::deleteManyBy
351
     *
352
     * @param array $conditions
353
     *
354
     * @return bool|int
355
     */
356
    public function deleteManyBy($conditions = [])
357
    {
358
        if (count($conditions)) {
359
            if (method_exists($this, 'beforeDelete')) {
360
                $this->beforeDelete();
361
            }
362
363
            if ($this->qb->table($this->table)->delete($conditions)) {
364
                if (method_exists($this, 'afterDelete')) {
365
                    return $this->afterDelete();
366
                }
367
368
                return $this->db->getAffectedRows();
369
            }
370
        }
371
372
        return false;
373
    }
374
375
    // ------------------------------------------------------------------------
376
377
    /**
378
     * ModifierTrait::updateRecordStatus
379
     *
380
     * @param int $id
381
     *
382
     * @return bool
383
     */
384
    private function updateRecordStatus($id, $recordStatus, $method)
385
    {
386
        $sets[ 'record_status' ] = $recordStatus;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$sets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sets = array(); before regardless.
Loading history...
387
        $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
388
389
        if (method_exists($this, 'updateRecordSets')) {
390
            $this->updateRecordSets($sets);
391
        }
392
393
        if (method_exists($this, $beforeMethod = 'before' . ucfirst($method))) {
394
            call_user_func_array([&$this, $beforeMethod], [$sets]);
395
        }
396
397
        if ($this->qb->table($this->table)->limit(1)->update($sets, [$primaryKey => $id])) {
398
            if (method_exists($this, $afterMethod = 'after' . ucfirst($method))) {
399
                return call_user_func([&$this, $beforeMethod]);
400
            }
401
402
            return true;
403
        }
404
405
        return false;
406
    }
407
408
    // ------------------------------------------------------------------------
409
410
    /**
411
     * ModifierTrait::updateRecordStatusMany
412
     *
413
     * @param array $ids
414
     *
415
     * @return bool|int
416
     */
417
    private function updateRecordStatusMany(array $ids, $recordStatus, $method)
418
    {
419
        if (count($ids)) {
420
            $sets[ 'record_status' ] = $recordStatus;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$sets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sets = array(); before regardless.
Loading history...
421
            $primaryKey = isset($this->primaryKey) ? $this->primaryKey : 'id';
422
423
            $this->qb->whereIn($primaryKey, $ids);
424
425
            if (method_exists($this, 'updateRecordSets')) {
426
                $this->updateRecordSets($sets[ $key ]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $key seems to be never defined.
Loading history...
427
            }
428
429
            if (method_exists($this, $beforeMethod = 'before' . ucfirst($method))) {
430
                call_user_func_array([&$this, $beforeMethod], [$sets]);
431
            }
432
433
            if ($this->qb->table($this->table)->update($sets)) {
434
                if (method_exists($this, $afterMethod = 'after' . ucfirst($method))) {
435
                    return call_user_func([&$this, $beforeMethod]);
436
                }
437
438
                return $this->getAffectedRows();
0 ignored issues
show
Bug introduced by
It seems like getAffectedRows() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

438
                return $this->/** @scrutinizer ignore-call */ getAffectedRows();
Loading history...
439
            }
440
        }
441
442
        return false;
443
    }
444
445
    // ------------------------------------------------------------------------
446
447
    /**
448
     * ModifierTrait::updateRecordStatusBy
449
     *
450
     * @param int   $id
451
     * @param array $conditions
452
     *
453
     * @return bool|int
454
     */
455
    private function updateRecordStatusBy(array $conditions = [], $recordStatus, $method)
456
    {
457
        if (count($conditions)) {
458
            $sets[ 'record_status' ] = $recordStatus;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$sets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sets = array(); before regardless.
Loading history...
459
460
            if (method_exists($this, 'updateRecordSets')) {
461
                $this->updateRecordSets($sets);
462
            }
463
464
            if (method_exists($this, $beforeMethod = 'before' . ucfirst($method))) {
465
                call_user_func_array([&$this, $beforeMethod], [$sets]);
466
            }
467
468
            if ($this->qb->table($this->table)->update($sets, $conditions)) {
469
                if (method_exists($this, $afterMethod = 'after' . ucfirst($method))) {
470
                    return call_user_func([&$this, $beforeMethod]);
471
                }
472
473
                return $this->getAffectedRows();
474
            }
475
        }
476
477
        return false;
478
    }
479
480
    // ------------------------------------------------------------------------
481
482
    /**
483
     * ModifierTrait::updateRecordStatusManyBy
484
     *
485
     * @param array $ids
486
     * @param array $conditions
487
     *
488
     * @return bool|int
489
     */
490
    private function updateRecordStatusManyBy($conditions = [], $recordStatus, $method)
491
    {
492
        if (count($conditions)) {
493
            $sets[ 'record_status' ] = $recordStatus;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$sets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sets = array(); before regardless.
Loading history...
494
495
            if (method_exists($this, 'updateRecordSets')) {
496
                $this->updateRecordSets($sets);
497
            }
498
499
            if (method_exists($this, $beforeMethod = 'before' . ucfirst($method))) {
500
                call_user_func_array([&$this, $beforeMethod], [$sets]);
501
            }
502
503
            if ($this->qb->table($this->table)->update($sets, $conditions)) {
504
                if (method_exists($this, $afterMethod = 'after' . ucfirst($method))) {
505
                    return call_user_func([&$this, $beforeMethod]);
506
                }
507
508
                return $this->getAffectedRows();
509
            }
510
        }
511
512
        return false;
513
    }
514
515
    // ------------------------------------------------------------------------
516
517
    /**
518
     * ModifierTrait::publish
519
     *
520
     * @param int $id
521
     *
522
     * @return bool
523
     */
524
    public function publish($id)
525
    {
526
        return $this->updateRecordStatus($id, 'PUBLISH', 'publish');
527
    }
528
529
    // ------------------------------------------------------------------------
530
531
    /**
532
     * ModifierTrait::publishBy
533
     *
534
     * @param array $conditions
535
     *
536
     * @return bool|int
537
     */
538
    public function publishBy(array $conditions = [])
539
    {
540
        return $this->updateRecordStatusBy($conditions, 'PUBLISH', 'publishBy');
541
    }
542
543
    // ------------------------------------------------------------------------
544
545
    /**
546
     * ModifierTrait::publishMany
547
     *
548
     * @param array $ids
549
     *
550
     * @return bool|int
551
     */
552
    public function publishMany(array $ids)
553
    {
554
        return $this->updateRecordStatusMany($ids, 'PUBLISH', 'publishMany');
555
    }
556
557
    // ------------------------------------------------------------------------
558
559
    /**
560
     * ModifierTrait::publishManyBy
561
     *
562
     * @param array $conditions
563
     *
564
     * @return bool|int
565
     */
566
    public function publishManyBy($conditions = [])
567
    {
568
        return $this->updateRecordStatusManyBy($ids, 'PUBLISH', 'publishManyBy');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ids seems to be never defined.
Loading history...
569
    }
570
571
    // ------------------------------------------------------------------------
572
573
    /**
574
     * ModifierTriat::restore
575
     *
576
     * @param int $id
577
     *
578
     * @return bool
579
     */
580
    public function restore($id)
581
    {
582
        return $this->updateRecordStatus($id, 'PUBLISH', 'restore');
583
    }
584
585
    // ------------------------------------------------------------------------
586
587
    /**
588
     * ModifierTrait::restoreBy
589
     *
590
     * @param array $conditions
591
     *
592
     * @return bool
593
     */
594
    public function restoreBy(array $conditions = [])
595
    {
596
        return $this->updateRecordStatusBy($conditions, 'PUBLISH', 'restoreBy');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->updateReco...'PUBLISH', 'restoreBy') also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
597
    }
598
599
    // ------------------------------------------------------------------------
600
601
    /**
602
     * ModifierTrait::restoreMany
603
     *
604
     * @param array $ids
605
     *
606
     * @return bool|int
607
     */
608
    public function restoreMany(array $ids)
609
    {
610
        return $this->updateRecordStatusMany($ids, 'PUBLISH', 'restoreMany');
611
    }
612
613
    // ------------------------------------------------------------------------
614
615
    /**
616
     * ModifierTrait::restoreManyBy
617
     *
618
     * @param array $conditions
619
     *
620
     * @return bool|int
621
     */
622
    public function restoreManyBy(array $ids, $conditions = [])
623
    {
624
        return $this->updateRecordStatusManyBy($ids, 'PUBLISH', 'restoreManyBy');
625
    }
626
627
    // ------------------------------------------------------------------------
628
629
    /**
630
     * ModifierTriat::unpublish
631
     *
632
     * @param int $id
633
     *
634
     * @return bool
635
     */
636
    public function unpublish($id)
637
    {
638
        return $this->updateRecordStatus($id, 'UNPUBLISH', 'unpublish');
639
    }
640
641
    // ------------------------------------------------------------------------
642
643
    /**
644
     * ModifierTrait::unpublishBy
645
     *
646
     * @param array $conditions
647
     *
648
     * @return bool
649
     */
650
    public function unpublishBy(array $conditions = [])
651
    {
652
        return $this->updateRecordStatusBy($conditions, 'UNPUBLISH', 'unpublishBy');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->updateReco...UBLISH', 'unpublishBy') also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
653
    }
654
655
    // ------------------------------------------------------------------------
656
657
    /**
658
     * ModifierTrait::unpublishMany
659
     *
660
     * @param array $ids
661
     *
662
     * @return bool|int
663
     */
664
    public function unpublishMany(array $ids)
665
    {
666
        return $this->updateRecordStatusMany($ids, 'UNPUBLISH', 'unpublishMany');
667
    }
668
669
    // ------------------------------------------------------------------------
670
671
    /**
672
     * ModifierTrait::unpublishManyBy
673
     *
674
     * @param array $conditions
675
     *
676
     * @return bool|int
677
     */
678
    public function unpublishManyBy(array $ids, $conditions = [])
679
    {
680
        return $this->updateRecordStatusManyBy($ids, 'UNPUBLISH', 'unpublishManyBy');
681
    }
682
683
    // ------------------------------------------------------------------------
684
685
    /**
686
     * ModifierTriat::softDelete
687
     *
688
     * @param int $id
689
     *
690
     * @return bool
691
     */
692
    public function softDelete($id)
693
    {
694
        return $this->updateRecordStatus($id, 'DELETED', 'softDelete');
695
    }
696
697
    // ------------------------------------------------------------------------
698
699
    /**
700
     * ModifierTrait::softDeleteBy
701
     *
702
     * @param array $conditions
703
     *
704
     * @return bool
705
     */
706
    public function softDeleteBy(array $conditions = [])
707
    {
708
        return $this->updateRecordStatusBy($conditions, 'DELETED', 'softDeleteBy');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->updateReco...LETED', 'softDeleteBy') also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
709
    }
710
711
    // ------------------------------------------------------------------------
712
713
    /**
714
     * ModifierTrait::softDeleteMany
715
     *
716
     * @param array $ids
717
     *
718
     * @return bool|int
719
     */
720
    public function softDeleteMany(array $ids)
721
    {
722
        return $this->updateRecordStatusMany($ids, 'DELETED', 'softDeleteMany');
723
    }
724
725
    // ------------------------------------------------------------------------
726
727
    /**
728
     * ModifierTrait::softDeleteManyBy
729
     *
730
     * @param array $conditions
731
     *
732
     * @return bool|int
733
     */
734
    public function softDeleteManyBy(array $ids, $conditions = [])
735
    {
736
        return $this->updateRecordStatusManyBy($ids, 'DELETED', 'softDeleteManyBy');
737
    }
738
739
    // ------------------------------------------------------------------------
740
741
    /**
742
     * ModifierTriat::archive
743
     *
744
     * @param int $id
745
     *
746
     * @return bool
747
     */
748
    public function archive($id)
749
    {
750
        return $this->updateRecordStatus($id, 'ARCHIVED', 'archive');
751
    }
752
753
    // ------------------------------------------------------------------------
754
755
    /**
756
     * ModifierTrait::archiveBy
757
     *
758
     * @param array $conditions
759
     *
760
     * @return bool
761
     */
762
    public function archiveBy(array $conditions = [])
763
    {
764
        return $this->updateRecordStatusBy($conditions, 'ARCHIVED', 'archiveBy');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->updateReco...ARCHIVED', 'archiveBy') also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
765
    }
766
767
    // ------------------------------------------------------------------------
768
769
    /**
770
     * ModifierTrait::archiveMany
771
     *
772
     * @param array $ids
773
     *
774
     * @return bool|int
775
     */
776
    public function archiveMany(array $ids)
777
    {
778
        return $this->updateRecordStatusMany($ids, 'ARCHIVED', 'archiveMany');
779
    }
780
781
    // ------------------------------------------------------------------------
782
783
    /**
784
     * ModifierTrait::archiveManyBy
785
     *
786
     * @param array $conditions
787
     *
788
     * @return bool|int
789
     */
790
    public function archiveManyBy(array $ids, $conditions = [])
791
    {
792
        return $this->updateRecordStatusManyBy($ids, 'ARCHIVED', 'archiveManyBy');
793
    }
794
795
    // ------------------------------------------------------------------------
796
797
    /**
798
     * ModifierTriat::lock
799
     *
800
     * @param int $id
801
     *
802
     * @return bool
803
     */
804
    public function lock($id)
805
    {
806
        return $this->updateRecordStatus($id, 'LOCKED', 'lock');
807
    }
808
809
    // ------------------------------------------------------------------------
810
811
    /**
812
     * ModifierTrait::lockBy
813
     *
814
     * @param array $conditions
815
     *
816
     * @return bool
817
     */
818
    public function lockBy(array $conditions = [])
819
    {
820
        return $this->updateRecordStatusBy($conditions, 'LOCKED', 'lockBy');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->updateReco...ns, 'LOCKED', 'lockBy') also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
821
    }
822
823
    // ------------------------------------------------------------------------
824
825
    /**
826
     * ModifierTrait::lockMany
827
     *
828
     * @param array $ids
829
     *
830
     * @return bool|int
831
     */
832
    public function lockMany(array $ids)
833
    {
834
        return $this->updateRecordStatusMany($ids, 'LOCKED', 'lockMany');
835
    }
836
837
    // ------------------------------------------------------------------------
838
839
    /**
840
     * ModifierTrait::lockManyBy
841
     *
842
     * @param array $conditions
843
     *
844
     * @return bool|int
845
     */
846
    public function lockManyBy(array $ids, $conditions = [])
847
    {
848
        return $this->updateRecordStatusManyBy($ids, 'LOCKED', 'lockManyBy');
849
    }
850
}