Code Duplication    Length = 43-43 lines in 2 locations

class/bbctypes.class.php 1 location

@@ 402-444 (lines=43) @@
399
	 *
400
	 * @return int <0 if KO, >0 if OK
401
	 */
402
	public function delete(User $user, $notrigger = false)
403
	{
404
		dol_syslog(__METHOD__, LOG_DEBUG);
405
406
		$error = 0;
407
408
		$this->db->begin();
409
410
		if (!$error) {
411
			if (!$notrigger) {
412
				// Uncomment this and change MYOBJECT to your own tag if you
413
				// want this action calls a trigger.
414
415
				//// Call triggers
416
				//$result=$this->call_trigger('MYOBJECT_DELETE',$user);
417
				//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
418
				//// End call triggers
419
			}
420
		}
421
422
		if (!$error) {
423
			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
424
			$sql .= ' WHERE idType=' . $this->id;
425
426
			$resql = $this->db->query($sql);
427
			if (!$resql) {
428
				$error ++;
429
				$this->errors[] = 'Error ' . $this->db->lasterror();
430
				dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
431
			}
432
		}
433
434
		// Commit or rollback
435
		if ($error) {
436
			$this->db->rollback();
437
438
			return - 1 * $error;
439
		} else {
440
			$this->db->commit();
441
442
			return 1;
443
		}
444
	}
445
446
	/**
447
	 * Load an object from its id and create a new one in database

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
     * Load an object from its id and create a new one in database