diff --git a/config/packages/oneup_uploader.yaml b/config/packages/oneup_uploader.yaml index 00efabd..0a30eb9 100644 --- a/config/packages/oneup_uploader.yaml +++ b/config/packages/oneup_uploader.yaml @@ -2,7 +2,13 @@ oneup_uploader: mappings: avatar: frontend: dropzone + storage: + directory: "%kernel.project_dir%/var/tmp/avatar" logo: frontend: dropzone + storage: + directory: "%kernel.project_dir%/var/tmp/logo" header: frontend: dropzone + storage: + directory: "%kernel.project_dir%/var/tmp/header" \ No newline at end of file diff --git a/src/Command/CleanCommand.php b/src/Command/CleanCommand.php deleted file mode 100644 index 00a311e..0000000 --- a/src/Command/CleanCommand.php +++ /dev/null @@ -1,100 +0,0 @@ -container = $container; - $this->em = $em; - } - - protected function configure() - { - $this - ->setName('app:Clean') - ->setDescription('Nettoyage des données obsolètes') - ->setHelp('Nettoyage des données obsolètes') - ; - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $this->output = $output; - $this->filesystem = new Filesystem(); - $this->rootlog = $this->container->get('kernel')->getLogDir()."/"; - $alias = $this->container->getParameter('appAlias'); - - $this->writelnred(''); - $this->writelnred('== app:Clean'); - $this->writelnred('=========================================================================================================='); - - $now=new \DateTime('now'); - - $directory=$this->container->get('kernel')->getProjectDir()."/public/uploads/avatar"; - $this->writeln($directory); - - $files=[]; - $fs = new Filesystem(); - - if($fs->exists($directory)) { - $finder = new Finder(); - $finder->in($directory)->files(); - - foreach (iterator_to_array($finder) as $file) { - $name = $file->getRelativePathname(); - if($name!="admin.jpg"&&$name!="noavatar.png"&&$name!="system.jpg") { - $entity=$this->em->getRepository("App\Entity\User")->findBy(["avatar"=>$name]); - if(!$entity) { - $this->writeln($name); - $url=$directory."/".$name; - if($fs->exists($url)) { - $fs->remove($url); - } - } - } - } - } - - $fs = new Filesystem(); - $users=$this->em->getRepository("App\Entity\User")->findAll(); - foreach($users as $user) { - if(!$fs->exists($directory."/".$user->getAvatar())) { - $this->writeln($user->getUsername()); - $user->setAvatar("noavatar.png"); - $this->em->persist($user); - $this->em->flush(); - } - } - - $this->writeln(''); - return Command::SUCCESS; - } - - private function writelnred($string) { - $this->output->writeln(''.$string.''); - $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); - } - private function writeln($string) { - $this->output->writeln($string); - $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); - } -} diff --git a/src/Command/InitCommand.php b/src/Command/InitCommand.php index eb5dd9b..8eaa591 100644 --- a/src/Command/InitCommand.php +++ b/src/Command/InitCommand.php @@ -487,22 +487,7 @@ class InitCommand extends Command ); $output->writeln(''); - - // Job de purge des fichiers obsolète - // Toute les 24h à 3h00 - $entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:Clean"]); - if(!$entity) { - $entity = new Cron; - $nextdate=$entity->getSubmitdate(); - $nextdate->setTime(3,0); - $entity->setCommand("app:Clean"); - $entity->setDescription("Nettoyage des données obsolètes"); - $entity->setStatut(1); - $entity->setRepeatinterval(86400); - $entity->setNextexecdate($nextdate); - $this->em->persist($entity); - } - + // Job synchronisation des comptes utilisateur // Toute les 24h à 3h00 $entity = $this->em->getRepository('App\Entity\Cron')->findOneBy(["command"=>"app:Synchro"]); diff --git a/src/Controller/CropController.php b/src/Controller/CropController.php index 6825dbb..04e9171 100644 --- a/src/Controller/CropController.php +++ b/src/Controller/CropController.php @@ -38,7 +38,7 @@ class CropController extends AbstractController { // Récupération de l'image à cropper $file=$request->query->get('file'); - $large_image_location = "uploads/$type/$file"; + $large_image_location=$this->minio->download($type."/".$file,$type."/".$file,true); // Récupérer les tailles de l'image $width = $this->getWidth($large_image_location); @@ -72,13 +72,14 @@ class CropController extends AbstractController $ratio="1:1"; break; } - + if($max_height>0) { $scale = $max_height/$height; if(($width*$scale)>$max_width) { $scale = $max_width/$width; } $this->resizeImage($large_image_location,$width,$height,$scale); + $this->minio->upload($large_image_location,$type."/".$file,false); } else $scale=1; @@ -103,12 +104,12 @@ class CropController extends AbstractController if ($form->get('submit')->isClicked() && $form->isValid()) { // Récupération des valeurs du formulaire $data = $form->getData(); - $thumb_image_location = "uploads/$type/thumb_".$file; + $tmpdir=$this->appKernel->getProjectDir()."/var/tmp"; + $thumb_image_location = "$tmpdir/$type/thumb_".$file; $cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location,$data["ws"],$data["hs"],$data["xs"],$data["ys"],$scale); // Dépot des fichiers sur minio - $this->minio->upload($large_image_location,$large_image_location,true); - $this->minio->upload($thumb_image_location,$thumb_image_location,true); + $this->minio->upload($thumb_image_location,$type."/thumb_".$file,false); $submited=true; } @@ -186,10 +187,13 @@ class CropController extends AbstractController list($imagewidth, $imageheight, $imageType) = getimagesize($image); $imageType = image_type_to_mime_type($imageType); - $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); + $newImageWidth=900; + $newImageHeight=900; $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); + + switch($imageType) { case "image/gif": $source=imagecreatefromgif($image); @@ -197,6 +201,7 @@ class CropController extends AbstractController case "image/pjpeg": case "image/jpeg": case "image/jpg": + dump("here"); $source=imagecreatefromjpeg($image); break; case "image/png": @@ -204,7 +209,9 @@ class CropController extends AbstractController $source=imagecreatefrompng($image); break; } - imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height); + + $ok=imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height); + switch($imageType) { case "image/gif": imagegif($newImage,$thumb_image_name); @@ -212,14 +219,16 @@ class CropController extends AbstractController case "image/pjpeg": case "image/jpeg": case "image/jpg": - imagejpeg($newImage,$thumb_image_name,90); + dump($thumb_image_name); + imagejpeg($newImage,$thumb_image_name,100); break; case "image/png": case "image/x-png": imagepng($newImage,$thumb_image_name); break; } - chmod($thumb_image_name, 0640); + + chmod($thumb_image_name, 0640); return $thumb_image_name; } diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index f893987..677732d 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -160,7 +160,7 @@ class GroupController extends AbstractController $userinfo=""; if($data->getOwner()) { - $userinfo.=""uploads/avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>"; + $userinfo.=""avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>"; $userinfo.="
".$data->getOwner()->getUsername(); } @@ -513,7 +513,7 @@ class GroupController extends AbstractController $action.=""; // Avatar - $avatar=""uploads/avatar/".$data->getAvatar()])."' class='avatar'>"; + $avatar=""avatar/".$data->getAvatar()])."' class='avatar'>"; array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),"","")); } @@ -647,7 +647,7 @@ class GroupController extends AbstractController $action.=""; // Avatar - $avatar=""uploads/avatar/".$data->getAvatar()])."' class='avatar'>"; + $avatar=""avatar/".$data->getAvatar()])."' class='avatar'>"; // Flag manager $rolegroup=""; diff --git a/src/Controller/MinioController.php b/src/Controller/MinioController.php index 58bbf05..e626fca 100644 --- a/src/Controller/MinioController.php +++ b/src/Controller/MinioController.php @@ -27,15 +27,13 @@ class MinioController extends AbstractController // Répertoire de Destination $fs = new Filesystem(); - $rootdir = $this->getParameter('kernel.project_dir') . '/public'; - $fs->mkdir($rootdir."/uploads/ckeditor"); + $rootdir = $this->getParameter('kernel.project_dir') . '/var/tmp'; + $fs->mkdir($rootdir."/ckeditor"); // Fichier cible $targetName = uniqid().".".$extention; - $targetFile = "uploads/ckeditor/".$targetName; - $targetUrl = $this->getParameter('appAlias')."uploads/ckeditor/".$targetName; - $targetUrl = $this->generateUrl('app_minio_document',["file"=>"uploads/ckeditor/".$targetName]); - $message = ""; + $targetFile = "ckeditor/".$targetName; + $targetUrl = $this->generateUrl('app_minio_document',["file"=>"ckeditor/".$targetName]); //move_uploaded_file($tmpfile,$targetFile); $this->minio->upload($tmpfile,$targetFile,true); @@ -49,19 +47,19 @@ class MinioController extends AbstractController public function logo(Request $request): Response { - return $this->redirectToRoute("app_minio_image",["file"=>"uploads/logo/".$request->getSession()->get("logolight")]); + return $this->redirectToRoute("app_minio_image",["file"=>"logo/".$request->getSession()->get("logolight")]); } public function image(Request $request): Response { $file=$request->query->get("file"); switch($file) { - case "uploads/avatar/admin.jpg": - case "uploads/avatar/noavatar.png": - case "uploads/avatar/system.jpg": - case "uploads/header/header.jpg": - case "uploads/logo/logo.png": - $file = str_replace("uploads","medias",$file); + case "avatar/admin.jpg": + case "avatar/noavatar.png": + case "avatar/system.jpg": + case "header/header.jpg": + case "logo/logo.png": + $file = "medias/".$file; $filePath = $file; $content = file_get_contents($file); break; @@ -73,15 +71,10 @@ class MinioController extends AbstractController $content = file_get_contents($file); } // C'est du contenu dynamique on download depuis minio - elseif(stripos($file,"uploads")===0) { + else { $filePath = $this->minio->download($file, $file, true); $content = file_get_contents($filePath); } - // C'est du contenu statique on download depuis minio - else { - $filePath = $file; - $content = file_get_contents($file); - } break; } diff --git a/src/Controller/PublishController.php b/src/Controller/PublishController.php index ac24cf7..3ef2dc2 100644 --- a/src/Controller/PublishController.php +++ b/src/Controller/PublishController.php @@ -22,7 +22,7 @@ class PublishController extends AbstractController $ret["from"]["id"]=$this->getUser()->getId(); $ret["from"]["username"]=$this->getUser()->getUsername(); $ret["from"]["displayname"]=$this->getUser()->getDisplayname(); - $ret["from"]["avatar"]=$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$this->getUser()->getAvatar()]); + $ret["from"]["avatar"]=$this->generateUrl('app_minio_image',["file"=>"avatar/".$this->getUser()->getAvatar()]); $update = new Update( diff --git a/src/Controller/RestController.php b/src/Controller/RestController.php index 94eb845..f2119dd 100644 --- a/src/Controller/RestController.php +++ b/src/Controller/RestController.php @@ -399,7 +399,7 @@ class RestController extends AbstractFOSRestController $output["userposition"]=$user->getPosition(); $output["userpostaladress"]=$user->getPostaladress(); $output["usertelephonenumber"]=$user->getTelephonenumber(); - $output["useravatar"]="https://".str_replace("//","/",$this->getParameter("appWeburl").$this->getParameter("appAlias").$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$user->getAvatar()],true)); + $output["useravatar"]="https://".str_replace("//","/",$this->getParameter("appWeburl").$this->getParameter("appAlias").$this->generateUrl('app_minio_image',["file"=>"avatar/".$user->getAvatar()],true)); $output["userniveau01"]=$this->niveau01Format($user->getNiveau01()); $output["userniveau02"]=$this->niveau02Format($user->getNiveau02()); $output["usergroups"]=[]; diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 32f6bcd..d3e0e64 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -255,7 +255,7 @@ class UserController extends AbstractController $tmp=array(); if($access=="admin"||$access=="modo") array_push($tmp,$action); - array_push($tmp,""uploads/avatar/".$data->getAvatar()])."' class='avatar'>"); + array_push($tmp,""avatar/".$data->getAvatar()])."' class='avatar'>"); array_push($tmp,$data->getUsername()); array_push($tmp,$data->getLastname()); diff --git a/src/Service/AppSession.php b/src/Service/AppSession.php index 795f222..41eeaeb 100644 --- a/src/Service/AppSession.php +++ b/src/Service/AppSession.php @@ -29,7 +29,7 @@ foreach($configs as $config) { $session->set($config->getId(), strval($config->getValue())); } - $session->set("headerimage","uploads/header/".$session->get("headerimage")); + $session->set("headerimage","header/".$session->get("headerimage")); // Calcul couleur $session->set("colorbgbodylight-darker", $this->adjustBrightness($session->get("colorbgbodylight"),-10)); diff --git a/src/Service/MinioService.php b/src/Service/MinioService.php index c2508e6..728ce0e 100644 --- a/src/Service/MinioService.php +++ b/src/Service/MinioService.php @@ -45,7 +45,6 @@ class MinioService 'SaveAs' => $tmpdir.'/'.$filename, ]); } catch (S3Exception $e) { - dump($e); switch ($e->getResponse()->getStatusCode()) { case 404: throw new NotFoundHttpException($this->translator->trans(self::ERR_FILE_NOT_FOUND, [], 'messages')); @@ -91,7 +90,8 @@ class MinioService } if ($deleteSource) { - unlink($file); + $tmpdir=$this->rootPath."/var/tmp"; + @unlink($tmpdir."/".$filename); } } @@ -112,8 +112,6 @@ class MinioService ]); } catch (Exception $e) { \Sentry\captureException($e); - dump($this->minioRoot.$to); - dump($e->getMessage()); throw new Exception(self::ERR_UNAVAILABLE); } @@ -231,7 +229,6 @@ class MinioService ]); } } catch (Exception $e) { - dump($e->getMessage()); throw new Exception(self::ERR_UNAVAILABLE); } } diff --git a/src/Service/UploadListener.php b/src/Service/UploadListener.php index a3dec5a..4c0c416 100644 --- a/src/Service/UploadListener.php +++ b/src/Service/UploadListener.php @@ -79,20 +79,13 @@ class UploadListener $type=$event->getType(); switch($type) { - case "logo": - $file=$event->getFile(); - $filename=$file->getFilename(); - $response = $event->getResponse(); - $response['file'] = $filename; - - $this->minio->upload($file,"uploads/logo/".$filename,true); - break; - default: $file=$event->getFile(); $filename=$file->getFilename(); $response = $event->getResponse(); $response['file'] = $filename; + + $this->minio->upload($file,$type."/".$filename,true); break; } } diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 2b57ccb..d66adc1 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -10,13 +10,6 @@ class AppExtension extends AbstractExtension { protected $container; - public function getFilters() - { - return [ - new TwigFilter('urlavatar', [$this, 'urlavatar']), - ]; - } - public function getFunctions() { return [ @@ -24,15 +17,6 @@ class AppExtension extends AbstractExtension ]; } - - public function urlavatar($avatar) - { - if(stripos($avatar,"http")===0) - return $avatar; - else - return $this->container->getParameter("appAlias")."uploads/avatar/".$avatar; - } - public function getUniqueId() { return str_replace("-","",Uuid::uuid4()); } diff --git a/templates/Config/edit.html.twig b/templates/Config/edit.html.twig index a18db9e..2f5b7fc 100755 --- a/templates/Config/edit.html.twig +++ b/templates/Config/edit.html.twig @@ -60,19 +60,14 @@ {% set color = app.session.get('colorbgbodylight') %} {% endif %} - + Modifier {% elseif config.type=="header" %}
- + Modifier
- {% elseif config.type=="image" %} -
- - Modifier -
{% endif %} {{ form_row(form.help) }} @@ -84,7 +79,7 @@ {% block localjavascript %} $("#config_value_img").on('error', function(){ var imgSrc = $(this).attr('src'); - if(imgSrc!="/{{appAlias}}/uploads/{{config.type}}/") + if(imgSrc!="/{{appAlias}}/{{config.type}}/") $(this).attr('src',imgSrc); }); $('#mymodallarge').on('hidden.bs.modal', function () { diff --git a/templates/Config/logo.html.twig b/templates/Config/logo.html.twig index fb21677..6b3f04f 100644 --- a/templates/Config/logo.html.twig +++ b/templates/Config/logo.html.twig @@ -24,7 +24,7 @@