private function getOneLazaretFile() { //The lazaret session $lazaretSession = new \Alchemy\Phrasea\Model\Entities\LazaretSession(); $lazaretSession->setUser(self::$DI['user']); $lazaretSession->setUpdated(new \DateTime('now')); $lazaretSession->setCreated(new \DateTime('-1 day')); //The lazaret file $lazaretFile = new \Alchemy\Phrasea\Model\Entities\LazaretFile(); $lazaretFile->setOriginalName('test'); $lazaretFile->setFilename('test001.jpg'); $lazaretFile->setThumbFilename('test001.jpg'); $lazaretFile->setBaseId(self::$DI['collection']->get_base_id()); $lazaretFile->setSession($lazaretSession); $lazaretFile->setSha256('3191af52748620e0d0da50a7b8020e118bd8b8a0845120b0bb'); $lazaretFile->setUuid('7b8ef0e3-dc8f-4b66-9e2f-bd049d175124'); $lazaretFile->setCreated(new \DateTime('-1 day')); $lazaretFile->setUpdated(new \DateTime('now')); return $lazaretFile; }
public function add_record(Application $app, Request $request) { if (count($request->files->get('file')) == 0) { throw new API_V1_exception_badrequest('Missing file parameter'); } if (!$request->files->get('file') instanceof Symfony\Component\HttpFoundation\File\UploadedFile) { throw new API_V1_exception_badrequest('You can upload one file at time'); } $file = $request->files->get('file'); /* @var $file Symfony\Component\HttpFoundation\File\UploadedFile */ if (!$file->isValid()) { throw new API_V1_exception_badrequest('Datas corrupted, please try again'); } if (!$request->get('base_id')) { throw new API_V1_exception_badrequest('Missing base_id parameter'); } $collection = \collection::get_from_base_id($this->app, $request->get('base_id')); if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->get('base_id'), 'canaddrecord')) { throw new API_V1_exception_forbidden(sprintf('You do not have access to collection %s', $collection->get_label($this->app['locale']))); } $media = $app['mediavorus']->guess($file->getPathname()); $Package = new File($this->app, $media, $collection, $file->getClientOriginalName()); if ($request->get('status')) { $Package->addAttribute(new Status($app, $request->get('status'))); } $session = new Alchemy\Phrasea\Model\Entities\LazaretSession(); $session->setUser($app['authentication']->getUser()); $app['EM']->persist($session); $app['EM']->flush(); $reasons = $output = null; $callback = function ($element, $visa, $code) use($app, &$reasons, &$output) { if (!$visa->isValid()) { $reasons = []; foreach ($visa->getResponses() as $response) { $reasons[] = $response->getMessage($app['translator']); } } $output = $element; }; switch ($request->get('forceBehavior')) { case '0': $behavior = BorderManager::FORCE_RECORD; break; case '1': $behavior = BorderManager::FORCE_LAZARET; break; case null: $behavior = null; break; default: throw new API_V1_exception_badrequest(sprintf('Invalid forceBehavior value `%s`', $request->get('forceBehavior'))); break; } $app['border-manager']->process($session, $Package, $callback, $behavior); $ret = ['entity' => null]; if ($output instanceof \record_adapter) { $ret['entity'] = '0'; $ret['url'] = '/records/' . $output->get_sbas_id() . '/' . $output->get_record_id() . '/'; $app['phraseanet.SE']->addRecord($output); } if ($output instanceof LazaretFile) { $ret['entity'] = '1'; $ret['url'] = '/quarantine/item/' . $output->getId() . '/'; } $result = new API_V1_result($this->app, $request, $this); $result->set_datas($ret); return $result; }