adaptation pour minio
This commit is contained in:
@ -1,100 +0,0 @@
|
||||
<?php
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use App\Entity\Tallyday as Tallyday;
|
||||
|
||||
|
||||
class CleanCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
private $rootlog;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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('<fg=red>'.$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");
|
||||
}
|
||||
}
|
@ -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"]);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ class GroupController extends AbstractController
|
||||
|
||||
$userinfo="";
|
||||
if($data->getOwner()) {
|
||||
$userinfo.="<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>";
|
||||
$userinfo.="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>";
|
||||
$userinfo.="<br>".$data->getOwner()->getUsername();
|
||||
}
|
||||
|
||||
@ -513,7 +513,7 @@ class GroupController extends AbstractController
|
||||
$action.="<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
|
||||
|
||||
// Avatar
|
||||
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getAvatar()])."' class='avatar'>";
|
||||
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"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.="<a style='cursor:pointer' onClick='delUsers(".$data->getId().")'><i class='fa fa-minus fa-fw'></i></a>";
|
||||
|
||||
// Avatar
|
||||
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getAvatar()])."' class='avatar'>";
|
||||
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
|
||||
|
||||
// Flag manager
|
||||
$rolegroup="";
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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"]=[];
|
||||
|
@ -255,7 +255,7 @@ class UserController extends AbstractController
|
||||
$tmp=array();
|
||||
if($access=="admin"||$access=="modo") array_push($tmp,$action);
|
||||
|
||||
array_push($tmp,"<img src='".$this->generateUrl('app_minio_image',["file"=>"uploads/avatar/".$data->getAvatar()])."' class='avatar'>");
|
||||
array_push($tmp,"<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>");
|
||||
|
||||
array_push($tmp,$data->getUsername());
|
||||
array_push($tmp,$data->getLastname());
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user