Code Duplication    Length = 37-43 lines in 2 locations

class/bbcvols.class.php 1 location

@@ 616-658 (lines=43) @@
613
     *
614
     * @return int <0 if KO, >0 if OK
615
     */
616
    public function delete(User $user, $notrigger = false)
617
    {
618
        dol_syslog(__METHOD__, LOG_DEBUG);
619
620
        $error = 0;
621
622
        $this->db->begin();
623
624
        if (!$error) {
625
            if (!$notrigger) {
626
                // Uncomment this and change MYOBJECT to your own tag if you
627
                // want this action calls a trigger.
628
629
                //// Call triggers
630
                //$result=$this->call_trigger('MYOBJECT_DELETE',$user);
631
                //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
632
                //// End call triggers
633
            }
634
        }
635
636
        if (!$error) {
637
            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
638
            $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
639
640
            $resql = $this->db->query($sql);
641
            if (!$resql) {
642
                $error++;
643
                $this->errors[] = 'Error ' . $this->db->lasterror();
644
                dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
645
            }
646
        }
647
648
        // Commit or rollback
649
        if ($error) {
650
            $this->db->rollback();
651
652
            return -1 * $error;
653
        } else {
654
            $this->db->commit();
655
656
            return 1;
657
        }
658
    }
659
660
    /**
661
     *  Return a link to the user card (with optionaly the picto)

class/bbctypes.class.php 1 location

@@ 383-419 (lines=37) @@
380
     *
381
     * @return int <0 if KO, >0 if OK
382
     */
383
    public function delete(User $user, $notrigger = false)
384
    {
385
        dol_syslog(__METHOD__, LOG_DEBUG);
386
387
        $error = 0;
388
389
        $this->db->begin();
390
391
        if (!$error) {
392
            if (!$notrigger) {
393
                $this->call_trigger('BBC_FLIGHT_TYPE_DELETE', $user);
394
            }
395
        }
396
397
        if (!$error) {
398
            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
399
            $sql .= ' WHERE idType=' . $this->id;
400
401
            $resql = $this->db->query($sql);
402
            if (!$resql) {
403
                $error++;
404
                $this->errors[] = 'Error ' . $this->db->lasterror();
405
                dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
406
            }
407
        }
408
409
        // Commit or rollback
410
        if ($error) {
411
            $this->db->rollback();
412
413
            return -1 * $error;
414
        } else {
415
            $this->db->commit();
416
417
            return 1;
418
        }
419
    }
420
421
    /**
422
     * Load an object from its id and create a new one in database