Code Duplication    Length = 43-43 lines in 2 locations

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

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