test duplicate database writes

Send Snippet To: Save this snippet to Code Collector Pro -- view all balzan's snippets
language: PHP
license: Other

Code for Snippet:

	private function upsertObject(SS_HTTPRequest $request, SS_HTTPResponse &$response, Member $member) {
		$payload = json_decode($request->getBody(), true);
		if ($payload) {
			$escapedItemID = Convert::raw2sql($payload['UUID']);
			$item = DataObject::get_one("Person", "UUID = '" . $escapedItemID . "'");
			if(!$item) {
				$item = new Person();
				$this->packageJsonResponse($response, $item->getField("UUID"));
			catch(SS_DatabaseException $e){
				$lines= explode( PHP_EOL,$e->getMessage());
				$this->packageJsonResponse($response, $lines[count($lines) - 1]);
				///"Duplicate entry '0-0671860013624' for key 'IndexPersonEventIDIdentifier'"
		$this->httpError(404, "Invalid payload");	
comments powered by Disqus


Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 188
Date Added: 2015-11-12 03:22:12
Last Modified: 2015-11-11 20:22:26

Web Analytics