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.
This commit is contained in:
Barry Dam 2017-03-16 09:35:51 +01:00 committed by GitHub
commit 1d105ad435

20
api.php
View file

@ -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]]);