Code Duplication    Length = 43-43 lines in 2 locations

class/bbctypes.class.php 1 location

@@ 380-422 (lines=43) @@
377
	 *
378
	 * @return int <0 if KO, >0 if OK
379
	 */
380
	public function delete(User $user, $notrigger = false)
381
	{
382
		dol_syslog(__METHOD__, LOG_DEBUG);
383
384
		$error = 0;
385
386
		$this->db->begin();
387
388
		if (!$error) {
389
			if (!$notrigger) {
390
				// Uncomment this and change MYOBJECT to your own tag if you
391
				// want this action calls a trigger.
392
393
				//// Call triggers
394
				//$result=$this->call_trigger('MYOBJECT_DELETE',$user);
395
				//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
396
				//// End call triggers
397
			}
398
		}
399
400
		if (!$error) {
401
			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
402
			$sql .= ' WHERE idType=' . $this->id;
403
404
			$resql = $this->db->query($sql);
405
			if (!$resql) {
406
				$error ++;
407
				$this->errors[] = 'Error ' . $this->db->lasterror();
408
				dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
409
			}
410
		}
411
412
		// Commit or rollback
413
		if ($error) {
414
			$this->db->rollback();
415
416
			return - 1 * $error;
417
		} else {
418
			$this->db->commit();
419
420
			return 1;
421
		}
422
	}
423
424
	/**
425
	 * Load an object from its id and create a new one in database

class/bbcvols.class.php 1 location

@@ 604-646 (lines=43) @@
601
     *
602
     * @return int <0 if KO, >0 if OK
603
     */
604
    public function delete(User $user, $notrigger = false)
605
    {
606
        dol_syslog(__METHOD__, LOG_DEBUG);
607
608
        $error = 0;
609
610
        $this->db->begin();
611
612
        if (!$error) {
613
            if (!$notrigger) {
614
                // Uncomment this and change MYOBJECT to your own tag if you
615
                // want this action calls a trigger.
616
617
                //// Call triggers
618
                //$result=$this->call_trigger('MYOBJECT_DELETE',$user);
619
                //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
620
                //// End call triggers
621
            }
622
        }
623
624
        if (!$error) {
625
            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
626
            $sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols;
627
628
            $resql = $this->db->query($sql);
629
            if (!$resql) {
630
                $error++;
631
                $this->errors[] = 'Error ' . $this->db->lasterror();
632
                dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
633
            }
634
        }
635
636
        // Commit or rollback
637
        if ($error) {
638
            $this->db->rollback();
639
640
            return -1 * $error;
641
        } else {
642
            $this->db->commit();
643
644
            return 1;
645
        }
646
    }
647
648
    /**
649
     * Load an object from its id and create a new one in database