Commit 9b5fab35 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Up : Une option a été ajouté pour ne pas trasférer le document lors d'un update

parent 5552a5be
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -262,10 +262,9 @@ class ProcessService
     */
    public function trigger(Process $process, bool $forceFirstSend = false): void
    {
        $this->getLoggerService()->debug("Recalucle pour '$process");
        if ($process->isSendable() && $forceFirstSend) {
            // Premier envoi
            $this->getLoggerService()->debug("Premier envoi");
            $this->getLoggerService()->debug("Processus (Premier envoi) : $process");
            try {
                $process->setCurrentStep(1);
                $processStep = $process->getStep();
@@ -280,15 +279,14 @@ class ProcessService
                    "Impossible d'envoyer le document à signer : " . $e->getMessage()
                );
            }

            return;
        }

        // Envoi (etape 1)
        if ($process->isTriggerable()) {
            $this->getLoggerService()->info("Etape courante : '" . $process->getCurrentStep() . "'");
            $this->getLoggerService()->info("Process (Etape courante) : '" . $process->getCurrentStep() . "'");
            try {
                $processStep = $process->getStep();
                $this->getLoggerService()->info(" - Etape '$processStep' (" . $processStep->getStatusText() . ')');

                if ($processStep->getStatus() == Signature::STATUS_SIGNATURE_DRAFT) {
                    $this->getLoggerService()->info(" - ENVOI de l'étape");
@@ -360,6 +358,7 @@ class ProcessService
     */
    protected function triggerProcessEvent(Process $process, string $eventType): void
    {
        $this->getLoggerService()->info("signature > trigger event > $eventType : $process");
        $em = new EventManager($this->getSharedEventManager());
        $em->triggerEvent(new ProcessEvent($eventType, null, ['id' => $process->getId()]));
    }
+31 −26
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ class SignatureService
                ]
            );
        }
        throw new SignatureException("Impossible de charger vos documents");
        throw new SignatureException("Impossible de charger vos documents (Vous n'avez pas d'email)");
    }

    /**
@@ -160,7 +160,7 @@ class SignatureService
                $letterfile
            );
        }
        throw new SignatureException("Impossible de charger vos documents");
        throw new SignatureException("Impossible de charger vos documents (Vous n'avez pas d'email)");
    }

    /**
@@ -489,7 +489,7 @@ class SignatureService
    ///

    /**
     * Création d'un signature.
     * Création d'une signature.
     *
     * @param Signature $signature
     * @param bool $pushToLetterFile
@@ -528,18 +528,19 @@ class SignatureService
     * @return void
     * @throws SignatureException
     */
    public function updateStatusSignature(Signature $signature, bool $callProcessStep = false): bool
    public function updateStatusSignature(Signature $signature, bool $callProcessStep = false, bool $writeDocument = true): bool
    {
        $this->getLoggerService()->debug("Actualisation du statut pour '$signature'");
        $this->getLoggerService()->debug("### UPDATE STATUS '$signature'");
        try {
            if (!$signature->isFinished()) {

                $documentSrc = $this->getSignatureConfigurationService()->getDocumentsLocation()
                    . DIRECTORY_SEPARATOR
                    . $signature->getDocumentPath();

                if (!is_writable($documentSrc)) {
                if ($writeDocument && !is_writable($documentSrc)) {
                    $err = "L'emplacement de dépôt du document n'est pas accessible en écriture";
                    $this->getLoggerService()->critical("$err : '$documentSrc'");
                    $this->getLoggerService()->critical("[update] $err : '$documentSrc'");
                    throw new SignatureException($err);
                }

@@ -551,20 +552,19 @@ class SignatureService
                try {
                    $infos = $letterFileStrategy->getSignatureInfos($signature);
                    $status = $infos->getStatus();
                    $status_remote = $infos->getStatusRemote();
                    $currentStatus = $signature->getStatusText();
                    $this->getLoggerService()->debug(
                        "Statut en cours '$currentStatus', statut reçu > '$status' ($status_remote)"
                    );
                } catch (Exception $e) {
                    $this->getLoggerService()->critical(
                        "[update] Impossible de mettre à jour le statut depuis le parapheur : "
                        . $e->getMessage());
                    throw new SignatureException("Impossible de mettre à jour le statut depuis le parapheur");
                }

                $statusChanged = $signature->getStatus() !== $status;

                $changed = false;
                $signature->setStatus($status);
                if ($statusChanged) {
                    $this->getLoggerService()->info(
                        "[update] Le statut a changé");
                    $signature->setDateUpdate(new \DateTime());
                }

@@ -575,9 +575,7 @@ class SignatureService
                    if ($infos->isAccepted($recipient->getEmail()) && !$recipient->isDone()) {
                        $recipient->setStatus(Signature::STATUS_SIGNATURE_SIGNED, true);
                        $recipient->setDateFinished($infos->getDateDone($recipient->getEmail()));
                        $this->getLoggerService()->debug("Mise à jour [SIGNATURE] pour '$recipient'");

                        //$this->triggerRecipientEvent($recipient, SignatureConstants::EVENT_RECIPIENT_ACCEPTED);
                        $this->getLoggerService()->debug("[update] Mise à jour SIGNED pour '$recipient'");

                        $events[] = [
                            'spot' => 'recipient',
@@ -587,9 +585,7 @@ class SignatureService
                    }
                    if ($infos->isRefused($recipient->getEmail()) && !$recipient->isDone()) {
                        $recipient->setStatus(Signature::STATUS_SIGNATURE_REJECT, true);
                        $this->getLoggerService()->debug("Mise à jour [REFUS] '$recipient'");

                        // $this->triggerRecipientEvent($recipient, SignatureConstants::EVENT_RECIPIENT_REJECTED);
                        $this->getLoggerService()->debug("[update] Mise à jour REJECT pour '$recipient'");

                        $events[] = [
                            'spot' => 'recipient',
@@ -599,16 +595,20 @@ class SignatureService
                        // TODO vérifier si on a la date de refus
                    }
                    if ($signature->isFinished() && $recipient->getStatus() == Signature::STATUS_SIGNATURE_WAIT) {
                        $recipient->setStatus(Signature::STATUS_SIGNATURE_CANCEL, true)
                        $recipient
                            ->setStatus(Signature::STATUS_SIGNATURE_CANCEL, true)
                            ->setDateUpdate(new \DateTime());
                        $this->getLoggerService()->debug("[update] Mise à jour CANCEL pour '$recipient'");
                    }
                }

                $this->getLoggerService()->debug("[update] Enregistrement en BDD");
                $this->getObjectManager()->flush();

                if ($signature->getStatus() == Signature::STATUS_SIGNATURE_SIGNED) {
                    $this->getLoggerService()->debug("Transfert du document");
                    // TODO 'backup' de l'original

                    if( $writeDocument ){
                        $this->getLoggerService()->debug("[update] Enregistrement du document");

                        $documentSrc = $this->getSignatureConfigurationService()->getDocumentsLocation()
                            . DIRECTORY_SEPARATOR
@@ -623,6 +623,7 @@ class SignatureService
                                "Impossible d'écrire le document"
                            );
                        }
                    }

                    $events[] = [
                        'spot' => 'signature',
@@ -639,7 +640,7 @@ class SignatureService
                    ];
                }

                $this->getLoggerService()->debug("Nombre d'événement : " . count($events));
                $this->getLoggerService()->debug("[update] Nombre d'événement : " . count($events));

                if( count($events) ){
                    $em = new EventManager($this->getSharedEventManager());
@@ -654,14 +655,18 @@ class SignatureService
                        );
                        $em->trigger($event['type'], null, ['id' => $event['id']]);
                    }
                }

                    // Notification des observateurs
                    // Notification
                if ($signature->getObservers() && count($events)) {
                    $this->notificationsObserversStatut($signature);
//                    if ($signature->getObservers() && count($events)) {
//                        $this->notificationsObserversStatut($signature);
//                    }
                }



                if ($callProcessStep && $signature->getProcessStep()) {

                    /** @var ProcessService $processService */
                    $processService = $this->getServiceContainer()->get(ProcessService::class);
                    $processService->trigger($signature->getProcessStep()->getProcess());