Skip to content

Commit

Permalink
#285 - fixing remaining major issues highlighted by Scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
alphadevx committed Aug 17, 2017
1 parent 470d2f1 commit 6002417
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
61 changes: 32 additions & 29 deletions Alpha/Controller/ActiveRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,13 @@ public function doPUT($request)

$record->load($params['ActiveRecordID']);
$record->populateFromArray($params);
$record->save();

try {
$record->save();
} catch (ValidationException $e) {
self::$logger->warn($e->getMessage());
$this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
}

self::$logger->action('Saved '.$ActiveRecordType.' instance with ID '.$record->getID());

Expand All @@ -485,6 +491,31 @@ public function doPUT($request)
}

ActiveRecord::disconnect();

if ($accept == 'application/json') {
$view = View::getInstance($record, false, $accept);
$body = $view->detailedView();
$response = new Response(200);
$response->setHeader('Content-Type', 'application/json');
$response->setHeader('Location', $config->get('app.url').'/record/'.$params['ActiveRecordType'].'/'.$record->getID());
$response->setBody($body);
} else {
$response = new Response(301);

if ($this->getNextJob() != '') {
$response->redirect($this->getNextJob());
} else {
if ($this->request->isSecureURI()) {
$response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType='.urldecode($params['ActiveRecordType']).'&ActiveRecordID='.$record->getID().'&view=edit'));
} else {
$response->redirect($config->get('app.url').'/record/'.$params['ActiveRecordType'].'/'.$record->getID().'/edit');
}
}
}

self::$logger->debug('<<doPUT');

return $response;
} catch (SecurityException $e) {
self::$logger->warn($e->getMessage());
throw new ResourceNotAllowedException($e->getMessage());
Expand All @@ -494,35 +525,7 @@ public function doPUT($request)
} catch (RecordNotFoundException $e) {
self::$logger->warn($e->getMessage());
throw new ResourceNotFoundException('The record that you have requested cannot be found!');
} catch (ValidationException $e) {
self::$logger->warn($e->getMessage());
$this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
}

if ($accept == 'application/json') {
$view = View::getInstance($record, false, $accept);
$body = $view->detailedView();
$response = new Response(200);
$response->setHeader('Content-Type', 'application/json');
$response->setHeader('Location', $config->get('app.url').'/record/'.$params['ActiveRecordType'].'/'.$record->getID());
$response->setBody($body);
} else {
$response = new Response(301);

if ($this->getNextJob() != '') {
$response->redirect($this->getNextJob());
} else {
if ($this->request->isSecureURI()) {
$response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType='.urldecode($params['ActiveRecordType']).'&ActiveRecordID='.$record->getID().'&view=edit'));
} else {
$response->redirect($config->get('app.url').'/record/'.$params['ActiveRecordType'].'/'.$record->getID().'/edit');
}
}
}

self::$logger->debug('<<doPUT');

return $response;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Alpha/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,8 @@ public function process($request)
case 'TRACE':
$response = $this->doTRACE($request);
break;
default:
$response = $this->doGET($request);
}

return $response;
Expand Down
2 changes: 1 addition & 1 deletion Alpha/Model/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ public function set($prop, $value, $noChildMethods = false)
*
* @param string $prop The name of the property we are getting.
*
* @return \Alpha\Model\Type\Type|bool The complex type object found.
* @return \Alpha\Model\Type\Type|\Alpha\Model\Type\DEnum|bool The complex type object found.
*
* @since 1.0
*
Expand Down

0 comments on commit 6002417

Please sign in to comment.