/**
  * Take care of saving a file in the database and file storage
  *
  * @param FileCreateOrUpdateEvent $event Image event
  *
  * @throws \Thelia\Exception\FileException|\Exception
  *
  */
 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;
     }
 }
Example #2
0
 /**
  * Take care of saving a file in the database and file storage
  *
  * @param FileCreateOrUpdateEvent $event Image event
  *
  * @throws \Thelia\Exception\FileException
  *
  */
 public function saveFile(FileCreateOrUpdateEvent $event)
 {
     $model = $event->getModel();
     $model->setFile(sprintf("tmp/%s", $event->getUploadedFile()->getFilename()));
     $nbModifiedLines = $model->save();
     $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);
 }