Skip to content

Commit 70922c6

Browse files
authored
Possible fix for issue 206
Possible fix for [issue 206](#206) soft delete example ```php 'before'=>function(&$cmd, &$db, &$tab, &$id, &$in) { if ($cmd == 'delete') { $cmd = 'update'; // change command to update foreach($in as $k => $o) { $in[$k]->deleted = date('Y-m-d H:i:s', time()); } } }, 'column_authorizer'=>function($cmd, $db ,$tab, $col) { return ( ! in_array($col, array('deleted'))); }, 'record_filter'=>function($cmd,$db,$tab) { return array('deleted,is,null'); } ```
1 parent 0da7a62 commit 70922c6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

api.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,9 +1879,6 @@ protected function getParameters($settings) {
18791879
// input
18801880
$multi = $post[0]=='[';
18811881
$contexts = $this->retrieveInputs($post);
1882-
if ($before) {
1883-
$this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$contexts);
1884-
}
18851882
foreach ($contexts as $context) {
18861883
$input = $this->filterInputByFields($context,$fields[$tables[0]]);
18871884

@@ -2635,6 +2632,14 @@ public function executeCommand() {
26352632
$this->swagger($this->settings);
26362633
} else {
26372634
$parameters = $this->getParameters($this->settings);
2635+
if ($parameters['before']) {
2636+
if (count($parameters['inputs']) == 0) {
2637+
for($i=1; $i <= count(explode(',', $parameters['key'][0])); $i++) {
2638+
$parameters['inputs'][] = new stdClass();
2639+
}
2640+
}
2641+
$this->applyBeforeHandler($parameters['action'], $parameters['database'],$parameters['tables'][0],$parameters['key'][0],$parameters['before'],$parameters['inputs']);
2642+
}
26382643
switch($parameters['action']){
26392644
case 'list': $output = $this->listCommand($parameters); break;
26402645
case 'read': $output = $this->readCommand($parameters); break;

0 commit comments

Comments
 (0)