ArchiveTransferComposition.php 2.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
 * Copyright (C) 2015 Maarch
 *
 * This file is part of bundle seda.
 *
 * Bundle seda is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Bundle seda is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with bundle seda.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace ext\demorm_publique\bundle\seda\Controller;


class ArchiveTransferComposition extends \ext\archivesPubliques\bundle\seda\Controller\ArchiveTransferComposition
{
    /**
     * Receive message with all contents embedded
     * @param object $messageObject The message
     * @param bool   $isTemplate    True if the message is a template
     *
     * @return string The new message identifier
     */
    public function create($messageObject, $isTemplate=false)
    {
        $message = $this->composeMessage($messageObject);
        $message->messageId = \laabs::newId();

        if ($isTemplate) {
            $message->status = 'template';
        }

        $message->reference = $message->reference . "_" . \laabs::newTimestamp()->getTimestamp()

        if ($this->sdoFactory->exists('medona/message', array('type'=>$message->type, 'senderOrgRegNumber'=>$message->senderOrgRegNumber, 'reference'=>$message->reference))) {
            throw \laabs::newException("seda/invalidMessageException", "L'identifiant du message existe déjà.");
        }

        $messageDir = $this->messageDirectory.DIRECTORY_SEPARATOR.(string) $message->messageId;
        if (!is_dir($messageDir)) {
            mkdir($messageDir, 0777, true);
        }

        $this->sdoFactory->create($message, 'medona/message');

        return $message->messageId;
    }
}