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

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