public function emptyDatabase(Request $request, $databox_id)
    {
        $msg = $this->app->trans('An error occurred');
        $success = false;
        $taskCreated = false;

        try {
            $databox = $this->findDataboxById($databox_id);

            foreach ($databox->get_collections() as $collection) {
                if ($collection->get_record_amount() <= 500) {
                    $collection->empty_collection(500);
                } else {
                    /** @var TaskManipulator $taskManipulator */
                    $taskManipulator = $this->app['manipulator.task'];
                    $taskManipulator->createEmptyCollectionJob($collection);
                }
            }

            $msg = $this->app->trans('Base empty successful');
            $success = true;

            if ($taskCreated) {
                $msg = $this->app->trans('A task has been created, please run it to complete empty collection');
            }
        } catch (\Exception $e) {

        }

        if ('json' === $request->getRequestFormat()) {
            return $this->app->json([
                'success' => $success,
                'msg'     => $msg,
                'sbas_id' => $databox_id,
            ]);
        }

        // TODO: Can this method be called as HTML?
        return $this->app->redirectPath('admin_database', [
            'databox_id' => $databox_id,
            'error'      => 'file-too-big',
        ]);
    }
public function emptyDatabase(Request $request, $databox_id)
    {
        $msg = $this->app->trans('An error occurred');
        $success = false;
        $taskCreated = false;

        try {
            $databox = $this->findDataboxById($databox_id);

            foreach ($databox->get_collections() as $collection) {
                if ($collection->get_record_amount() <= 500) {
                    $collection->empty_collection(500);
                } else {
                    /** @var TaskManipulator $taskManipulator */
                    $taskManipulator = $this->app['manipulator.task'];
                    $taskManipulator->createEmptyCollectionJob($collection);
                }
            }

            $msg = $this->app->trans('Base empty successful');
            $success = true;

            if ($taskCreated) {
                $msg = $this->app->trans('A task has been created, please run it to complete empty collection');
            }
        } catch (\Exception $e) {

        }

        if ('json' === $request->getRequestFormat()) {
            return $this->app->json([
                'success' => $success,
                'msg'     => $msg,
                'sbas_id' => $databox_id,
            ]);
        }

        // TODO: Can this method be called as HTML?
        return $this->app->redirectPath('admin_database', [
            'databox_id' => $databox_id,
            'error'      => 'file-too-big',
        ]);
    }
public function emptyDatabase ( Request $ request , $ databox_id ) { $ msg = $ this -> app -> trans ( 'An error occurred' ) ; $ success = false ; $ taskCreated = false ; try { $ databox = $ this -> findDataboxById ( $ databox_id ) ; foreach ( $ databox -> get_collections ( ) as $ collection ) { if ( $ collection -> get_record_amount ( ) <= 500 ) { $ collection -> empty_collection ( 500 ) ; } else { /** @var TaskManipulator $taskManipulator */ $ taskManipulator = $ this -> app [ 'manipulator.task' ] ; $ taskManipulator -> createEmptyCollectionJob ( $ collection ) ; } } $ msg = $ this -> app -> trans ( 'Base empty successful' ) ; $ success = true ; if ( $ taskCreated ) { $ msg = $ this -> app -> trans ( 'A task has been created, please run it to complete empty collection' ) ; } } catch ( \ Exception $ e ) { } if ( 'json' === $ request -> getRequestFormat ( ) ) { return $ this -> app -> json ( [ 'success' => $ success , 'msg' => $ msg , 'sbas_id' => $ databox_id , ] ) ; } // TODO: Can this method be called as HTML? return $ this -> app -> redirectPath ( 'admin_database' , [ 'databox_id' => $ databox_id , 'error' => 'file-too-big' , ] ) ; }
Empty a databox

@param  Request $request    The current HTTP request
@param  integer $databox_id The requested databox
@return JsonResponse|RedirectResponse
Empty a databox