'error', 'key' => 'project', 'method' => 'update', 'data' => '', ]; $token = $request->headers->get('x-auth-token'); $security->isGranted('MAESTRO_PROJECT_PROJECTS_UPDATE', $token); $this->validate($request, $respond); $data = json_decode($request->getContent(), true); if (isset($data['data']) && isset($data['data']['productsImport']) && isset($data['data']['groupIds'])) { $productsImport = filter_var($data['data']['productsImport'], FILTER_VALIDATE_BOOLEAN); $view = new ProjectUpdateView( $id, isset($data['data']['title']) && $data['data']['title'] ? $data['data']['title'] : "", isset($data['data']['description']) && $data['data']['description'] ? $data['data']['description'] : "", $productsImport, isset($data['data']['groupIds']["ownerId"]) && $data['data']['groupIds']["ownerId"] ? $data['data']['groupIds']["ownerId"] : null, isset($data['data']['groupIds']["associatedIds"]) && $data['data']['groupIds']["associatedIds"] ? $data['data']['groupIds']["associatedIds"] : [] ); } if (isset($data['lastStep'])) { $lastStep = $data['lastStep']; } else { $lastStep = false; } $allowedMimeTypes = [ 'application/msword', // doc 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // docx 'application/vnd.ms-excel', // xls 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // xlsx 'application/pdf', // pdf 'text/plain', // txt 'text/csv', // csv 'image/png', // png 'image/jpeg', // jpg 'image/gif', // gif ]; $filePath = $this->getParameter('files_directory') . md5($id); if (!file_exists($filePath) && !mkdir($filePath, 0755, true) && !is_dir($filePath)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $filePath)); } //UPLOAD PROJECT DOCUMENTS $documents = []; foreach ($data['data']['documents'] as $document) { if (in_array($document['mimeType'], $allowedMimeTypes, false)) { $base64 = base64_decode($document['base64']); if (file_exists($filePath . '/' . $document['filename'])) { $newName = uniqid() . '_' . $document['filename']; $fullPath = $filePath . '/' . $newName; $document['filename'] = $newName; } else { $fullPath = $filePath . '/' . $document['filename']; } file_put_contents($fullPath, $base64); $document['path'] = $fullPath; $documents[] = $document; } } //END UPLOAD PROJECT DOCUMENTS $project = $updateQuery->update($view, $lastStep, $documents); if ($project) { $body['type'] = 'success'; $body['data'] = $project; $respond->statusOK(); //DELETE THE CACHE IF WE HAVE, BECAUSE THE VALUE WAS CHANGED $cache = new FilesystemAdapter(); $cache->clear(); //END DELETING CACHE } else { $respond->statusUnprocessableEntity(); } return $respond->createBody($body)->respond(); } }