Permalink
Browse files

bug fix server-side after POST /edit

  • Loading branch information...
1 parent c07e1cc commit b37172c7ed76d3a48921d61482b298eda7b30474 Anonymous Coward committed May 26, 2014
Showing with 13 additions and 14 deletions.
  1. +13 −14 app.php
View
@@ -182,22 +182,20 @@ class AppLevelException extends Exception {}
$form = $app['form.factory']->create($geopoi = new GeoPoiType($doc), null, array('action'=> 'edit/'.$doc['_id']));
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
- if ($form->isSubmitted()) {
- $savdoc = $geopoi->merge($form->getData());
- $savdoc['_id'] = new MongoId($doc['_id']);
- try {
- $result = $ugc_coll->save($savdoc);
- if ( !isset($result['ok']) || !$result['ok'] ) {
- throw new AppLevelException("Error saving to database (update), try again later", 503);
- }
- $doc = $ugc_coll->findOne(array('_id' => new MongoId($reqid)));
- } catch ( MongoResultException $e ) {
- throw new AppLevelException("Error saving to database, try again later", 503, $e);
+ if (!$form->isSubmitted()) {
+ return $app->json(array("error"=>"Error in POST"), 500);
+ }
+ $savdoc = $geopoi->merge($form->getData());
+ $savdoc['_id'] = new MongoId($doc['_id']);
+ try {
+ $result = $ugc_coll->save($savdoc);
+ if ( !isset($result['ok']) || !$result['ok'] ) {
+ throw new AppLevelException("Error saving to database (update), try again later", 503);
}
-
- return $app->json($doc);
+ $doc = $ugc_coll->findOne(array('_id' => new MongoId($reqid)));
+ } catch ( MongoResultException $e ) {
+ throw new AppLevelException("Error saving to database, try again later", 503, $e);
}
- return $app->json(array("error"=>"Error in POST"), 500);
}
} catch ( AppLevelException $e ) {
return $app->json(array("error"=> $e->getMessage() . ($e->getPrevious()?' -- '.$e->getPrevious()->getMessage() : '')), $e->getCode());
@@ -208,6 +206,7 @@ class AppLevelException extends Exception {}
} catch ( Exception $e ) {
return $app->json(array("error"=>"The query failed for an unspecified reason. This might be a caused by a bug and/or a malformed request. You may want to notify the site administrator about it"), 500);
}
+ $doc['_id'] = (string)$doc['_id'];
$doc['cached_form'] = $app['twig']->render('ajaxform.twig', array(
'form' => $form->createView()
));

0 comments on commit b37172c

Please sign in to comment.