Browse Source

Bug in beforehandler, on deleting multiple rows

Hi there,

We're allmost there, I found 2 bug, one I solved by this pull request:

The first one: when deleting multiple rows at once and applying my soft delete [see example 209](https://github.com/mevdschee/php-crud-api/issues/209) I got an 404 errror : Subject cuased by the [updateObject method](https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1533-L1535) 

The other you will find here [209](https://github.com/mevdschee/php-crud-api/issues/209), this needs to be discussed first.
Barry Dam 8 years ago
parent
commit
1d105ad435
1 changed files with 13 additions and 7 deletions
  1. 13
    7
      api.php

+ 13
- 7
api.php View File

@@ -1862,6 +1862,19 @@ class PHP_CRUD_API {
1862 1862
 		$page      = $this->processPageParameter($page);
1863 1863
 		$orderings = $this->processOrderingsParameter($orderings);
1864 1864
 
1865
+		// input
1866
+		$multi = (strpos($key[0],',')!==false) || (strlen($post)?($post[0]=='['):false);
1867
+		$inputs = $this->retrieveInputs($post);
1868
+		if ($before) {
1869
+			if ($action == 'delete' && $multi) { 
1870
+				$inputs = array();
1871
+				for($i=1; $i <= count(explode(',', $key[0])); $i++) {
1872
+					$inputs[] = (object) array();
1873
+				}
1874
+			}
1875
+			$this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$inputs);
1876
+		}
1877
+		
1865 1878
 		// reflection
1866 1879
 		list($tables,$collect,$select) = $this->findRelations($tables,$database,$auto_include);
1867 1880
 		$fields = $this->findFields($tables,$columns,$exclude,$select,$database);
@@ -1873,13 +1886,6 @@ class PHP_CRUD_API {
1873 1886
 		if ($tenancy_function) $this->applyTenancyFunction($tenancy_function,$action,$database,$fields,$filters);
1874 1887
 		if ($column_authorizer) $this->applyColumnAuthorizer($column_authorizer,$action,$database,$fields);
1875 1888
 
1876
-		// input
1877
-		$multi = (strpos($key[0],',')!==false) || (strlen($post)?($post[0]=='['):false);
1878
-		$inputs = $this->retrieveInputs($post);
1879
-		if ($before) {
1880
-			$this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$inputs);
1881
-		}
1882
-		
1883 1889
 		foreach ($inputs as $k=>$context) {
1884 1890
 			$input = $this->filterInputByFields($context,$fields[$tables[0]]);
1885 1891
 

Loading…
Cancel
Save