Skip to content

Commit 68a4043

Browse files
authored
call before multiple times
[refererring to](#210)
1 parent 1d105ad commit 68a4043

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

api.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,9 +1134,9 @@ protected function parseGetParameterArray($get,$name,$characters) {
11341134
return $values;
11351135
}
11361136

1137-
protected function applyBeforeHandler(&$action,&$database,&$table,&$id,&$callback,&$inputs) {
1137+
protected function applyBeforeHandler(&$action,&$database,&$table,&$id,&$callback,&$input) {
11381138
if (is_callable($callback,true)) {
1139-
$callback($action,$database,$table,$id,$inputs);
1139+
$callback($action,$database,$table,$id,$input);
11401140
}
11411141
}
11421142

@@ -1862,19 +1862,6 @@ 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-
18781865
// reflection
18791866
list($tables,$collect,$select) = $this->findRelations($tables,$database,$auto_include);
18801867
$fields = $this->findFields($tables,$columns,$exclude,$select,$database);
@@ -1886,17 +1873,34 @@ protected function getParameters($settings) {
18861873
if ($tenancy_function) $this->applyTenancyFunction($tenancy_function,$action,$database,$fields,$filters);
18871874
if ($column_authorizer) $this->applyColumnAuthorizer($column_authorizer,$action,$database,$fields);
18881875

1876+
// input
1877+
$multi = (strpos($key[0],',')!==false) || (strlen($post)?($post[0]=='['):false);
1878+
if ($before && $action == 'delete' && $multi) {
1879+
$inputs = array();
1880+
for($i=1; $i <= count(explode(',', $key[0])); $i++) {
1881+
$inputs[] = (object) array();
1882+
}
1883+
} else {
1884+
$inputs = $this->retrieveInputs($post);
1885+
}
1886+
$originalAction = $action;
18891887
foreach ($inputs as $k=>$context) {
1888+
//echo $k.' - ';
18901889
$input = $this->filterInputByFields($context,$fields[$tables[0]]);
18911890

18921891
if ($tenancy_function) $this->applyInputTenancy($tenancy_function,$action,$database,$tables[0],$input,$fields[$tables[0]]);
18931892
if ($input_sanitizer) $this->applyInputSanitizer($input_sanitizer,$action,$database,$tables[0],$input,$fields[$tables[0]]);
18941893
if ($input_validator) $this->applyInputValidator($input_validator,$action,$database,$tables[0],$input,$fields[$tables[0]],$context);
18951894

1896-
$this->convertInputs($input,$fields[$tables[0]]);
1895+
$this->convertInputs($input,$fields[$tables[0]]);
1896+
1897+
if ($before) {
1898+
$action = $originalAction;
1899+
$this->applyBeforeHandler($action,$database,$tables[0],$ids[$k],$before,$input);
1900+
}
1901+
18971902
$inputs[$k] = $input;
18981903
}
1899-
19001904
return compact('action','database','tables','key','page','filters','fields','orderings','transform','multi','inputs','collect','select','before','after');
19011905
}
19021906

0 commit comments

Comments
 (0)