Browse Source

As discussed in #200

Maurits van der Schee 8 years ago
parent
commit
4e27405863
1 changed files with 7 additions and 6 deletions
  1. 7
    6
      api.php

+ 7
- 6
api.php View File

@@ -1134,8 +1134,10 @@ class PHP_CRUD_API {
1134 1134
 		return $values;
1135 1135
 	}
1136 1136
 
1137
-	protected function applyAfterWrite($callback,$action,$database,$table,$id,$input) {
1137
+	protected function applyAfterWrite($action,$table,$id,$input) {
1138
+		$callback = $this->settings['after_write'];
1138 1139
 		if (is_callable($callback,true)) {
1140
+			$database = $this->settings['database'];
1139 1141
 			$callback($action,$database,$table,$id,$input);
1140 1142
 		}
1141 1143
 	}
@@ -1474,8 +1476,7 @@ class PHP_CRUD_API {
1474 1476
 		$result = $this->db->query('INSERT INTO ! ('.$keys.') VALUES ('.$values.')',$params);
1475 1477
 		if (!$result) return null;
1476 1478
 		$insertId = $this->db->insertId($result);
1477
-		extract($this->settings);
1478
-		$this->applyAfterWrite($after_write,'create',$database,$tables[0],$insertId,$input);
1479
+		$this->applyAfterWrite('create',$tables[0],$insertId,$input);
1479 1480
 		return $insertId;
1480 1481
 	}
1481 1482
 
@@ -1512,7 +1513,7 @@ class PHP_CRUD_API {
1512 1513
 		$this->addWhereFromFilters($filters[$table],$sql,$params);
1513 1514
 		$result = $this->db->query($sql,$params);
1514 1515
 		if (!$result) return null;
1515
-		$this->applyAfterWrite($after_write,'update',$database,$tables[0],$key[0],$input);
1516
+		$this->applyAfterWrite('update',$tables[0],$key[0],$input);
1516 1517
 		return $this->db->affectedRows($result);
1517 1518
 	}
1518 1519
 
@@ -1545,7 +1546,7 @@ class PHP_CRUD_API {
1545 1546
 		$this->addWhereFromFilters($filters[$table],$sql,$params);
1546 1547
 		$result = $this->db->query($sql,$params);
1547 1548
 		if (!$result) return null;
1548
-		$this->applyAfterWrite($after_write,'delete',$database,$tables[0],$key[0],array());
1549
+		$this->applyAfterWrite('delete',$tables[0],$key[0],array());
1549 1550
 		return $this->db->affectedRows($result);
1550 1551
 	}
1551 1552
 
@@ -1590,7 +1591,7 @@ class PHP_CRUD_API {
1590 1591
 		$this->addWhereFromFilters($filters[$table],$sql,$params);
1591 1592
 		$result = $this->db->query($sql,$params);
1592 1593
 		if (!$result) return null;
1593
-		$this->applyAfterWrite($after_write,'increment',$database,$tables[0],$key[0],$input);
1594
+		$this->applyAfterWrite('increment',$tables[0],$key[0],$input);
1594 1595
 		return $this->db->affectedRows($result);
1595 1596
 	}
1596 1597
 

Loading…
Cancel
Save