@@ -1134,15 +1134,9 @@ protected function parseGetParameterArray($get,$name,$characters) {
1134
1134
return $ values ;
1135
1135
}
1136
1136
1137
- protected function applyAfterCreate ($ callback ,$ database ,$ table ,$ id ) {
1137
+ protected function applyAfterWrite ($ callback ,$ action , $ database ,$ table ,$ id, $ input ) {
1138
1138
if (is_callable ($ callback ,true )) {
1139
- $ fields = $ this ->findPrimaryKeys ($ table ,$ database );
1140
- if (count ($ fields )!=1 ) $ this ->exitWith404 ('1pk ' );
1141
- if ($ result = $ this ->db ->query ("SELECT * FROM ! WHERE ! = ? " ,array ($ table , $ fields [0 ], $ id ))) {
1142
- $ object = $ this ->db ->fetchAssoc ($ result );
1143
- $ callback ($ database ,$ table ,$ object );
1144
- $ this ->db ->close ($ result );
1145
- }
1139
+ $ callback ($ action ,$ database ,$ table ,$ id ,$ input );
1146
1140
}
1147
1141
}
1148
1142
@@ -1481,7 +1475,7 @@ protected function createObject($input,$tables) {
1481
1475
if (!$ result ) return null ;
1482
1476
$ insertId = $ this ->db ->insertId ($ result );
1483
1477
extract ($ this ->settings );
1484
- $ this ->applyAfterCreate ( $ after_create , $ database ,$ tables [0 ],$ insertId );
1478
+ $ this ->applyAfterWrite ( $ after_write , ' create ' , $ database ,$ tables [0 ],$ insertId, $ input );
1485
1479
return $ insertId ;
1486
1480
}
1487
1481
@@ -1518,6 +1512,7 @@ protected function updateObject($key,$input,$filters,$tables) {
1518
1512
$ this ->addWhereFromFilters ($ filters [$ table ],$ sql ,$ params );
1519
1513
$ result = $ this ->db ->query ($ sql ,$ params );
1520
1514
if (!$ result ) return null ;
1515
+ $ this ->applyAfterWrite ($ after_write ,'update ' ,$ database ,$ tables [0 ],$ key [0 ],$ input );
1521
1516
return $ this ->db ->affectedRows ($ result );
1522
1517
}
1523
1518
@@ -1550,6 +1545,7 @@ protected function deleteObject($key,$filters,$tables) {
1550
1545
$ this ->addWhereFromFilters ($ filters [$ table ],$ sql ,$ params );
1551
1546
$ result = $ this ->db ->query ($ sql ,$ params );
1552
1547
if (!$ result ) return null ;
1548
+ $ this ->applyAfterWrite ($ after_write ,'delete ' ,$ database ,$ tables [0 ],$ key [0 ],array ());
1553
1549
return $ this ->db ->affectedRows ($ result );
1554
1550
}
1555
1551
@@ -1594,6 +1590,7 @@ protected function incrementObject($key,$input,$filters,$tables,$fields) {
1594
1590
$ this ->addWhereFromFilters ($ filters [$ table ],$ sql ,$ params );
1595
1591
$ result = $ this ->db ->query ($ sql ,$ params );
1596
1592
if (!$ result ) return null ;
1593
+ $ this ->applyAfterWrite ($ after_write ,'increment ' ,$ database ,$ tables [0 ],$ key [0 ],$ input );
1597
1594
return $ this ->db ->affectedRows ($ result );
1598
1595
}
1599
1596
@@ -2124,7 +2121,7 @@ public function __construct($config) {
2124
2121
$ input_validator = isset ($ input_validator )?$ input_validator :null ;
2125
2122
$ auto_include = isset ($ auto_include )?$ auto_include :null ;
2126
2123
$ allow_origin = isset ($ allow_origin )?$ allow_origin :null ;
2127
- $ after_create = isset ($ after_create )?$ after_create :null ;
2124
+ $ after_write = isset ($ after_write )?$ after_write :null ;
2128
2125
2129
2126
$ db = isset ($ db )?$ db :null ;
2130
2127
$ method = isset ($ method )?$ method :null ;
@@ -2176,7 +2173,7 @@ public function __construct($config) {
2176
2173
}
2177
2174
2178
2175
$ this ->db = $ db ;
2179
- $ this ->settings = compact ('method ' , 'request ' , 'get ' , 'post ' , 'origin ' , 'database ' , 'table_authorizer ' , 'record_filter ' , 'column_authorizer ' , 'tenancy_function ' , 'input_sanitizer ' , 'input_validator ' , 'after_create ' , 'auto_include ' , 'allow_origin ' );
2176
+ $ this ->settings = compact ('method ' , 'request ' , 'get ' , 'post ' , 'origin ' , 'database ' , 'table_authorizer ' , 'record_filter ' , 'column_authorizer ' , 'tenancy_function ' , 'input_sanitizer ' , 'input_validator ' , 'after_write ' , 'auto_include ' , 'allow_origin ' );
2180
2177
}
2181
2178
2182
2179
public static function php_crud_api_transform (&$ tables ) {
0 commit comments