From 1d105ad4357d0d5f617a2fe1177bfeae107c52a8 Mon Sep 17 00:00:00 2001 From: Barry Dam Date: Thu, 16 Mar 2017 09:35:51 +0100 Subject: [PATCH] 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. --- api.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/api.php b/api.php index 933b239..de4edaa 100644 --- a/api.php +++ b/api.php @@ -1862,6 +1862,19 @@ class PHP_CRUD_API { $page = $this->processPageParameter($page); $orderings = $this->processOrderingsParameter($orderings); + // input + $multi = (strpos($key[0],',')!==false) || (strlen($post)?($post[0]=='['):false); + $inputs = $this->retrieveInputs($post); + if ($before) { + if ($action == 'delete' && $multi) { + $inputs = array(); + for($i=1; $i <= count(explode(',', $key[0])); $i++) { + $inputs[] = (object) array(); + } + } + $this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$inputs); + } + // reflection list($tables,$collect,$select) = $this->findRelations($tables,$database,$auto_include); $fields = $this->findFields($tables,$columns,$exclude,$select,$database); @@ -1873,13 +1886,6 @@ class PHP_CRUD_API { if ($tenancy_function) $this->applyTenancyFunction($tenancy_function,$action,$database,$fields,$filters); if ($column_authorizer) $this->applyColumnAuthorizer($column_authorizer,$action,$database,$fields); - // input - $multi = (strpos($key[0],',')!==false) || (strlen($post)?($post[0]=='['):false); - $inputs = $this->retrieveInputs($post); - if ($before) { - $this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$inputs); - } - foreach ($inputs as $k=>$context) { $input = $this->filterInputByFields($context,$fields[$tables[0]]);