Commit 2e2ded00 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Merge branch 'upgrade-module-information' into develop

parents 23b72665 24576f32
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -32,13 +32,16 @@ class FichierController extends AbstractActionController
        $request = $this->getRequest();
        if ($request->isPost()) {
            $file = $request->getFiles()->toArray();
            if ($file['chemin'] !== null) {
            if ($file['chemin'] !== null && $file['chemin']['tmp_name'] !== "") {
                $pathDir = $this->fileService->computeDirectoryPathForInformation();
                $this->fileService->createWritableDirectory($pathDir);

                $newFilename = $this->getInformationFichierService()->generateUniqueFilename();



                $uploadPath = $file['chemin']['tmp_name'];
                $truePath = implode("/", [$pathDir, $file['chemin']['name']]);
                var_dump($uploadPath . " -> ".$truePath);
                $truePath = implode("/", [$pathDir, $newFilename]);
                $ok = rename($uploadPath, $truePath);
                if (! $ok) {
                    throw new RuntimeException("Impossible de renommer le fichier sur le disque.");
@@ -47,6 +50,7 @@ class FichierController extends AbstractActionController
                $user = $this->userContextService->getIdentityDb();
                $fichier = new InformationFichier();
                $fichier->setNom($file['chemin']['name']);
                $fichier->setFilename($newFilename);
                $fichier->setCreateur($user);
                $fichier->setDateCreation(new \DateTime());
                $this->getInformationFichierService()->create($fichier);
+0 −2
Original line number Diff line number Diff line
@@ -4,9 +4,7 @@ namespace Information\Controller;

use Application\Service\Fichier\FichierService;
use Application\Service\File\FileService;
use Application\Service\These\TheseService;
use Application\Service\UserContextService;
use Application\Service\Utilisateur\UtilisateurService;
use Information\Service\InformationFichierService;
use Zend\Mvc\Controller\ControllerManager;

+22 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ class InformationFichier {
    private $id;
    /** @var string */
    private $nom;
    /** @var string */
    private $filename;
    /** @var Utilisateur */
    private $createur;
    /** @var DateTime */
@@ -77,4 +79,24 @@ class InformationFichier {
        return $this;
    }

    /**
     * @return string
     */
    public function getFilename()
    {
        return $this->filename;
    }

    /**
     * @param string $filename
     * @return InformationFichier
     */
    public function setFilename($filename)
    {
        $this->filename = $filename;
        return $this;
    }



}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
        </id>

        <field name="nom"       column="NOM"          type="string"   length="256"    nullable="false"/>
        <field name="filename"  column="FILENAME"     type="string"   length="256"    nullable="false"/>

        <field name="dateCreation" type="datetime" column="CREATION" nullable="false"/>

+16 −0
Original line number Diff line number Diff line
@@ -96,4 +96,20 @@ class InformationFichierService {
        $filePath = implode("/", [$pathDir, $fichier->getNom()]);
        return $filePath;
    }


    /**
     * @param integer $length (longueur des paquets)
     * @param integer $group (nombre de paquets)
     * @return string
     */
    public function generateUniqueFilename($length = 5, $group = 4)
    {
        $result = "";
        for ($i = 0 ; $i < $group ; $i++) {
            if ($i) $result .= "-";
            $result .= uniqid();
        }
        return $result;
    }
}
 No newline at end of file
Loading