Commit graph

339 commits

Author SHA1 Message Date
xhorntail
bbbfbb40f4 Update api.php 2017-10-10 03:17:07 -06:00
Maurits van der Schee
46373011cd proper support for bianry and varbinary in mysql 2017-03-28 01:02:58 +02:00
Maurits van der Schee
0981d64463 Proper support for binary and varbinary 2017-03-28 00:46:42 +02:00
Maurits van der Schee
d55163dfb0 Support varbinary (for Adriano) 2017-03-28 00:27:13 +02:00
mevdschee
2e320f3796 table_names outside loop, see #216 and #217 2017-03-19 21:54:11 +01:00
mevdschee
ea61344256 maxLength should be positive, see #216 and #217 2017-03-19 21:39:32 +01:00
Maurits van der Schee
ef95cda39a bugfix in line with 212 2017-03-17 11:55:26 +01:00
Maurits van der Schee
9d14c9bb9d bugfix in line with #212 2017-03-17 11:54:35 +01:00
Barry Dam
13af017ce5 Bugfix multiple soft deletes (beforeHandler)
Following our conversation [210](https://github.com/mevdschee/php-crud-api/pull/210)

The first issue is in the "applyBeforeHandler":
```php
$callback($action,$database,$table,$id,$inputs[$i]);
```
$id shoud be $ids[$i], you've probally missed that one :
```php
$callback($action,$database,$table,$ids[$i],$inputs[$i]);
```

The second issue will rise if you do 2 or more (soft)deletes: Like
```php
DELETE http://localhost/api.php/categories/1,2
```
In the second [loop](https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1140-L1144) of the applyBeforeHandler, the $action is overwritten by the first loop.. so the in the second before call, the action is update.. so the 2nd one wil never be deleted
first:
```php
'before'=>function(&$cmd, $db, $tab, $id, &$in) { 
	$cmd;//delete
	// then we do this
	if ($cmd = 'delete') {
		$cmd = 'update'; // change command to update
		$in = (object) array(date('Y-m-d H:i:s', time()));
	}
}
```
In the second call cmd is changed to update by the first call:
```php
'before'=>function(&$cmd, $db, $tab, $id, &$in) { 
	$cmd;//update
	// so the code below never gets executed
	if ($cmd = 'delete') {
		$cmd = 'update'; // change command to update
		$in = (object) array(date('Y-m-d H:i:s', time()));
	}
}
```
I fixed this by storing the $action in a temp variable $origaction; and reset the $action in every start of the loop
```php
protected function applyBeforeHandler(&$action,&$database,&$table,&$ids,&$callback,&$inputs) {
	if (is_callable($callback,true)) {
		$max = count($ids)?:count($inputs);
		$origaction = $action;
		for ($i=0;$i<$max;$i++) {
			$action = $origaction;
			if (!isset($ids[$i])) $ids[$i] = false;
			if (!isset($inputs[$i])) $inputs[$i] = false;
			$callback($action,$database,$table,$ids[$i],$inputs[$i]);
		}
	}
}
```

Then the last error, which I allready pointed out before.
The call to the [applyBeforeHandler](https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1888-L1890)
should be placed AFTER the [foreach](https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1892-L1901)
Right now the [filterInputByFields ](https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1893) filteres out the "delete" column which I just inserted in my "before" statement.
We may presume that the backend dev kwows what consequences his action have by changing input, so there's no need to call the applyInputTenancy, applyInputSanitizer, applyInputValidator after the applyBeforeHandler is called.
So we need to change [this](https://github.com/mevdschee/php-crud-api/blob/master/api.php#L1888-L1901) to:
```php
foreach ($inputs as $k=>$context) {
	$input = $this->filterInputByFields($context,$fields[$tables[0]]);

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

	$this->convertInputs($input,$fields[$tables[0]]);
	$inputs[$k] = $input;
}


if ($before) {
	$this->applyBeforeHandler($action,$database,$tables[0],$key[0],$before,$inputs);
}
```

Barry
2017-03-17 10:38:46 +01:00
Maurits van der Schee
07e5ce5e1f fix soft delete 2017-03-17 03:01:35 +01:00
Maurits van der Schee
c240c4fdcd bugfix 2017-03-17 02:14:33 +01:00
Maurits van der Schee
75febbe3a5 some adjustments 2017-03-17 01:45:33 +01:00
Maurits van der Schee
c3fd4564bf Merge pull request #208 from appcrew/hotfix/1.0.8_swagger
Swagger: Output swagger description
2017-03-17 01:45:08 +01:00
Maurits van der Schee
ebb8fecc0e Fix for #208 2017-03-17 01:43:54 +01:00
Maurits van der Schee
919e820ba0 Some fixes 2017-03-17 01:29:52 +01:00
Barry Dam
68a4043965 call before multiple times
[refererring to](https://github.com/mevdschee/php-crud-api/pull/210)
2017-03-16 13:16:07 +01:00
Barry Dam
1d105ad435 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.
2017-03-16 09:35:51 +01:00
mevdschee
753c0c05bb bugfix 2017-03-16 09:33:24 +01:00
Benedikt Dahm
aada5cab0a Swagger: Output swagger description when api.php (__FILE__) is requested and no path requested entitiy is given 2017-03-15 23:26:13 +01:00
Maurits van der Schee
71116bc8e5 12.04 compatability fix 2017-03-15 22:57:50 +01:00
Maurits van der Schee
33d82a6a08 12.04 compatability fix 2017-03-15 22:55:53 +01:00
Maurits van der Schee
c05cb8d130 cleanup construct 2017-03-15 22:32:28 +01:00
Maurits van der Schee
b91bd3177a cleanup construct 2017-03-15 19:17:31 +01:00
mevdschee
fec8b5ccef fix #207 2017-03-15 17:37:39 +01:00
Maurits van der Schee
c6d79bbdf3 Merge branch 'master' into patch-1 2017-03-15 17:36:15 +01:00
mevdschee
b11f5966e6 Fix for #130 2017-03-15 17:26:59 +01:00
Barry Dam
70922c6ec2 Possible fix for issue 206
Possible fix for [issue 206](https://github.com/mevdschee/php-crud-api/issues/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');
}
```
2017-03-15 15:35:27 +01:00
Maurits van der Schee
272f5759f4 Adjust before handler to facilitate #130 2017-03-12 14:17:57 +01:00
Maurits van der Schee
4cf339c9ea Before handler to facilitate #151 2017-03-12 09:56:27 +01:00
Maurits van der Schee
7ff9ff9d30 Allow error logging 2017-03-11 09:04:08 +01:00
Maurits van der Schee
1a41e008e7 whitespace 2017-03-11 01:46:37 +01:00
Maurits van der Schee
bc31c2ba67 As discussed in #200 2017-03-11 00:22:59 +01:00
Maurits van der Schee
4e27405863 As discussed in #200 2017-03-10 23:09:25 +01:00
Maurits van der Schee
ee34a99942 As discussed in #200 2017-03-10 23:00:07 +01:00
Maurits van der Schee
d50eac6813 Merge pull request #200 from VyseExhale/patch-1
after_create
2017-03-10 22:40:29 +01:00
Rob Cermak
cefe7b44e9 Fix for schema object. If no fields are required, do not add required tag. Fix to tests (Token->TOKEN). 2017-03-10 18:47:30 +00:00
Barry Dam
b712ebc8d7 after_create
Hi Maurits,

I needed a callback function that got triggered on a new db entry (Create).

For example I wanted to send an e-mail to a newly registered member.
In this example I have a "members" table with the columns: id , firstName, lastName, email
the yourEmailFunction method will send a welcome message to the newly entered member.

```php
$api = new PHP_CRUD_API(array(
   'after_create'=>function($db,$tab,$row) {
      if ($tab == 'members') 
         yourEmailFunction($row['firstName'],$row['lastName'],$row['email']);
      }
   }
));
$api->executeCommand();
```
Tell me you thoughts... maybe if you like it and willing to accept the pull request I can also create an after_delete and after_update method.
2017-03-09 15:14:08 +01:00
Maurits van der Schee
88b7bdb41a bugfix 2017-03-07 04:17:15 +01:00
Maurits van der Schee
40be702430 Merge branch 'master' of github.com:mevdschee/php-crud-api 2017-03-05 02:41:26 +01:00
Maurits van der Schee
c060399550 Improve CORS header implementation 2017-03-05 02:40:20 +01:00
Maurits van der Schee
3fadb01951 updated json2xml.php 2017-03-03 23:55:10 +01:00
Karl Hughes
244696c091 Allowing json, jsonb in postgres 2017-02-27 12:50:21 -06:00
mevdschee
4f5f7cf2d3 bugfix 2017-02-27 14:33:07 +01:00
Maurits van der Schee
7e0c2410be bugfix 2017-02-26 23:05:16 +01:00
Maurits van der Schee
6da5732fd0 Fix for #193, thank you jr3cermak 2017-02-26 14:33:41 +01:00
Maurits van der Schee
18b29420e8 Fix for #193, thank you jr3cermak 2017-02-26 14:15:06 +01:00
Maurits van der Schee
16a2abec99 Fix for #193, thank you jr3cermak 2017-02-26 13:57:41 +01:00
Maurits van der Schee
1e7b510062 bugfix 2017-02-26 04:05:09 +01:00
Maurits van der Schee
082d5e4a37 bugfix 2017-02-26 04:01:43 +01:00
Maurits van der Schee
34c7ac98ff Small fix for #192 and #192 to detect integer types 2017-02-26 02:02:54 +01:00