public function acceptElement(Request $request, $file_id)
    {
        $ret = ['success' => false, 'message' => '', 'result'  => []];

        //Mandatory parameter
        if (null === $recordId = $request->request->get('record_id')) {
            $ret['message'] = $this->app->trans('You must give a destination record');

            return $this->app->json($ret);
        }

        /** @var LazaretFile $lazaretFile */
        $lazaretFile = $this->getLazaretFileRepository()->find($file_id);

        if (null === $lazaretFile) {
            $ret['message'] = $this->app->trans('File is not present in quarantine anymore, please refresh');

            return $this->app->json($ret);
        }

        $found = false;

        //Check if the chosen record is eligible to the substitution
        foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $record) {
            if ($record->getRecordId() !== (int) $recordId) {
                continue;
            }

            $found = true;
            break;
        }

        if (!$found) {
            $ret['message'] = $this->app->trans('The destination record provided is not allowed');

            return $this->app->json($ret);
        }

        $path = $this->app['tmp.lazaret.path'] . '/';
        $lazaretFileName = $path .$lazaretFile->getFilename();
        $lazaretThumbFileName = $path .$lazaretFile->getThumbFilename();

        try {
            $media = $this->app->getMediaFromUri($lazaretFileName);

            $record = $lazaretFile->getCollection($this->app)->get_databox()->get_record($recordId);
            $this->getSubDefinitionSubstituer()->substituteDocument($record, $media);
            $this->getDataboxLogger($record->getDatabox())->log(
                $record,
                \Session_Logger::EVENT_SUBSTITUTE,
                'HD',
                ''
            );

            //Delete lazaret file
            $manager = $this->getEntityManager();
            $manager->remove($lazaretFile);
            $manager->flush();

            $ret['success'] = true;
        } catch (\Exception $e) {
            $ret['message'] = $this->app->trans('An error occured');
        }

        try {
            $this->getFilesystem()->remove([$lazaretFileName, $lazaretThumbFileName]);
        } catch (IOException $e) {

        }

        return $this->app->json($ret);
    }
public function acceptElement(Request $request, $file_id)
    {
        $ret = ['success' => false, 'message' => '', 'result'  => []];

        //Mandatory parameter
        if (null === $recordId = $request->request->get('record_id')) {
            $ret['message'] = $this->app->trans('You must give a destination record');

            return $this->app->json($ret);
        }

        /** @var LazaretFile $lazaretFile */
        $lazaretFile = $this->getLazaretFileRepository()->find($file_id);

        if (null === $lazaretFile) {
            $ret['message'] = $this->app->trans('File is not present in quarantine anymore, please refresh');

            return $this->app->json($ret);
        }

        $found = false;

        //Check if the chosen record is eligible to the substitution
        foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $record) {
            if ($record->getRecordId() !== (int) $recordId) {
                continue;
            }

            $found = true;
            break;
        }

        if (!$found) {
            $ret['message'] = $this->app->trans('The destination record provided is not allowed');

            return $this->app->json($ret);
        }

        $path = $this->app['tmp.lazaret.path'] . '/';
        $lazaretFileName = $path .$lazaretFile->getFilename();
        $lazaretThumbFileName = $path .$lazaretFile->getThumbFilename();

        try {
            $media = $this->app->getMediaFromUri($lazaretFileName);

            $record = $lazaretFile->getCollection($this->app)->get_databox()->get_record($recordId);
            $this->getSubDefinitionSubstituer()->substituteDocument($record, $media);
            $this->getDataboxLogger($record->getDatabox())->log(
                $record,
                \Session_Logger::EVENT_SUBSTITUTE,
                'HD',
                ''
            );

            //Delete lazaret file
            $manager = $this->getEntityManager();
            $manager->remove($lazaretFile);
            $manager->flush();

            $ret['success'] = true;
        } catch (\Exception $e) {
            $ret['message'] = $this->app->trans('An error occured');
        }

        try {
            $this->getFilesystem()->remove([$lazaretFileName, $lazaretThumbFileName]);
        } catch (IOException $e) {

        }

        return $this->app->json($ret);
    }
public function acceptElement ( Request $ request , $ file_id ) { $ ret = [ 'success' => false , 'message' => '' , 'result' => [ ] ] ; //Mandatory parameter if ( null === $ recordId = $ request -> request -> get ( 'record_id' ) ) { $ ret [ 'message' ] = $ this -> app -> trans ( 'You must give a destination record' ) ; return $ this -> app -> json ( $ ret ) ; } /** @var LazaretFile $lazaretFile */ $ lazaretFile = $ this -> getLazaretFileRepository ( ) -> find ( $ file_id ) ; if ( null === $ lazaretFile ) { $ ret [ 'message' ] = $ this -> app -> trans ( 'File is not present in quarantine anymore, please refresh' ) ; return $ this -> app -> json ( $ ret ) ; } $ found = false ; //Check if the chosen record is eligible to the substitution foreach ( $ lazaretFile -> getRecordsToSubstitute ( $ this -> app ) as $ record ) { if ( $ record -> getRecordId ( ) !== ( int ) $ recordId ) { continue ; } $ found = true ; break ; } if ( ! $ found ) { $ ret [ 'message' ] = $ this -> app -> trans ( 'The destination record provided is not allowed' ) ; return $ this -> app -> json ( $ ret ) ; } $ path = $ this -> app [ 'tmp.lazaret.path' ] . '/' ; $ lazaretFileName = $ path . $ lazaretFile -> getFilename ( ) ; $ lazaretThumbFileName = $ path . $ lazaretFile -> getThumbFilename ( ) ; try { $ media = $ this -> app -> getMediaFromUri ( $ lazaretFileName ) ; $ record = $ lazaretFile -> getCollection ( $ this -> app ) -> get_databox ( ) -> get_record ( $ recordId ) ; $ this -> getSubDefinitionSubstituer ( ) -> substituteDocument ( $ record , $ media ) ; $ this -> getDataboxLogger ( $ record -> getDatabox ( ) ) -> log ( $ record , \ Session_Logger :: EVENT_SUBSTITUTE , 'HD' , '' ) ; //Delete lazaret file $ manager = $ this -> getEntityManager ( ) ; $ manager -> remove ( $ lazaretFile ) ; $ manager -> flush ( ) ; $ ret [ 'success' ] = true ; } catch ( \ Exception $ e ) { $ ret [ 'message' ] = $ this -> app -> trans ( 'An error occured' ) ; } try { $ this -> getFilesystem ( ) -> remove ( [ $ lazaretFileName , $ lazaretThumbFileName ] ) ; } catch ( IOException $ e ) { } return $ this -> app -> json ( $ ret ) ; }
Substitute a record element by a lazaret element

@param Request     $request The current request
@param int         $file_id A lazaret element id

@return Response
Substitute a record element by a lazaret element