DeployerGuide/Others/ObjectsTriggers: MRDDecreeDocumentsObserver.inc

Plik MRDDecreeDocumentsObserver.inc, 3.3 KB (dodany przez JP, 9 years temu)
xx

Obserwator dekretacji dokumentu

Line 
1<?php
2require_once('./classes/Notifier/observers/AbsNotifierObserver.inc');
3require_once('./classes/Log/LogFactory.inc');
4
5/**
6 * MRDDecreeDocumentsObserver
7 *
8 * @uses AbsNotifierObserver
9 * @final
10 * @author Tomasz Świenty
11 * @version 0.1
12 * @copyright Copyright (c) BetaSoft
13 */
14final class MRDDecreeDocumentsObserver extends AbsNotifierObserver {
15
16
17
18    private static $log = FALSE;
19
20
21
22    public function preapreReceiversList() {
23
24        $this->receivers = array();
25
26    }
27
28
29
30    private static function log($message, $priority = Log::EVENT_INFO) {
31
32        if (!self::$log) {
33            self::$log = LogFactory::factory('DATA')->unregisterAllWriters()->registerWriter(Log::FILE_LOG_WRITER);
34        }
35
36        self::$log->setWriterConfig(Log::FILE_LOG_WRITER, array('fileName' => date('Y-m-d'), 'tranIdx' => SysContext::$usr_info['usr_id'], 'clsnam' => 'UMR_DDO'));
37        self::$log->write($message, Log::getDayKey(), array(), NULL, $priority);
38
39    }
40
41
42
43    public function update() {
44
45        if (!isset($this->data['target']) OR !$this->data['target']) {
46            return FALSE;
47        }
48
49        if (isset($this->data['source']) AND ($this->data['source'] == $this->data['target'])) {
50            return FALSE;
51        }
52
53        require_once(MOD_PATH.'/Employers/OrganizationUnits/OrganizationUnitBean.inc');
54        $organizationUnit = new OrganizationUnitBean($this->data['target']);
55
56        // !! Obserwator uruchamia się jeśli dokument jest przekazany na skrzynke innej organizacji !!
57        if ($organizationUnit->get('ndetpe') != 'ENTITY') {
58            return FALSE;
59        }
60
61        if (bs_empty_str($organizationUnit->get('orunsm'))) {
62            self::log('Brak symbolu jednostki', Log::EVENT_ERR);
63            return FALSE;
64        }
65
66        if (!isset($this->data['source']) OR !$this->data['source']) {
67            self::log('Brak source', Log::EVENT_ERR);
68            return FALSE;
69        }
70
71        if ($this->data['source'] <= 0) {
72            self::log('Przekazanie ze stanowiska będącego usługą (source < 0)', Log::EVENT_ERR);
73            return FALSE;
74        }
75
76        if (!isset($this->data['doc_id']) OR empty($this->data['doc_id'])) {
77            self::log('Brak doc_id', Log::EVENT_ERR);
78            return FALSE;
79        }
80
81        $db = PgManager::getInstance();
82
83        require_once(MOD_PATH.'ADocuments/beans/Document.inc');
84        $document = Document::getInstance($this->data['doc_id']);
85
86        ErrorHandler::tryBegin();
87
88        self::log(sprintf('Przekazuję dokument doc_id=%s na stanowisko orunid=%s (target z documents)', $this->data['doc_id'], $this->data['target']));
89        self::log('Odpalam komendę UCExportDocToMRDCommand');
90
91        try {
92            require_once('./commands/UCExportDocToMRDCommand.inc');
93            $command = new UCExportDocToMRDCommand();
94            $command->execute($document, array('orunsm' => $organizationUnit->get('orunsm')));
95        } catch (Exception $e) {
96            $db->rollback();
97
98            self::log('Błąd komendy');
99            self::log($e->getMessage(), Log::EVENT_ERR);
100            throw new CustomErrorException($e->getMessage());
101        }
102
103        self::log('Komenda UCExportDocToMRDCommand wykonana');
104        ErrorHandler::tryEnd();
105
106        self::log('Koniec obserwatora dekretacji do MRD');
107
108        return TRUE;
109
110    }
111
112}
113
114?>