1 | <?php |
---|
2 | |
---|
3 | set_time_limit(-1); |
---|
4 | chdir('../apps/edokumenty/'); |
---|
5 | |
---|
6 | $args = array(); |
---|
7 | if (isset($_SERVER['argv'])) { |
---|
8 | $args = $_SERVER['argv']; |
---|
9 | array_shift($args); |
---|
10 | } |
---|
11 | |
---|
12 | require_once('./../../framework/lib/util/Translator/Translator.inc'); |
---|
13 | |
---|
14 | define('SCRIPT_PATH', '.'); |
---|
15 | define('ASYNC_SERVICE', false); |
---|
16 | require_once('./config.inc'); |
---|
17 | require_once('../../framework/globalVar.inc'); |
---|
18 | require_once('./localVar.inc'); |
---|
19 | require_once(FUNC_PATH.'GetUsrAcc.inc'); |
---|
20 | require_once(LIB_PATH.'system.inc'); |
---|
21 | require_once(LIB_PATH.'db/PgManager.inc'); |
---|
22 | require_once(LIB_PATH.'util/Debug.inc'); |
---|
23 | require_once(LIB_PATH.'db/Bean.inc'); |
---|
24 | require_once('./classes/eDokumentyApi/EDokApi.inc'); |
---|
25 | require_once(MOD_PATH.'ADocuments/ADocumentsService.inc'); |
---|
26 | |
---|
27 | if(!defined("STDIN")) { |
---|
28 | define("STDIN", "fopen('php://stdin','r')"); |
---|
29 | } |
---|
30 | |
---|
31 | UserRights::disable(); |
---|
32 | |
---|
33 | $db = new PgManager(DB_NAME); |
---|
34 | echo "\n"; |
---|
35 | |
---|
36 | $ent_id = $db->select('podmioty', 'id_pod', 'symbol=\''.ENTITY.'\'', 'id_pod'); |
---|
37 | |
---|
38 | $decreeArr = array(); |
---|
39 | $out = $db->select('organization_units', 'orunid', 'ent_id = '.$ent_id.' AND is_del IS NOT TRUE', FALSE, PGSQL_ASSOC); |
---|
40 | if ((is_array($out)) AND (!empty($out))) { |
---|
41 | foreach ($out as $oo) { |
---|
42 | $decreeArr[] = $oo['orunid']; |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | SysContext::$ent_id = $ent_id; |
---|
47 | $_SESSION['curr_ent_id'] = $ent_id; |
---|
48 | |
---|
49 | SysContext::$usr_info = array( |
---|
50 | 'usr_id' => 1, |
---|
51 | 'orunid' => array(-3), // EXTSYS_SERVICE_ID = -3 |
---|
52 | 'lasnam' => Translator::translate('Wypełniacz'), |
---|
53 | 'firnam' => 'Usługa', |
---|
54 | 'usrnam' => 'Usługa Wypełniacz', |
---|
55 | 'fullnm' => 'Usługa Wypełniacz' |
---|
56 | ); |
---|
57 | |
---|
58 | // ile dokumentów ma wygenerować |
---|
59 | $maxDocs = 10; |
---|
60 | |
---|
61 | // po ilu wygenerowanych dokumentach na rozpoczynać transakcje (commit/begin) |
---|
62 | $tCommit = 500; |
---|
63 | |
---|
64 | // maksymalna ilość słów w opisie dokumentu |
---|
65 | $maxDocWords = 3; |
---|
66 | |
---|
67 | $edokApi = new EDokApi(); |
---|
68 | |
---|
69 | $dictionary = './../../contrib/slowa-new.txt'; |
---|
70 | |
---|
71 | $maxDicStrLength = prepareDictionary($dictionary); |
---|
72 | $dictionary = $dictionary.'_com'; |
---|
73 | |
---|
74 | clearstatcache(); |
---|
75 | |
---|
76 | $lineLimit = filesize($dictionary) / $maxDicStrLength; |
---|
77 | |
---|
78 | function prepareDictionary($dictionary) { |
---|
79 | |
---|
80 | $handle = fopen($dictionary, 'r'); |
---|
81 | |
---|
82 | $dictionaryCom = $dictionary.'_com'; |
---|
83 | $crt = FALSE; |
---|
84 | if ((!file_exists($dictionaryCom)) OR (filesize($dictionaryCom) < 20)) { |
---|
85 | file_put_contents($dictionaryCom, NULL); |
---|
86 | $crt = TRUE; |
---|
87 | } |
---|
88 | |
---|
89 | $maxStrLen = 0; |
---|
90 | if ($handle) { |
---|
91 | |
---|
92 | while (($buffer = fgets($handle, 4096)) !== FALSE) { |
---|
93 | $l = strlen($buffer); |
---|
94 | if ($maxStrLen < $l) { |
---|
95 | $maxStrLen = $l; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | $maxStrLen += 5; |
---|
100 | |
---|
101 | fseek($handle, 0); |
---|
102 | |
---|
103 | if ($crt) { |
---|
104 | while (($buffer = fgets($handle, 4096)) !== FALSE) { |
---|
105 | $text = str_pad(trim($buffer), $maxStrLen, '#', STR_PAD_RIGHT); |
---|
106 | file_put_contents($dictionaryCom, $text, FILE_APPEND); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | fclose($handle); |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | return $maxStrLen; |
---|
115 | |
---|
116 | } |
---|
117 | |
---|
118 | function getWords($dictionary, $lineLimit, $maxDicStrLength, $limit = 3) { |
---|
119 | |
---|
120 | for ($i = 0; $i < $limit; $i++) { |
---|
121 | $arr[] = rand(0, ($lineLimit-1)); |
---|
122 | } |
---|
123 | |
---|
124 | $out = ''; |
---|
125 | |
---|
126 | $handle = fopen($dictionary, 'r'); |
---|
127 | if ($handle) { |
---|
128 | foreach ($arr as $ss) { |
---|
129 | fseek($handle, ($ss * $maxDicStrLength)); |
---|
130 | $out .= str_replace('#', '', fread($handle, $maxDicStrLength)).' '; |
---|
131 | |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | return trim($out); |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | $start = time(); |
---|
140 | |
---|
141 | $db->begin(); |
---|
142 | |
---|
143 | $srv = new ADocumentsService(); |
---|
144 | |
---|
145 | for ($i = 0; $i < $maxDocs; $i++) { |
---|
146 | |
---|
147 | $words = getWords($dictionary, $lineLimit, $maxDicStrLength, $maxDocWords); |
---|
148 | $data = array( |
---|
149 | 'dscrpt' => $words, |
---|
150 | 'dctpid' => 1, |
---|
151 | 'target' => 2, |
---|
152 | ); |
---|
153 | |
---|
154 | $to = $decreeArr[rand(0, count($decreeArr)-1)]; |
---|
155 | |
---|
156 | $orders = 'Instrukcje dla dokumentu '.$words; |
---|
157 | |
---|
158 | $doc_id = $edokApi->createDocument($data); |
---|
159 | if ($doc_id) { |
---|
160 | $out = $srv->decree($doc_id, $to, array(), array(), FALSE, FALSE, $orders, TRUE, FALSE, FALSE); |
---|
161 | } |
---|
162 | |
---|
163 | if (($tCommit % ($i+1)) == 0) { |
---|
164 | $db->commit(); |
---|
165 | $db->begin(); |
---|
166 | } |
---|
167 | |
---|
168 | } |
---|
169 | |
---|
170 | $db->commit(); |
---|
171 | |
---|
172 | echo (time() - $start); |
---|
173 | |
---|
174 | |
---|
175 | ?> |
---|