Skip to content

Commit 1d105ad

Browse files
authored
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](#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](#209), this needs to be discussed first.
1 parent 753c0c0 commit 1d105ad

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

api.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,19 @@ protected function getParameters($settings) {
18621862
$page = $this->processPageParameter($page);
18631863
$orderings = $this->processOrderingsParameter($orderings);
18641864

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+
18651878
// reflection
18661879
list($tables,$collect,$select) = $this->findRelations($tables,$database,$auto_include);
18671880
$fields = $this->findFields($tables,$columns,$exclude,$select,$database);
@@ -1873,13 +1886,6 @@ protected function getParameters($settings) {
18731886
if ($tenancy_function) $this->applyTenancyFunction($tenancy_function,$action,$database,$fields,$filters);
18741887
if ($column_authorizer) $this->applyColumnAuthorizer($column_authorizer,$action,$database,$fields);
18751888

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-
18831889
foreach ($inputs as $k=>$context) {
18841890
$input = $this->filterInputByFields($context,$fields[$tables[0]]);
18851891

0 commit comments

Comments
 (0)