add php modification

This commit is contained in:
aynsix
2020-04-02 14:56:27 +03:00
parent 661f09e3fd
commit 51b10b6bec
4 changed files with 174 additions and 65 deletions

View File

@@ -47,6 +47,10 @@ class ApiOrderController extends BaseOrderController
use FilesystemAware;
use JsonBodyAware;
/**
* @param Request $request
* @return Response
*/
public function createAction(Request $request)
{
$data = $this->decodeJsonBody($request, 'orders.json#/definitions/order_request');
@@ -54,7 +58,13 @@ class ApiOrderController extends BaseOrderController
$availableRecords = $this->toRequestedRecords($data->data->records);
$records = $this->filterOrderableRecords($availableRecords);
$recordRequest = new RecordsRequest($records, new ArrayCollection($availableRecords), null, RecordsRequest::FLATTEN_YES);
$recordRequest = new RecordsRequest(
$records, // orderable records
new ArrayCollection([]), // rejected (rights)
new ArrayCollection($availableRecords), // all records from request
null, // basket
RecordsRequest::FLATTEN_YES // orderable records is stories + children
);
$filler = new OrderFiller($this->app['repo.collection-references'], $this->app['orm.em']);
@@ -62,7 +72,13 @@ class ApiOrderController extends BaseOrderController
$order = new Order();
$order->setUser($this->getAuthenticatedUser());
$order->setDeadline(new \DateTime($data->data->deadline, new \DateTimeZone('UTC')));
try {
$order->setDeadline(new \DateTime()); // safe value in case of data->deadline is invalid
$order->setDeadline(new \DateTime($data->data->deadline, new \DateTimeZone('UTC')));
}
catch (\Exception $e) {
// no-op, will end-up with safe value
}
$order->setOrderUsage($data->data->usage);
$order->setNotificationMethod(Order::NOTIFY_WEBHOOK);
@@ -139,8 +155,9 @@ class ApiOrderController extends BaseOrderController
}
/**
* @param int $orderId
* @param $orderId
* @return Response
* @throws \Exception
*/
public function getArchiveAction($orderId)
{
@@ -162,7 +179,12 @@ class ApiOrderController extends BaseOrderController
$user = $this->getAuthenticatedUser();
$subdefs = $this->findDataboxSubdefNames();
$exportData = $export->prepare_export($user, $this->getFilesystem(), $subdefs, true, true);
try {
$exportData = $export->prepare_export($user, $this->getFilesystem(), $subdefs, true, true);
}
catch (\Exception $e) {
throw new NotFoundHttpException(sprintf('No archive could be downloaded for Order "%d"', $order->getId()));
}
/** @var Token $token */
$token = $this->app['manipulator.token']->createDownloadToken($user, serialize($exportData));
@@ -248,8 +270,13 @@ class ApiOrderController extends BaseOrderController
$filtered = [];
foreach ($records as $index => $record) {
if (!$record->isStory() && $acl->has_right_on_base($record->getBaseId(), \ACL::CANCMD)) {
$filtered[$index] = $record;
try {
if ($acl->has_right_on_base($record->getBaseId(), \ACL::CANCMD)) {
$filtered[$index] = $record;
}
}
catch (\Exception $e) {
// will NOT happen since \ACL::CANCMD IS a known right
}
}