public function saveFile(FileCreateOrUpdateEvent $event)
    {
        $model = $event->getModel();
        $model->setFile(sprintf("tmp/%s", $event->getUploadedFile()->getFilename()));
        $con = Propel::getWriteConnection(ProductImageTableMap::DATABASE_NAME);
        $con->beginTransaction();

        try {
            $nbModifiedLines = $model->save($con);
            $event->setModel($model);

            if (!$nbModifiedLines) {
                throw new FileException(
                    sprintf(
                        'File "%s" (type %s) with parent id %s failed to be saved',
                        $event->getParentName(),
                        \get_class($model),
                        $event->getParentId()
                    )
                );
            }

            $newUploadedFile = $this->fileManager->copyUploadedFile($event->getModel(), $event->getUploadedFile());

            $event->setUploadedFile($newUploadedFile);
            $con->commit();
        } catch (\Exception $e) {
            $con->rollBack();

            throw $e;
        }
    }
public function saveFile(FileCreateOrUpdateEvent $event)
    {
        $model = $event->getModel();
        $model->setFile(sprintf("tmp/%s", $event->getUploadedFile()->getFilename()));
        $con = Propel::getWriteConnection(ProductImageTableMap::DATABASE_NAME);
        $con->beginTransaction();

        try {
            $nbModifiedLines = $model->save($con);
            $event->setModel($model);

            if (!$nbModifiedLines) {
                throw new FileException(
                    sprintf(
                        'File "%s" (type %s) with parent id %s failed to be saved',
                        $event->getParentName(),
                        \get_class($model),
                        $event->getParentId()
                    )
                );
            }

            $newUploadedFile = $this->fileManager->copyUploadedFile($event->getModel(), $event->getUploadedFile());

            $event->setUploadedFile($newUploadedFile);
            $con->commit();
        } catch (\Exception $e) {
            $con->rollBack();

            throw $e;
        }
    }
public function saveFile ( FileCreateOrUpdateEvent $ event ) { $ model = $ event -> getModel ( ) ; $ model -> setFile ( sprintf ( "tmp/%s" , $ event -> getUploadedFile ( ) -> getFilename ( ) ) ) ; $ con = Propel :: getWriteConnection ( ProductImageTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; try { $ nbModifiedLines = $ model -> save ( $ con ) ; $ event -> setModel ( $ model ) ; if ( ! $ nbModifiedLines ) { throw new FileException ( sprintf ( 'File "%s" (type %s) with parent id %s failed to be saved' , $ event -> getParentName ( ) , \ get_class ( $ model ) , $ event -> getParentId ( ) ) ) ; } $ newUploadedFile = $ this -> fileManager -> copyUploadedFile ( $ event -> getModel ( ) , $ event -> getUploadedFile ( ) ) ; $ event -> setUploadedFile ( $ newUploadedFile ) ; $ con -> commit ( ) ; } catch ( \ Exception $ e ) { $ con -> rollBack ( ) ; throw $ e ; } }
Take care of saving a file in the database and file storage

@param FileCreateOrUpdateEvent $event Image event

@throws \Thelia\Exception\FileException|\Exception
Take care of saving a file in the database and file storage