1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,496 @@ |
1 |
+<?php |
|
2 |
+/** |
|
3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
+ * |
|
5 |
+ * @author Double Bastion LLC |
|
6 |
+ * |
|
7 |
+ * @license GNU AGPL version 3 or any later version |
|
8 |
+ * |
|
9 |
+ * This program is free software; you can redistribute it and/or |
|
10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
+ * License as published by the Free Software Foundation; either |
|
12 |
+ * version 3 of the License, or any later version. |
|
13 |
+ * |
|
14 |
+ * This program is distributed in the hope that it will be useful, |
|
15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
+ * |
|
19 |
+ * You should have received a copy of the GNU Affero General Public |
|
20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
+ * |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+declare(strict_types=1); |
|
25 |
+ |
|
26 |
+namespace OCA\SMSRelentless\Migration; |
|
27 |
+ |
|
28 |
+use Closure; |
|
29 |
+use OCP\DB\Types; |
|
30 |
+use OCP\DB\ISchemaWrapper; |
|
31 |
+use OCP\IDBConnection; |
|
32 |
+use OCP\Migration\IOutput; |
|
33 |
+use OCP\Migration\SimpleMigrationStep; |
|
34 |
+ |
|
35 |
+ |
|
36 |
+class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
+ |
|
38 |
+ /** @var IDBConnection */ |
|
39 |
+ private $connection; |
|
40 |
+ |
|
41 |
+ /** |
|
42 |
+ * @param IDBConnection $connection |
|
43 |
+ */ |
|
44 |
+ public function __construct(IDBConnection $connection) { |
|
45 |
+ $this->connection = $connection; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ /** |
|
49 |
+ * @param IOutput $output |
|
50 |
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
+ * @param array $options |
|
52 |
+ * @return null|ISchemaWrapper |
|
53 |
+ */ |
|
54 |
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
+ /** @var ISchemaWrapper $schema */ |
|
56 |
+ $schema = $schemaClosure(); |
|
57 |
+ |
|
58 |
+ if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
+ $table = $schema->createTable('sms_relent_settings'); |
|
60 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
61 |
+ 'autoincrement' => true, |
|
62 |
+ 'notnull' => true, |
|
63 |
+ 'length' => 11, |
|
64 |
+ 'unsigned' => true, |
|
65 |
+ ]); |
|
66 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
67 |
+ 'notnull' => true, |
|
68 |
+ 'length' => 128, |
|
69 |
+ ]); |
|
70 |
+ $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
+ 'notnull' => true, |
|
72 |
+ 'length' => 512, |
|
73 |
+ ]); |
|
74 |
+ $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
+ 'notnull' => true, |
|
76 |
+ 'length' => 512, |
|
77 |
+ ]); |
|
78 |
+ $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
+ 'notnull' => true, |
|
80 |
+ 'length' => 512, |
|
81 |
+ ]); |
|
82 |
+ $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
+ 'notnull' => true, |
|
84 |
+ 'length' => 512, |
|
85 |
+ ]); |
|
86 |
+ $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
+ 'notnull' => true, |
|
88 |
+ 'length' => 512, |
|
89 |
+ ]); |
|
90 |
+ $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
+ 'notnull' => true, |
|
92 |
+ 'length' => 512, |
|
93 |
+ ]); |
|
94 |
+ $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
+ 'notnull' => true, |
|
96 |
+ 'length' => 512, |
|
97 |
+ ]); |
|
98 |
+ $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
+ 'notnull' => true, |
|
100 |
+ 'length' => 512, |
|
101 |
+ ]); |
|
102 |
+ $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
+ 'notnull' => true, |
|
104 |
+ 'length' => 512, |
|
105 |
+ ]); |
|
106 |
+ $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
+ 'notnull' => true, |
|
108 |
+ 'length' => 512, |
|
109 |
+ ]); |
|
110 |
+ $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
+ 'notnull' => true, |
|
112 |
+ 'length' => 512, |
|
113 |
+ ]); |
|
114 |
+ $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
+ 'notnull' => true, |
|
116 |
+ 'length' => 512, |
|
117 |
+ ]); |
|
118 |
+ $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
+ 'notnull' => true, |
|
120 |
+ 'length' => 512, |
|
121 |
+ ]); |
|
122 |
+ $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
+ 'notnull' => true, |
|
124 |
+ 'length' => 512, |
|
125 |
+ ]); |
|
126 |
+ $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
+ 'notnull' => true, |
|
128 |
+ 'length' => 512, |
|
129 |
+ ]); |
|
130 |
+ $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
+ 'notnull' => true, |
|
132 |
+ 'length' => 512, |
|
133 |
+ ]); |
|
134 |
+ $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
+ 'notnull' => true, |
|
136 |
+ 'length' => 512, |
|
137 |
+ ]); |
|
138 |
+ $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
+ 'notnull' => false, |
|
140 |
+ 'length' => 48, |
|
141 |
+ 'default' => '', |
|
142 |
+ ]); |
|
143 |
+ $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
+ 'notnull' => false, |
|
145 |
+ 'length' => 48, |
|
146 |
+ 'default' => '', |
|
147 |
+ ]); |
|
148 |
+ $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
+ 'notnull' => false, |
|
150 |
+ 'length' => 48, |
|
151 |
+ 'default' => '', |
|
152 |
+ ]); |
|
153 |
+ $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
+ 'notnull' => false, |
|
155 |
+ 'length' => 48, |
|
156 |
+ 'default' => '', |
|
157 |
+ ]); |
|
158 |
+ $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
+ 'notnull' => false, |
|
160 |
+ 'length' => 11, |
|
161 |
+ 'unsigned' => true, |
|
162 |
+ ]); |
|
163 |
+ $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
+ 'notnull' => false, |
|
165 |
+ 'length' => 1, |
|
166 |
+ ]); |
|
167 |
+ $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
+ 'notnull' => false, |
|
169 |
+ 'length' => 512, |
|
170 |
+ 'default' => '', |
|
171 |
+ ]); |
|
172 |
+ $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
+ 'notnull' => false, |
|
174 |
+ 'length' => 1, |
|
175 |
+ ]); |
|
176 |
+ $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
+ 'notnull' => false, |
|
178 |
+ 'length' => 1, |
|
179 |
+ ]); |
|
180 |
+ $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
+ 'notnull' => false, |
|
182 |
+ 'length' => 1, |
|
183 |
+ ]); |
|
184 |
+ $table->setPrimaryKey(['id']); |
|
185 |
+ $table->addUniqueIndex(['id']); |
|
186 |
+ |
|
187 |
+ } |
|
188 |
+ |
|
189 |
+ |
|
190 |
+ if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
+ $table = $schema->createTable('sms_relent_received'); |
|
192 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
193 |
+ 'autoincrement' => true, |
|
194 |
+ 'notnull' => true, |
|
195 |
+ 'length' => 11, |
|
196 |
+ 'unsigned' => true, |
|
197 |
+ ]); |
|
198 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
199 |
+ 'notnull' => true, |
|
200 |
+ 'length' => 64, |
|
201 |
+ ]); |
|
202 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
203 |
+ 'notnull' => true, |
|
204 |
+ 'length' => 512, |
|
205 |
+ ]); |
|
206 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
207 |
+ 'notnull' => true, |
|
208 |
+ ]); |
|
209 |
+ $table->addColumn('from', Types::STRING, [ |
|
210 |
+ 'notnull' => true, |
|
211 |
+ 'length' => 128, |
|
212 |
+ ]); |
|
213 |
+ $table->addColumn('to', Types::STRING, [ |
|
214 |
+ 'notnull' => true, |
|
215 |
+ 'length' => 128, |
|
216 |
+ ]); |
|
217 |
+ $table->addColumn('message', Types::TEXT, [ |
|
218 |
+ 'notnull' => false, |
|
219 |
+ 'default' => '', |
|
220 |
+ ]); |
|
221 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
+ 'notnull' => true, |
|
223 |
+ 'length' => 255, |
|
224 |
+ ]); |
|
225 |
+ $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
+ 'notnull' => false, |
|
227 |
+ 'length' => 1, |
|
228 |
+ ]); |
|
229 |
+ $table->setPrimaryKey(['id']); |
|
230 |
+ $table->addUniqueIndex(['id']); |
|
231 |
+ |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ |
|
235 |
+ if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
+ $table = $schema->createTable('sms_relent_sent'); |
|
237 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
238 |
+ 'autoincrement' => true, |
|
239 |
+ 'notnull' => true, |
|
240 |
+ 'length' => 11, |
|
241 |
+ 'unsigned' => true, |
|
242 |
+ ]); |
|
243 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
244 |
+ 'notnull' => true, |
|
245 |
+ 'length' => 64, |
|
246 |
+ ]); |
|
247 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
248 |
+ 'notnull' => true, |
|
249 |
+ 'length' => 512, |
|
250 |
+ ]); |
|
251 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
252 |
+ 'notnull' => true, |
|
253 |
+ ]); |
|
254 |
+ $table->addColumn('from', Types::STRING, [ |
|
255 |
+ 'notnull' => true, |
|
256 |
+ 'length' => 128, |
|
257 |
+ ]); |
|
258 |
+ $table->addColumn('to', Types::STRING, [ |
|
259 |
+ 'notnull' => true, |
|
260 |
+ 'length' => 128, |
|
261 |
+ ]); |
|
262 |
+ $table->addColumn('network ', Types::STRING, [ |
|
263 |
+ 'notnull' => false, |
|
264 |
+ 'length' => 64, |
|
265 |
+ 'default' => '', |
|
266 |
+ ]); |
|
267 |
+ $table->addColumn('price', Types::STRING, [ |
|
268 |
+ 'notnull' => false, |
|
269 |
+ 'length' => 64, |
|
270 |
+ 'default' => '', |
|
271 |
+ ]); |
|
272 |
+ $table->addColumn('status', Types::STRING, [ |
|
273 |
+ 'notnull' => false, |
|
274 |
+ 'length' => 512, |
|
275 |
+ 'default' => '', |
|
276 |
+ ]); |
|
277 |
+ $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
+ 'notnull' => false, |
|
279 |
+ 'length' => 64, |
|
280 |
+ 'default' => '', |
|
281 |
+ ]); |
|
282 |
+ $table->addColumn('message', Types::TEXT, [ |
|
283 |
+ 'notnull' => false, |
|
284 |
+ 'default' => '', |
|
285 |
+ ]); |
|
286 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
+ 'notnull' => true, |
|
288 |
+ 'length' => 255, |
|
289 |
+ ]); |
|
290 |
+ $table->setPrimaryKey(['id']); |
|
291 |
+ $table->addUniqueIndex(['id']); |
|
292 |
+ |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+ |
|
296 |
+ if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
+ $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
299 |
+ 'autoincrement' => true, |
|
300 |
+ 'notnull' => true, |
|
301 |
+ 'length' => 11, |
|
302 |
+ 'unsigned' => true, |
|
303 |
+ ]); |
|
304 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
305 |
+ 'notnull' => true, |
|
306 |
+ 'length' => 128, |
|
307 |
+ ]); |
|
308 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
+ 'notnull' => true, |
|
310 |
+ 'length' => 255, |
|
311 |
+ ]); |
|
312 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
+ 'notnull' => true, |
|
314 |
+ 'length' => 128, |
|
315 |
+ ]); |
|
316 |
+ $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
+ 'notnull' => false, |
|
318 |
+ 'length' => 64, |
|
319 |
+ 'default' => '', |
|
320 |
+ ]); |
|
321 |
+ $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
+ 'notnull' => false, |
|
323 |
+ 'length' => 8, |
|
324 |
+ 'default' => '', |
|
325 |
+ ]); |
|
326 |
+ $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
+ 'notnull' => false, |
|
328 |
+ 'length' => 8, |
|
329 |
+ 'default' => '', |
|
330 |
+ ]); |
|
331 |
+ $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
+ 'notnull' => false, |
|
333 |
+ ]); |
|
334 |
+ $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
+ 'notnull' => false, |
|
336 |
+ ]); |
|
337 |
+ $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
+ 'notnull' => false, |
|
339 |
+ 'default' => '', |
|
340 |
+ ]); |
|
341 |
+ $table->setPrimaryKey(['id']); |
|
342 |
+ $table->addUniqueIndex(['id']); |
|
343 |
+ |
|
344 |
+ } |
|
345 |
+ |
|
346 |
+ |
|
347 |
+ if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
+ $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
350 |
+ 'autoincrement' => true, |
|
351 |
+ 'notnull' => true, |
|
352 |
+ 'length' => 11, |
|
353 |
+ 'unsigned' => true, |
|
354 |
+ ]); |
|
355 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
356 |
+ 'notnull' => true, |
|
357 |
+ 'length' => 128, |
|
358 |
+ ]); |
|
359 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
+ 'notnull' => true, |
|
361 |
+ 'length' => 255, |
|
362 |
+ ]); |
|
363 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
+ 'notnull' => true, |
|
365 |
+ 'length' => 128, |
|
366 |
+ ]); |
|
367 |
+ $table->addColumn('groups', Types::STRING, [ |
|
368 |
+ 'notnull' => true, |
|
369 |
+ 'length' => 2048, |
|
370 |
+ ]); |
|
371 |
+ $table->addColumn('users', Types::STRING, [ |
|
372 |
+ 'notnull' => true, |
|
373 |
+ 'length' => 2048, |
|
374 |
+ ]); |
|
375 |
+ $table->setPrimaryKey(['id']); |
|
376 |
+ $table->addUniqueIndex(['id']); |
|
377 |
+ |
|
378 |
+ } |
|
379 |
+ |
|
380 |
+ return $schema; |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
+ |
|
385 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade |
|
386 |
+ $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`'); |
|
387 |
+ $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
+ |
|
389 |
+ $recdatauids = []; |
|
390 |
+ $idsent = []; |
|
391 |
+ while ($rowfetched = $getrecfromnbres->fetch()) { |
|
392 |
+ $recdatauids[] = $rowfetched['user_id']; |
|
393 |
+ $idsent[] = $rowfetched['id']; |
|
394 |
+ } |
|
395 |
+ $getrecfromnbres->closeCursor(); |
|
396 |
+ |
|
397 |
+ if ($recdatauids) { |
|
398 |
+ |
|
399 |
+ $recuids = array_values(array_unique($recdatauids)); |
|
400 |
+ $acdatausrdn = []; |
|
401 |
+ |
|
402 |
+ foreach ($recuids as $dnkey => $dnvalue) { |
|
403 |
+ $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
404 |
+ $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
405 |
+ |
|
406 |
+ while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
407 |
+ $acdatausrdn[$dnvalue] = $acusrdnfetched['value']; |
|
408 |
+ } |
|
409 |
+ $getacdatadnres->closeCursor(); |
|
410 |
+ } |
|
411 |
+ |
|
412 |
+ foreach ($recdatauids as $pdpkey => $pdpvalue) { |
|
413 |
+ |
|
414 |
+ $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?'); |
|
415 |
+ $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]); |
|
416 |
+ $updaterecmsres->closeCursor(); |
|
417 |
+ } |
|
418 |
+ } |
|
419 |
+ |
|
420 |
+ |
|
421 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade |
|
422 |
+ $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`'); |
|
423 |
+ $getrecfromnbres = $getrecfromnb->execute(); |
|
424 |
+ |
|
425 |
+ $recdatanmbrs = []; |
|
426 |
+ $idsrc = []; |
|
427 |
+ $daterec = []; |
|
428 |
+ while ($rowfetched = $getrecfromnbres->fetch()) { |
|
429 |
+ $recdatanmbrs[] = $rowfetched['from']; |
|
430 |
+ $idsrc[] = $rowfetched['id']; |
|
431 |
+ $daterecarr = explode(":", $rowfetched['date']); |
|
432 |
+ $daterec[] = $daterecarr[0]; |
|
433 |
+ } |
|
434 |
+ $getrecfromnbres->closeCursor(); |
|
435 |
+ |
|
436 |
+ if ($recdatanmbrs) { |
|
437 |
+ |
|
438 |
+ foreach ($recdatanmbrs as $rckey => $rcvalue) { |
|
439 |
+ |
|
440 |
+ // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table |
|
441 |
+ $recmsgfromprc = '%' . $rcvalue; |
|
442 |
+ $recdataprc = $daterec[$rckey] . '%'; |
|
443 |
+ $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?'); |
|
444 |
+ $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]); |
|
445 |
+ |
|
446 |
+ $dispnamearr = []; |
|
447 |
+ while ($dspnmstfetched = $getdspnmstres->fetch()) { |
|
448 |
+ $dispnamearr[] = $dspnmstfetched['author_displayname']; |
|
449 |
+ } |
|
450 |
+ $getdspnmstres->closeCursor(); |
|
451 |
+ |
|
452 |
+ if ($dispnamearr) { |
|
453 |
+ $descdspnmarr = array_reverse($dispnamearr); |
|
454 |
+ $authorDisplayNm = $descdspnmarr[0]; |
|
455 |
+ $internalSender = 1; |
|
456 |
+ |
|
457 |
+ } else { |
|
458 |
+ |
|
459 |
+ $authorDisplayNm = ''; |
|
460 |
+ |
|
461 |
+ $getfrom = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? LIMIT 1'); |
|
462 |
+ $getfromres = $getfrom->execute([$recmsgfromprc]); |
|
463 |
+ $fromfetched = $getfromres->fetch(); |
|
464 |
+ |
|
465 |
+ if ($fromfetched) { $internalSender = 1; } else { $internalSender = 0; } |
|
466 |
+ |
|
467 |
+ |
|
468 |
+ // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table |
|
469 |
+ $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?'); |
|
470 |
+ $getdspnmres = $getdspnm->execute([$rcvalue]); |
|
471 |
+ |
|
472 |
+ $dspnmearr = []; |
|
473 |
+ while ($dspnmfetched = $getdspnmres->fetch()) { |
|
474 |
+ if ($dspnmfetched['author_displayname']) { |
|
475 |
+ $dspnmearr[] = $dspnmfetched['author_displayname']; |
|
476 |
+ } |
|
477 |
+ } |
|
478 |
+ $getdspnmres->closeCursor(); |
|
479 |
+ |
|
480 |
+ if ($dspnmearr) { |
|
481 |
+ $descdisplaynmarr = array_reverse($dspnmearr); |
|
482 |
+ $authorDisplayNm = $descdisplaynmarr[0]; |
|
483 |
+ } else { $authorDisplayNm = ''; } |
|
484 |
+ } |
|
485 |
+ |
|
486 |
+ $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? |
|
487 |
+ WHERE `from` LIKE ? AND `id` = ?'); |
|
488 |
+ $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $recmsgfromprc, $idsrc[$rckey]]); |
|
489 |
+ $updaterecmsres->closeCursor(); |
|
490 |
+ } |
|
491 |
+ } |
|
492 |
+ |
|
493 |
+ return null; |
|
494 |
+ } |
|
495 |
+ |
|
496 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,494 +0,0 @@ |
1 |
-<?php |
|
2 |
-/** |
|
3 |
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
- * |
|
5 |
- * @author Double Bastion LLC |
|
6 |
- * |
|
7 |
- * @license GNU AGPL version 3 or any later version |
|
8 |
- * |
|
9 |
- * This program is free software; you can redistribute it and/or |
|
10 |
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
- * License as published by the Free Software Foundation; either |
|
12 |
- * version 3 of the License, or any later version. |
|
13 |
- * |
|
14 |
- * This program is distributed in the hope that it will be useful, |
|
15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU Affero General Public |
|
20 |
- * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
- * |
|
22 |
- */ |
|
23 |
- |
|
24 |
-declare(strict_types=1); |
|
25 |
- |
|
26 |
-namespace OCA\SMSRelentless\Migration; |
|
27 |
- |
|
28 |
-use Closure; |
|
29 |
-use OCP\DB\Types; |
|
30 |
-use OCP\DB\ISchemaWrapper; |
|
31 |
-use OCP\IDBConnection; |
|
32 |
-use OCP\Migration\IOutput; |
|
33 |
-use OCP\Migration\SimpleMigrationStep; |
|
34 |
- |
|
35 |
- |
|
36 |
-class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
- |
|
38 |
- /** @var IDBConnection */ |
|
39 |
- private $connection; |
|
40 |
- |
|
41 |
- /** |
|
42 |
- * @param IDBConnection $connection |
|
43 |
- */ |
|
44 |
- public function __construct(IDBConnection $connection) { |
|
45 |
- $this->connection = $connection; |
|
46 |
- } |
|
47 |
- |
|
48 |
- /** |
|
49 |
- * @param IOutput $output |
|
50 |
- * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
- * @param array $options |
|
52 |
- * @return null|ISchemaWrapper |
|
53 |
- */ |
|
54 |
- public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
- /** @var ISchemaWrapper $schema */ |
|
56 |
- $schema = $schemaClosure(); |
|
57 |
- |
|
58 |
- if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
- $table = $schema->createTable('sms_relent_settings'); |
|
60 |
- $table->addColumn('id', Types::BIGINT, [ |
|
61 |
- 'autoincrement' => true, |
|
62 |
- 'notnull' => true, |
|
63 |
- 'length' => 11, |
|
64 |
- 'unsigned' => true, |
|
65 |
- ]); |
|
66 |
- $table->addColumn('user_id', Types::STRING, [ |
|
67 |
- 'notnull' => true, |
|
68 |
- 'length' => 128, |
|
69 |
- ]); |
|
70 |
- $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
- 'notnull' => true, |
|
72 |
- 'length' => 512, |
|
73 |
- ]); |
|
74 |
- $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
- 'notnull' => true, |
|
76 |
- 'length' => 512, |
|
77 |
- ]); |
|
78 |
- $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
- 'notnull' => true, |
|
80 |
- 'length' => 512, |
|
81 |
- ]); |
|
82 |
- $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
- 'notnull' => true, |
|
84 |
- 'length' => 512, |
|
85 |
- ]); |
|
86 |
- $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
- 'notnull' => true, |
|
88 |
- 'length' => 512, |
|
89 |
- ]); |
|
90 |
- $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
- 'notnull' => true, |
|
92 |
- 'length' => 512, |
|
93 |
- ]); |
|
94 |
- $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
- 'notnull' => true, |
|
96 |
- 'length' => 512, |
|
97 |
- ]); |
|
98 |
- $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
- 'notnull' => true, |
|
100 |
- 'length' => 512, |
|
101 |
- ]); |
|
102 |
- $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
- 'notnull' => true, |
|
104 |
- 'length' => 512, |
|
105 |
- ]); |
|
106 |
- $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
- 'notnull' => true, |
|
108 |
- 'length' => 512, |
|
109 |
- ]); |
|
110 |
- $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
- 'notnull' => true, |
|
112 |
- 'length' => 512, |
|
113 |
- ]); |
|
114 |
- $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
- 'notnull' => true, |
|
116 |
- 'length' => 512, |
|
117 |
- ]); |
|
118 |
- $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
- 'notnull' => true, |
|
120 |
- 'length' => 512, |
|
121 |
- ]); |
|
122 |
- $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
- 'notnull' => true, |
|
124 |
- 'length' => 512, |
|
125 |
- ]); |
|
126 |
- $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
- 'notnull' => true, |
|
128 |
- 'length' => 512, |
|
129 |
- ]); |
|
130 |
- $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
- 'notnull' => true, |
|
132 |
- 'length' => 512, |
|
133 |
- ]); |
|
134 |
- $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
- 'notnull' => true, |
|
136 |
- 'length' => 512, |
|
137 |
- ]); |
|
138 |
- $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
- 'notnull' => false, |
|
140 |
- 'length' => 48, |
|
141 |
- 'default' => '', |
|
142 |
- ]); |
|
143 |
- $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
- 'notnull' => false, |
|
145 |
- 'length' => 48, |
|
146 |
- 'default' => '', |
|
147 |
- ]); |
|
148 |
- $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
- 'notnull' => false, |
|
150 |
- 'length' => 48, |
|
151 |
- 'default' => '', |
|
152 |
- ]); |
|
153 |
- $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
- 'notnull' => false, |
|
155 |
- 'length' => 48, |
|
156 |
- 'default' => '', |
|
157 |
- ]); |
|
158 |
- $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
- 'notnull' => false, |
|
160 |
- 'length' => 11, |
|
161 |
- 'unsigned' => true, |
|
162 |
- ]); |
|
163 |
- $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
- 'notnull' => false, |
|
165 |
- 'length' => 1, |
|
166 |
- ]); |
|
167 |
- $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
- 'notnull' => false, |
|
169 |
- 'length' => 512, |
|
170 |
- 'default' => '', |
|
171 |
- ]); |
|
172 |
- $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
- 'notnull' => false, |
|
174 |
- 'length' => 1, |
|
175 |
- ]); |
|
176 |
- $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
- 'notnull' => false, |
|
178 |
- 'length' => 1, |
|
179 |
- ]); |
|
180 |
- $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
- 'notnull' => false, |
|
182 |
- 'length' => 1, |
|
183 |
- ]); |
|
184 |
- $table->setPrimaryKey(['id']); |
|
185 |
- $table->addUniqueIndex(['id']); |
|
186 |
- |
|
187 |
- } |
|
188 |
- |
|
189 |
- |
|
190 |
- if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
- $table = $schema->createTable('sms_relent_received'); |
|
192 |
- $table->addColumn('id', Types::BIGINT, [ |
|
193 |
- 'autoincrement' => true, |
|
194 |
- 'notnull' => true, |
|
195 |
- 'length' => 11, |
|
196 |
- 'unsigned' => true, |
|
197 |
- ]); |
|
198 |
- $table->addColumn('user_id', Types::STRING, [ |
|
199 |
- 'notnull' => true, |
|
200 |
- 'length' => 64, |
|
201 |
- ]); |
|
202 |
- $table->addColumn('message_id', Types::STRING, [ |
|
203 |
- 'notnull' => true, |
|
204 |
- 'length' => 512, |
|
205 |
- ]); |
|
206 |
- $table->addColumn('date', Types::DATETIME, [ |
|
207 |
- 'notnull' => true, |
|
208 |
- ]); |
|
209 |
- $table->addColumn('from', Types::STRING, [ |
|
210 |
- 'notnull' => true, |
|
211 |
- 'length' => 128, |
|
212 |
- ]); |
|
213 |
- $table->addColumn('to', Types::STRING, [ |
|
214 |
- 'notnull' => true, |
|
215 |
- 'length' => 128, |
|
216 |
- ]); |
|
217 |
- $table->addColumn('message', Types::TEXT, [ |
|
218 |
- 'notnull' => false, |
|
219 |
- 'default' => '', |
|
220 |
- ]); |
|
221 |
- $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
- 'notnull' => true, |
|
223 |
- 'length' => 255, |
|
224 |
- ]); |
|
225 |
- $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
- 'notnull' => false, |
|
227 |
- 'length' => 1, |
|
228 |
- ]); |
|
229 |
- $table->setPrimaryKey(['id']); |
|
230 |
- $table->addUniqueIndex(['id']); |
|
231 |
- |
|
232 |
- } |
|
233 |
- |
|
234 |
- |
|
235 |
- if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
- $table = $schema->createTable('sms_relent_sent'); |
|
237 |
- $table->addColumn('id', Types::BIGINT, [ |
|
238 |
- 'autoincrement' => true, |
|
239 |
- 'notnull' => true, |
|
240 |
- 'length' => 11, |
|
241 |
- 'unsigned' => true, |
|
242 |
- ]); |
|
243 |
- $table->addColumn('user_id', Types::STRING, [ |
|
244 |
- 'notnull' => true, |
|
245 |
- 'length' => 64, |
|
246 |
- ]); |
|
247 |
- $table->addColumn('message_id', Types::STRING, [ |
|
248 |
- 'notnull' => true, |
|
249 |
- 'length' => 512, |
|
250 |
- ]); |
|
251 |
- $table->addColumn('date', Types::DATETIME, [ |
|
252 |
- 'notnull' => true, |
|
253 |
- ]); |
|
254 |
- $table->addColumn('from', Types::STRING, [ |
|
255 |
- 'notnull' => true, |
|
256 |
- 'length' => 128, |
|
257 |
- ]); |
|
258 |
- $table->addColumn('to', Types::STRING, [ |
|
259 |
- 'notnull' => true, |
|
260 |
- 'length' => 128, |
|
261 |
- ]); |
|
262 |
- $table->addColumn('network ', Types::STRING, [ |
|
263 |
- 'notnull' => false, |
|
264 |
- 'length' => 64, |
|
265 |
- 'default' => '', |
|
266 |
- ]); |
|
267 |
- $table->addColumn('price', Types::STRING, [ |
|
268 |
- 'notnull' => false, |
|
269 |
- 'length' => 64, |
|
270 |
- 'default' => '', |
|
271 |
- ]); |
|
272 |
- $table->addColumn('status', Types::STRING, [ |
|
273 |
- 'notnull' => false, |
|
274 |
- 'length' => 512, |
|
275 |
- 'default' => '', |
|
276 |
- ]); |
|
277 |
- $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
- 'notnull' => false, |
|
279 |
- 'length' => 64, |
|
280 |
- 'default' => '', |
|
281 |
- ]); |
|
282 |
- $table->addColumn('message', Types::TEXT, [ |
|
283 |
- 'notnull' => false, |
|
284 |
- 'default' => '', |
|
285 |
- ]); |
|
286 |
- $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
- 'notnull' => true, |
|
288 |
- 'length' => 255, |
|
289 |
- ]); |
|
290 |
- $table->setPrimaryKey(['id']); |
|
291 |
- $table->addUniqueIndex(['id']); |
|
292 |
- |
|
293 |
- } |
|
294 |
- |
|
295 |
- |
|
296 |
- if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
- $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
- $table->addColumn('id', Types::BIGINT, [ |
|
299 |
- 'autoincrement' => true, |
|
300 |
- 'notnull' => true, |
|
301 |
- 'length' => 11, |
|
302 |
- 'unsigned' => true, |
|
303 |
- ]); |
|
304 |
- $table->addColumn('user_id', Types::STRING, [ |
|
305 |
- 'notnull' => true, |
|
306 |
- 'length' => 128, |
|
307 |
- ]); |
|
308 |
- $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
- 'notnull' => true, |
|
310 |
- 'length' => 255, |
|
311 |
- ]); |
|
312 |
- $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
- 'notnull' => true, |
|
314 |
- 'length' => 128, |
|
315 |
- ]); |
|
316 |
- $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
- 'notnull' => false, |
|
318 |
- 'length' => 64, |
|
319 |
- 'default' => '', |
|
320 |
- ]); |
|
321 |
- $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
- 'notnull' => false, |
|
323 |
- 'length' => 8, |
|
324 |
- 'default' => '', |
|
325 |
- ]); |
|
326 |
- $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
- 'notnull' => false, |
|
328 |
- 'length' => 8, |
|
329 |
- 'default' => '', |
|
330 |
- ]); |
|
331 |
- $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
- 'notnull' => false, |
|
333 |
- ]); |
|
334 |
- $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
- 'notnull' => false, |
|
336 |
- ]); |
|
337 |
- $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
- 'notnull' => false, |
|
339 |
- 'default' => '', |
|
340 |
- ]); |
|
341 |
- $table->setPrimaryKey(['id']); |
|
342 |
- $table->addUniqueIndex(['id']); |
|
343 |
- |
|
344 |
- } |
|
345 |
- |
|
346 |
- |
|
347 |
- if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
- $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
- $table->addColumn('id', Types::BIGINT, [ |
|
350 |
- 'autoincrement' => true, |
|
351 |
- 'notnull' => true, |
|
352 |
- 'length' => 11, |
|
353 |
- 'unsigned' => true, |
|
354 |
- ]); |
|
355 |
- $table->addColumn('user_id', Types::STRING, [ |
|
356 |
- 'notnull' => true, |
|
357 |
- 'length' => 128, |
|
358 |
- ]); |
|
359 |
- $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
- 'notnull' => true, |
|
361 |
- 'length' => 255, |
|
362 |
- ]); |
|
363 |
- $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
- 'notnull' => true, |
|
365 |
- 'length' => 128, |
|
366 |
- ]); |
|
367 |
- $table->addColumn('groups', Types::STRING, [ |
|
368 |
- 'notnull' => true, |
|
369 |
- 'length' => 2048, |
|
370 |
- ]); |
|
371 |
- $table->addColumn('users', Types::STRING, [ |
|
372 |
- 'notnull' => true, |
|
373 |
- 'length' => 2048, |
|
374 |
- ]); |
|
375 |
- $table->setPrimaryKey(['id']); |
|
376 |
- $table->addUniqueIndex(['id']); |
|
377 |
- |
|
378 |
- } |
|
379 |
- |
|
380 |
- return $schema; |
|
381 |
- } |
|
382 |
- |
|
383 |
- public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
- |
|
385 |
- // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade |
|
386 |
- $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`'); |
|
387 |
- $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
- |
|
389 |
- $recdatauids = []; |
|
390 |
- $idsent = []; |
|
391 |
- while ($rowfetched = $getrecfromnbres->fetch()) { |
|
392 |
- $recdatauids[] = $rowfetched['user_id']; |
|
393 |
- $idsent[] = $rowfetched['id']; |
|
394 |
- } |
|
395 |
- $getrecfromnbres->closeCursor(); |
|
396 |
- |
|
397 |
- if ($recdatauids) { |
|
398 |
- |
|
399 |
- $recuids = array_values(array_unique($recdatauids)); |
|
400 |
- $acdatausrdn = []; |
|
401 |
- |
|
402 |
- foreach ($recuids as $dnkey => $dnvalue) { |
|
403 |
- $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
404 |
- $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
405 |
- |
|
406 |
- while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
407 |
- $acdatausrdn[$dnvalue] = $acusrdnfetched['value']; |
|
408 |
- } |
|
409 |
- $getacdatadnres->closeCursor(); |
|
410 |
- } |
|
411 |
- |
|
412 |
- foreach ($recdatauids as $pdpkey => $pdpvalue) { |
|
413 |
- |
|
414 |
- $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?'); |
|
415 |
- $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]); |
|
416 |
- $updaterecmsres->closeCursor(); |
|
417 |
- } |
|
418 |
- } |
|
419 |
- |
|
420 |
- |
|
421 |
- // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade |
|
422 |
- $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`'); |
|
423 |
- $getrecfromnbres = $getrecfromnb->execute(); |
|
424 |
- |
|
425 |
- $recdatanmbrs = []; |
|
426 |
- $idsrc = []; |
|
427 |
- $daterec = []; |
|
428 |
- while ($rowfetched = $getrecfromnbres->fetch()) { |
|
429 |
- $recdatanmbrs[] = $rowfetched['from']; |
|
430 |
- $idsrc[] = $rowfetched['id']; |
|
431 |
- $daterecarr = explode(":", $rowfetched['date']); |
|
432 |
- $daterec[] = $daterecarr[0]; |
|
433 |
- } |
|
434 |
- $getrecfromnbres->closeCursor(); |
|
435 |
- |
|
436 |
- if ($recdatanmbrs) { |
|
437 |
- |
|
438 |
- foreach ($recdatanmbrs as $rckey => $rcvalue) { |
|
439 |
- |
|
440 |
- $authorDisplayNm = ''; |
|
441 |
- $internalSender = 0; |
|
442 |
- |
|
443 |
- // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table |
|
444 |
- $recmsgfromprc = '%' . $rcvalue; |
|
445 |
- $recdataprc = $daterec[$rckey] . '%'; |
|
446 |
- $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?'); |
|
447 |
- $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]); |
|
448 |
- |
|
449 |
- $dispnamearr = []; |
|
450 |
- while ($dspnmstfetched = $getdspnmstres->fetch()) { |
|
451 |
- $dispnamearr[] = $dspnmstfetched['author_displayname']; |
|
452 |
- } |
|
453 |
- $getdspnmstres->closeCursor(); |
|
454 |
- |
|
455 |
- if ($dispnamearr) { |
|
456 |
- $descdspnmarr = array_reverse($dispnamearr); |
|
457 |
- $authorDisplayNm = $descdspnmarr[0]; |
|
458 |
- $internalSender = 1; |
|
459 |
- } else { $authorDisplayNm = ''; $internalSender = 0; } |
|
460 |
- |
|
461 |
- |
|
462 |
- if (!$authorDisplayNm) { |
|
463 |
- |
|
464 |
- // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table |
|
465 |
- $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?'); |
|
466 |
- $getdspnmres = $getdspnm->execute([$rcvalue]); |
|
467 |
- |
|
468 |
- $dspnmearr = []; |
|
469 |
- while ($dspnmfetched = $getdspnmres->fetch()) { |
|
470 |
- if ($dspnmfetched['author_displayname']) { |
|
471 |
- $dspnmearr[] = $dspnmfetched['author_displayname']; |
|
472 |
- } |
|
473 |
- } |
|
474 |
- $getdspnmres->closeCursor(); |
|
475 |
- |
|
476 |
- if ($dspnmearr) { |
|
477 |
- $descdisplaynmarr = array_reverse($dspnmearr); |
|
478 |
- $authorDisplayNm = $descdisplaynmarr[0]; |
|
479 |
- $internalSender = 0; |
|
480 |
- } else { $authorDisplayNm = ''; $internalSender = 0; } |
|
481 |
- } |
|
482 |
- |
|
483 |
- $pdpkeyprc = '%' . $rcvalue; |
|
484 |
- $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? |
|
485 |
- WHERE `from` LIKE ? AND `id` = ?'); |
|
486 |
- $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $pdpkeyprc, $idsrc[$rckey]]); |
|
487 |
- $updaterecmsres->closeCursor(); |
|
488 |
- } |
|
489 |
- } |
|
490 |
- |
|
491 |
- return null; |
|
492 |
- } |
|
493 |
- |
|
494 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,494 @@ |
1 |
+<?php |
|
2 |
+/** |
|
3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
+ * |
|
5 |
+ * @author Double Bastion LLC |
|
6 |
+ * |
|
7 |
+ * @license GNU AGPL version 3 or any later version |
|
8 |
+ * |
|
9 |
+ * This program is free software; you can redistribute it and/or |
|
10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
+ * License as published by the Free Software Foundation; either |
|
12 |
+ * version 3 of the License, or any later version. |
|
13 |
+ * |
|
14 |
+ * This program is distributed in the hope that it will be useful, |
|
15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
+ * |
|
19 |
+ * You should have received a copy of the GNU Affero General Public |
|
20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
+ * |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+declare(strict_types=1); |
|
25 |
+ |
|
26 |
+namespace OCA\SMSRelentless\Migration; |
|
27 |
+ |
|
28 |
+use Closure; |
|
29 |
+use OCP\DB\Types; |
|
30 |
+use OCP\DB\ISchemaWrapper; |
|
31 |
+use OCP\IDBConnection; |
|
32 |
+use OCP\Migration\IOutput; |
|
33 |
+use OCP\Migration\SimpleMigrationStep; |
|
34 |
+ |
|
35 |
+ |
|
36 |
+class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
+ |
|
38 |
+ /** @var IDBConnection */ |
|
39 |
+ private $connection; |
|
40 |
+ |
|
41 |
+ /** |
|
42 |
+ * @param IDBConnection $connection |
|
43 |
+ */ |
|
44 |
+ public function __construct(IDBConnection $connection) { |
|
45 |
+ $this->connection = $connection; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ /** |
|
49 |
+ * @param IOutput $output |
|
50 |
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
+ * @param array $options |
|
52 |
+ * @return null|ISchemaWrapper |
|
53 |
+ */ |
|
54 |
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
+ /** @var ISchemaWrapper $schema */ |
|
56 |
+ $schema = $schemaClosure(); |
|
57 |
+ |
|
58 |
+ if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
+ $table = $schema->createTable('sms_relent_settings'); |
|
60 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
61 |
+ 'autoincrement' => true, |
|
62 |
+ 'notnull' => true, |
|
63 |
+ 'length' => 11, |
|
64 |
+ 'unsigned' => true, |
|
65 |
+ ]); |
|
66 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
67 |
+ 'notnull' => true, |
|
68 |
+ 'length' => 128, |
|
69 |
+ ]); |
|
70 |
+ $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
+ 'notnull' => true, |
|
72 |
+ 'length' => 512, |
|
73 |
+ ]); |
|
74 |
+ $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
+ 'notnull' => true, |
|
76 |
+ 'length' => 512, |
|
77 |
+ ]); |
|
78 |
+ $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
+ 'notnull' => true, |
|
80 |
+ 'length' => 512, |
|
81 |
+ ]); |
|
82 |
+ $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
+ 'notnull' => true, |
|
84 |
+ 'length' => 512, |
|
85 |
+ ]); |
|
86 |
+ $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
+ 'notnull' => true, |
|
88 |
+ 'length' => 512, |
|
89 |
+ ]); |
|
90 |
+ $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
+ 'notnull' => true, |
|
92 |
+ 'length' => 512, |
|
93 |
+ ]); |
|
94 |
+ $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
+ 'notnull' => true, |
|
96 |
+ 'length' => 512, |
|
97 |
+ ]); |
|
98 |
+ $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
+ 'notnull' => true, |
|
100 |
+ 'length' => 512, |
|
101 |
+ ]); |
|
102 |
+ $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
+ 'notnull' => true, |
|
104 |
+ 'length' => 512, |
|
105 |
+ ]); |
|
106 |
+ $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
+ 'notnull' => true, |
|
108 |
+ 'length' => 512, |
|
109 |
+ ]); |
|
110 |
+ $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
+ 'notnull' => true, |
|
112 |
+ 'length' => 512, |
|
113 |
+ ]); |
|
114 |
+ $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
+ 'notnull' => true, |
|
116 |
+ 'length' => 512, |
|
117 |
+ ]); |
|
118 |
+ $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
+ 'notnull' => true, |
|
120 |
+ 'length' => 512, |
|
121 |
+ ]); |
|
122 |
+ $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
+ 'notnull' => true, |
|
124 |
+ 'length' => 512, |
|
125 |
+ ]); |
|
126 |
+ $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
+ 'notnull' => true, |
|
128 |
+ 'length' => 512, |
|
129 |
+ ]); |
|
130 |
+ $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
+ 'notnull' => true, |
|
132 |
+ 'length' => 512, |
|
133 |
+ ]); |
|
134 |
+ $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
+ 'notnull' => true, |
|
136 |
+ 'length' => 512, |
|
137 |
+ ]); |
|
138 |
+ $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
+ 'notnull' => false, |
|
140 |
+ 'length' => 48, |
|
141 |
+ 'default' => '', |
|
142 |
+ ]); |
|
143 |
+ $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
+ 'notnull' => false, |
|
145 |
+ 'length' => 48, |
|
146 |
+ 'default' => '', |
|
147 |
+ ]); |
|
148 |
+ $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
+ 'notnull' => false, |
|
150 |
+ 'length' => 48, |
|
151 |
+ 'default' => '', |
|
152 |
+ ]); |
|
153 |
+ $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
+ 'notnull' => false, |
|
155 |
+ 'length' => 48, |
|
156 |
+ 'default' => '', |
|
157 |
+ ]); |
|
158 |
+ $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
+ 'notnull' => false, |
|
160 |
+ 'length' => 11, |
|
161 |
+ 'unsigned' => true, |
|
162 |
+ ]); |
|
163 |
+ $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
+ 'notnull' => false, |
|
165 |
+ 'length' => 1, |
|
166 |
+ ]); |
|
167 |
+ $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
+ 'notnull' => false, |
|
169 |
+ 'length' => 512, |
|
170 |
+ 'default' => '', |
|
171 |
+ ]); |
|
172 |
+ $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
+ 'notnull' => false, |
|
174 |
+ 'length' => 1, |
|
175 |
+ ]); |
|
176 |
+ $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
+ 'notnull' => false, |
|
178 |
+ 'length' => 1, |
|
179 |
+ ]); |
|
180 |
+ $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
+ 'notnull' => false, |
|
182 |
+ 'length' => 1, |
|
183 |
+ ]); |
|
184 |
+ $table->setPrimaryKey(['id']); |
|
185 |
+ $table->addUniqueIndex(['id']); |
|
186 |
+ |
|
187 |
+ } |
|
188 |
+ |
|
189 |
+ |
|
190 |
+ if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
+ $table = $schema->createTable('sms_relent_received'); |
|
192 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
193 |
+ 'autoincrement' => true, |
|
194 |
+ 'notnull' => true, |
|
195 |
+ 'length' => 11, |
|
196 |
+ 'unsigned' => true, |
|
197 |
+ ]); |
|
198 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
199 |
+ 'notnull' => true, |
|
200 |
+ 'length' => 64, |
|
201 |
+ ]); |
|
202 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
203 |
+ 'notnull' => true, |
|
204 |
+ 'length' => 512, |
|
205 |
+ ]); |
|
206 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
207 |
+ 'notnull' => true, |
|
208 |
+ ]); |
|
209 |
+ $table->addColumn('from', Types::STRING, [ |
|
210 |
+ 'notnull' => true, |
|
211 |
+ 'length' => 128, |
|
212 |
+ ]); |
|
213 |
+ $table->addColumn('to', Types::STRING, [ |
|
214 |
+ 'notnull' => true, |
|
215 |
+ 'length' => 128, |
|
216 |
+ ]); |
|
217 |
+ $table->addColumn('message', Types::TEXT, [ |
|
218 |
+ 'notnull' => false, |
|
219 |
+ 'default' => '', |
|
220 |
+ ]); |
|
221 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
+ 'notnull' => true, |
|
223 |
+ 'length' => 255, |
|
224 |
+ ]); |
|
225 |
+ $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
+ 'notnull' => false, |
|
227 |
+ 'length' => 1, |
|
228 |
+ ]); |
|
229 |
+ $table->setPrimaryKey(['id']); |
|
230 |
+ $table->addUniqueIndex(['id']); |
|
231 |
+ |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ |
|
235 |
+ if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
+ $table = $schema->createTable('sms_relent_sent'); |
|
237 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
238 |
+ 'autoincrement' => true, |
|
239 |
+ 'notnull' => true, |
|
240 |
+ 'length' => 11, |
|
241 |
+ 'unsigned' => true, |
|
242 |
+ ]); |
|
243 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
244 |
+ 'notnull' => true, |
|
245 |
+ 'length' => 64, |
|
246 |
+ ]); |
|
247 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
248 |
+ 'notnull' => true, |
|
249 |
+ 'length' => 512, |
|
250 |
+ ]); |
|
251 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
252 |
+ 'notnull' => true, |
|
253 |
+ ]); |
|
254 |
+ $table->addColumn('from', Types::STRING, [ |
|
255 |
+ 'notnull' => true, |
|
256 |
+ 'length' => 128, |
|
257 |
+ ]); |
|
258 |
+ $table->addColumn('to', Types::STRING, [ |
|
259 |
+ 'notnull' => true, |
|
260 |
+ 'length' => 128, |
|
261 |
+ ]); |
|
262 |
+ $table->addColumn('network ', Types::STRING, [ |
|
263 |
+ 'notnull' => false, |
|
264 |
+ 'length' => 64, |
|
265 |
+ 'default' => '', |
|
266 |
+ ]); |
|
267 |
+ $table->addColumn('price', Types::STRING, [ |
|
268 |
+ 'notnull' => false, |
|
269 |
+ 'length' => 64, |
|
270 |
+ 'default' => '', |
|
271 |
+ ]); |
|
272 |
+ $table->addColumn('status', Types::STRING, [ |
|
273 |
+ 'notnull' => false, |
|
274 |
+ 'length' => 512, |
|
275 |
+ 'default' => '', |
|
276 |
+ ]); |
|
277 |
+ $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
+ 'notnull' => false, |
|
279 |
+ 'length' => 64, |
|
280 |
+ 'default' => '', |
|
281 |
+ ]); |
|
282 |
+ $table->addColumn('message', Types::TEXT, [ |
|
283 |
+ 'notnull' => false, |
|
284 |
+ 'default' => '', |
|
285 |
+ ]); |
|
286 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
+ 'notnull' => true, |
|
288 |
+ 'length' => 255, |
|
289 |
+ ]); |
|
290 |
+ $table->setPrimaryKey(['id']); |
|
291 |
+ $table->addUniqueIndex(['id']); |
|
292 |
+ |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+ |
|
296 |
+ if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
+ $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
299 |
+ 'autoincrement' => true, |
|
300 |
+ 'notnull' => true, |
|
301 |
+ 'length' => 11, |
|
302 |
+ 'unsigned' => true, |
|
303 |
+ ]); |
|
304 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
305 |
+ 'notnull' => true, |
|
306 |
+ 'length' => 128, |
|
307 |
+ ]); |
|
308 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
+ 'notnull' => true, |
|
310 |
+ 'length' => 255, |
|
311 |
+ ]); |
|
312 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
+ 'notnull' => true, |
|
314 |
+ 'length' => 128, |
|
315 |
+ ]); |
|
316 |
+ $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
+ 'notnull' => false, |
|
318 |
+ 'length' => 64, |
|
319 |
+ 'default' => '', |
|
320 |
+ ]); |
|
321 |
+ $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
+ 'notnull' => false, |
|
323 |
+ 'length' => 8, |
|
324 |
+ 'default' => '', |
|
325 |
+ ]); |
|
326 |
+ $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
+ 'notnull' => false, |
|
328 |
+ 'length' => 8, |
|
329 |
+ 'default' => '', |
|
330 |
+ ]); |
|
331 |
+ $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
+ 'notnull' => false, |
|
333 |
+ ]); |
|
334 |
+ $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
+ 'notnull' => false, |
|
336 |
+ ]); |
|
337 |
+ $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
+ 'notnull' => false, |
|
339 |
+ 'default' => '', |
|
340 |
+ ]); |
|
341 |
+ $table->setPrimaryKey(['id']); |
|
342 |
+ $table->addUniqueIndex(['id']); |
|
343 |
+ |
|
344 |
+ } |
|
345 |
+ |
|
346 |
+ |
|
347 |
+ if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
+ $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
350 |
+ 'autoincrement' => true, |
|
351 |
+ 'notnull' => true, |
|
352 |
+ 'length' => 11, |
|
353 |
+ 'unsigned' => true, |
|
354 |
+ ]); |
|
355 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
356 |
+ 'notnull' => true, |
|
357 |
+ 'length' => 128, |
|
358 |
+ ]); |
|
359 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
+ 'notnull' => true, |
|
361 |
+ 'length' => 255, |
|
362 |
+ ]); |
|
363 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
+ 'notnull' => true, |
|
365 |
+ 'length' => 128, |
|
366 |
+ ]); |
|
367 |
+ $table->addColumn('groups', Types::STRING, [ |
|
368 |
+ 'notnull' => true, |
|
369 |
+ 'length' => 2048, |
|
370 |
+ ]); |
|
371 |
+ $table->addColumn('users', Types::STRING, [ |
|
372 |
+ 'notnull' => true, |
|
373 |
+ 'length' => 2048, |
|
374 |
+ ]); |
|
375 |
+ $table->setPrimaryKey(['id']); |
|
376 |
+ $table->addUniqueIndex(['id']); |
|
377 |
+ |
|
378 |
+ } |
|
379 |
+ |
|
380 |
+ return $schema; |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
+ |
|
385 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade |
|
386 |
+ $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`'); |
|
387 |
+ $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
+ |
|
389 |
+ $recdatauids = []; |
|
390 |
+ $idsent = []; |
|
391 |
+ while ($rowfetched = $getrecfromnbres->fetch()) { |
|
392 |
+ $recdatauids[] = $rowfetched['user_id']; |
|
393 |
+ $idsent[] = $rowfetched['id']; |
|
394 |
+ } |
|
395 |
+ $getrecfromnbres->closeCursor(); |
|
396 |
+ |
|
397 |
+ if ($recdatauids) { |
|
398 |
+ |
|
399 |
+ $recuids = array_values(array_unique($recdatauids)); |
|
400 |
+ $acdatausrdn = []; |
|
401 |
+ |
|
402 |
+ foreach ($recuids as $dnkey => $dnvalue) { |
|
403 |
+ $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
404 |
+ $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
405 |
+ |
|
406 |
+ while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
407 |
+ $acdatausrdn[$dnvalue] = $acusrdnfetched['value']; |
|
408 |
+ } |
|
409 |
+ $getacdatadnres->closeCursor(); |
|
410 |
+ } |
|
411 |
+ |
|
412 |
+ foreach ($recdatauids as $pdpkey => $pdpvalue) { |
|
413 |
+ |
|
414 |
+ $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?'); |
|
415 |
+ $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]); |
|
416 |
+ $updaterecmsres->closeCursor(); |
|
417 |
+ } |
|
418 |
+ } |
|
419 |
+ |
|
420 |
+ |
|
421 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade |
|
422 |
+ $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`'); |
|
423 |
+ $getrecfromnbres = $getrecfromnb->execute(); |
|
424 |
+ |
|
425 |
+ $recdatanmbrs = []; |
|
426 |
+ $idsrc = []; |
|
427 |
+ $daterec = []; |
|
428 |
+ while ($rowfetched = $getrecfromnbres->fetch()) { |
|
429 |
+ $recdatanmbrs[] = $rowfetched['from']; |
|
430 |
+ $idsrc[] = $rowfetched['id']; |
|
431 |
+ $daterecarr = explode(":", $rowfetched['date']); |
|
432 |
+ $daterec[] = $daterecarr[0]; |
|
433 |
+ } |
|
434 |
+ $getrecfromnbres->closeCursor(); |
|
435 |
+ |
|
436 |
+ if ($recdatanmbrs) { |
|
437 |
+ |
|
438 |
+ foreach ($recdatanmbrs as $rckey => $rcvalue) { |
|
439 |
+ |
|
440 |
+ $authorDisplayNm = ''; |
|
441 |
+ $internalSender = 0; |
|
442 |
+ |
|
443 |
+ // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table |
|
444 |
+ $recmsgfromprc = '%' . $rcvalue; |
|
445 |
+ $recdataprc = $daterec[$rckey] . '%'; |
|
446 |
+ $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?'); |
|
447 |
+ $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]); |
|
448 |
+ |
|
449 |
+ $dispnamearr = []; |
|
450 |
+ while ($dspnmstfetched = $getdspnmstres->fetch()) { |
|
451 |
+ $dispnamearr[] = $dspnmstfetched['author_displayname']; |
|
452 |
+ } |
|
453 |
+ $getdspnmstres->closeCursor(); |
|
454 |
+ |
|
455 |
+ if ($dispnamearr) { |
|
456 |
+ $descdspnmarr = array_reverse($dispnamearr); |
|
457 |
+ $authorDisplayNm = $descdspnmarr[0]; |
|
458 |
+ $internalSender = 1; |
|
459 |
+ } else { $authorDisplayNm = ''; $internalSender = 0; } |
|
460 |
+ |
|
461 |
+ |
|
462 |
+ if (!$authorDisplayNm) { |
|
463 |
+ |
|
464 |
+ // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table |
|
465 |
+ $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?'); |
|
466 |
+ $getdspnmres = $getdspnm->execute([$rcvalue]); |
|
467 |
+ |
|
468 |
+ $dspnmearr = []; |
|
469 |
+ while ($dspnmfetched = $getdspnmres->fetch()) { |
|
470 |
+ if ($dspnmfetched['author_displayname']) { |
|
471 |
+ $dspnmearr[] = $dspnmfetched['author_displayname']; |
|
472 |
+ } |
|
473 |
+ } |
|
474 |
+ $getdspnmres->closeCursor(); |
|
475 |
+ |
|
476 |
+ if ($dspnmearr) { |
|
477 |
+ $descdisplaynmarr = array_reverse($dspnmearr); |
|
478 |
+ $authorDisplayNm = $descdisplaynmarr[0]; |
|
479 |
+ $internalSender = 0; |
|
480 |
+ } else { $authorDisplayNm = ''; $internalSender = 0; } |
|
481 |
+ } |
|
482 |
+ |
|
483 |
+ $pdpkeyprc = '%' . $rcvalue; |
|
484 |
+ $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? |
|
485 |
+ WHERE `from` LIKE ? AND `id` = ?'); |
|
486 |
+ $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $pdpkeyprc, $idsrc[$rckey]]); |
|
487 |
+ $updaterecmsres->closeCursor(); |
|
488 |
+ } |
|
489 |
+ } |
|
490 |
+ |
|
491 |
+ return null; |
|
492 |
+ } |
|
493 |
+ |
|
494 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,533 +0,0 @@ |
1 |
-<?php |
|
2 |
-/** |
|
3 |
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
- * |
|
5 |
- * @author Double Bastion LLC |
|
6 |
- * |
|
7 |
- * @license GNU AGPL version 3 or any later version |
|
8 |
- * |
|
9 |
- * This program is free software; you can redistribute it and/or |
|
10 |
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
- * License as published by the Free Software Foundation; either |
|
12 |
- * version 3 of the License, or any later version. |
|
13 |
- * |
|
14 |
- * This program is distributed in the hope that it will be useful, |
|
15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU Affero General Public |
|
20 |
- * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
- * |
|
22 |
- */ |
|
23 |
- |
|
24 |
-declare(strict_types=1); |
|
25 |
- |
|
26 |
-namespace OCA\SMSRelentless\Migration; |
|
27 |
- |
|
28 |
-use Closure; |
|
29 |
-use OCP\DB\Types; |
|
30 |
-use OCP\DB\ISchemaWrapper; |
|
31 |
-use OCP\IDBConnection; |
|
32 |
-use OCP\Migration\IOutput; |
|
33 |
-use OCP\Migration\SimpleMigrationStep; |
|
34 |
- |
|
35 |
- |
|
36 |
-class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
- |
|
38 |
- /** @var IDBConnection */ |
|
39 |
- private $connection; |
|
40 |
- |
|
41 |
- /** |
|
42 |
- * @param IDBConnection $connection |
|
43 |
- */ |
|
44 |
- public function __construct(IDBConnection $connection) { |
|
45 |
- $this->connection = $connection; |
|
46 |
- } |
|
47 |
- |
|
48 |
- /** |
|
49 |
- * @param IOutput $output |
|
50 |
- * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
- * @param array $options |
|
52 |
- * @return null|ISchemaWrapper |
|
53 |
- */ |
|
54 |
- public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
- /** @var ISchemaWrapper $schema */ |
|
56 |
- $schema = $schemaClosure(); |
|
57 |
- |
|
58 |
- if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
- $table = $schema->createTable('sms_relent_settings'); |
|
60 |
- $table->addColumn('id', Types::BIGINT, [ |
|
61 |
- 'autoincrement' => true, |
|
62 |
- 'notnull' => true, |
|
63 |
- 'length' => 11, |
|
64 |
- 'unsigned' => true, |
|
65 |
- ]); |
|
66 |
- $table->addColumn('user_id', Types::STRING, [ |
|
67 |
- 'notnull' => true, |
|
68 |
- 'length' => 128, |
|
69 |
- ]); |
|
70 |
- $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
- 'notnull' => true, |
|
72 |
- 'length' => 512, |
|
73 |
- ]); |
|
74 |
- $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
- 'notnull' => true, |
|
76 |
- 'length' => 512, |
|
77 |
- ]); |
|
78 |
- $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
- 'notnull' => true, |
|
80 |
- 'length' => 512, |
|
81 |
- ]); |
|
82 |
- $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
- 'notnull' => true, |
|
84 |
- 'length' => 512, |
|
85 |
- ]); |
|
86 |
- $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
- 'notnull' => true, |
|
88 |
- 'length' => 512, |
|
89 |
- ]); |
|
90 |
- $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
- 'notnull' => true, |
|
92 |
- 'length' => 512, |
|
93 |
- ]); |
|
94 |
- $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
- 'notnull' => true, |
|
96 |
- 'length' => 512, |
|
97 |
- ]); |
|
98 |
- $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
- 'notnull' => true, |
|
100 |
- 'length' => 512, |
|
101 |
- ]); |
|
102 |
- $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
- 'notnull' => true, |
|
104 |
- 'length' => 512, |
|
105 |
- ]); |
|
106 |
- $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
- 'notnull' => true, |
|
108 |
- 'length' => 512, |
|
109 |
- ]); |
|
110 |
- $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
- 'notnull' => true, |
|
112 |
- 'length' => 512, |
|
113 |
- ]); |
|
114 |
- $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
- 'notnull' => true, |
|
116 |
- 'length' => 512, |
|
117 |
- ]); |
|
118 |
- $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
- 'notnull' => true, |
|
120 |
- 'length' => 512, |
|
121 |
- ]); |
|
122 |
- $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
- 'notnull' => true, |
|
124 |
- 'length' => 512, |
|
125 |
- ]); |
|
126 |
- $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
- 'notnull' => true, |
|
128 |
- 'length' => 512, |
|
129 |
- ]); |
|
130 |
- $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
- 'notnull' => true, |
|
132 |
- 'length' => 512, |
|
133 |
- ]); |
|
134 |
- $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
- 'notnull' => true, |
|
136 |
- 'length' => 512, |
|
137 |
- ]); |
|
138 |
- $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
- 'notnull' => false, |
|
140 |
- 'length' => 48, |
|
141 |
- 'default' => '', |
|
142 |
- ]); |
|
143 |
- $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
- 'notnull' => false, |
|
145 |
- 'length' => 48, |
|
146 |
- 'default' => '', |
|
147 |
- ]); |
|
148 |
- $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
- 'notnull' => false, |
|
150 |
- 'length' => 48, |
|
151 |
- 'default' => '', |
|
152 |
- ]); |
|
153 |
- $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
- 'notnull' => false, |
|
155 |
- 'length' => 48, |
|
156 |
- 'default' => '', |
|
157 |
- ]); |
|
158 |
- $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
- 'notnull' => false, |
|
160 |
- 'length' => 11, |
|
161 |
- 'unsigned' => true, |
|
162 |
- ]); |
|
163 |
- $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
- 'notnull' => false, |
|
165 |
- 'length' => 1, |
|
166 |
- ]); |
|
167 |
- $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
- 'notnull' => false, |
|
169 |
- 'length' => 512, |
|
170 |
- 'default' => '', |
|
171 |
- ]); |
|
172 |
- $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
- 'notnull' => false, |
|
174 |
- 'length' => 1, |
|
175 |
- ]); |
|
176 |
- $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
- 'notnull' => false, |
|
178 |
- 'length' => 1, |
|
179 |
- ]); |
|
180 |
- $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
- 'notnull' => false, |
|
182 |
- 'length' => 1, |
|
183 |
- ]); |
|
184 |
- $table->setPrimaryKey(['id']); |
|
185 |
- $table->addUniqueIndex(['id']); |
|
186 |
- |
|
187 |
- } |
|
188 |
- |
|
189 |
- |
|
190 |
- if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
- $table = $schema->createTable('sms_relent_received'); |
|
192 |
- $table->addColumn('id', Types::BIGINT, [ |
|
193 |
- 'autoincrement' => true, |
|
194 |
- 'notnull' => true, |
|
195 |
- 'length' => 11, |
|
196 |
- 'unsigned' => true, |
|
197 |
- ]); |
|
198 |
- $table->addColumn('user_id', Types::STRING, [ |
|
199 |
- 'notnull' => true, |
|
200 |
- 'length' => 64, |
|
201 |
- ]); |
|
202 |
- $table->addColumn('message_id', Types::STRING, [ |
|
203 |
- 'notnull' => true, |
|
204 |
- 'length' => 512, |
|
205 |
- ]); |
|
206 |
- $table->addColumn('date', Types::DATETIME, [ |
|
207 |
- 'notnull' => true, |
|
208 |
- ]); |
|
209 |
- $table->addColumn('from', Types::STRING, [ |
|
210 |
- 'notnull' => true, |
|
211 |
- 'length' => 128, |
|
212 |
- ]); |
|
213 |
- $table->addColumn('to', Types::STRING, [ |
|
214 |
- 'notnull' => true, |
|
215 |
- 'length' => 128, |
|
216 |
- ]); |
|
217 |
- $table->addColumn('message', Types::TEXT, [ |
|
218 |
- 'notnull' => false, |
|
219 |
- 'default' => '', |
|
220 |
- ]); |
|
221 |
- $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
- 'notnull' => true, |
|
223 |
- 'length' => 255, |
|
224 |
- ]); |
|
225 |
- $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
- 'notnull' => false, |
|
227 |
- 'length' => 1, |
|
228 |
- ]); |
|
229 |
- $table->setPrimaryKey(['id']); |
|
230 |
- $table->addUniqueIndex(['id']); |
|
231 |
- |
|
232 |
- } |
|
233 |
- |
|
234 |
- |
|
235 |
- if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
- $table = $schema->createTable('sms_relent_sent'); |
|
237 |
- $table->addColumn('id', Types::BIGINT, [ |
|
238 |
- 'autoincrement' => true, |
|
239 |
- 'notnull' => true, |
|
240 |
- 'length' => 11, |
|
241 |
- 'unsigned' => true, |
|
242 |
- ]); |
|
243 |
- $table->addColumn('user_id', Types::STRING, [ |
|
244 |
- 'notnull' => true, |
|
245 |
- 'length' => 64, |
|
246 |
- ]); |
|
247 |
- $table->addColumn('message_id', Types::STRING, [ |
|
248 |
- 'notnull' => true, |
|
249 |
- 'length' => 512, |
|
250 |
- ]); |
|
251 |
- $table->addColumn('date', Types::DATETIME, [ |
|
252 |
- 'notnull' => true, |
|
253 |
- ]); |
|
254 |
- $table->addColumn('from', Types::STRING, [ |
|
255 |
- 'notnull' => true, |
|
256 |
- 'length' => 128, |
|
257 |
- ]); |
|
258 |
- $table->addColumn('to', Types::STRING, [ |
|
259 |
- 'notnull' => true, |
|
260 |
- 'length' => 128, |
|
261 |
- ]); |
|
262 |
- $table->addColumn('network ', Types::STRING, [ |
|
263 |
- 'notnull' => false, |
|
264 |
- 'length' => 64, |
|
265 |
- 'default' => '', |
|
266 |
- ]); |
|
267 |
- $table->addColumn('price', Types::STRING, [ |
|
268 |
- 'notnull' => false, |
|
269 |
- 'length' => 64, |
|
270 |
- 'default' => '', |
|
271 |
- ]); |
|
272 |
- $table->addColumn('status', Types::STRING, [ |
|
273 |
- 'notnull' => false, |
|
274 |
- 'length' => 512, |
|
275 |
- 'default' => '', |
|
276 |
- ]); |
|
277 |
- $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
- 'notnull' => false, |
|
279 |
- 'length' => 64, |
|
280 |
- 'default' => '', |
|
281 |
- ]); |
|
282 |
- $table->addColumn('message', Types::TEXT, [ |
|
283 |
- 'notnull' => false, |
|
284 |
- 'default' => '', |
|
285 |
- ]); |
|
286 |
- $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
- 'notnull' => true, |
|
288 |
- 'length' => 255, |
|
289 |
- ]); |
|
290 |
- $table->setPrimaryKey(['id']); |
|
291 |
- $table->addUniqueIndex(['id']); |
|
292 |
- |
|
293 |
- } |
|
294 |
- |
|
295 |
- |
|
296 |
- if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
- $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
- $table->addColumn('id', Types::BIGINT, [ |
|
299 |
- 'autoincrement' => true, |
|
300 |
- 'notnull' => true, |
|
301 |
- 'length' => 11, |
|
302 |
- 'unsigned' => true, |
|
303 |
- ]); |
|
304 |
- $table->addColumn('user_id', Types::STRING, [ |
|
305 |
- 'notnull' => true, |
|
306 |
- 'length' => 128, |
|
307 |
- ]); |
|
308 |
- $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
- 'notnull' => true, |
|
310 |
- 'length' => 255, |
|
311 |
- ]); |
|
312 |
- $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
- 'notnull' => true, |
|
314 |
- 'length' => 128, |
|
315 |
- ]); |
|
316 |
- $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
- 'notnull' => false, |
|
318 |
- 'length' => 64, |
|
319 |
- 'default' => '', |
|
320 |
- ]); |
|
321 |
- $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
- 'notnull' => false, |
|
323 |
- 'length' => 8, |
|
324 |
- 'default' => '', |
|
325 |
- ]); |
|
326 |
- $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
- 'notnull' => false, |
|
328 |
- 'length' => 8, |
|
329 |
- 'default' => '', |
|
330 |
- ]); |
|
331 |
- $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
- 'notnull' => false, |
|
333 |
- ]); |
|
334 |
- $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
- 'notnull' => false, |
|
336 |
- ]); |
|
337 |
- $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
- 'notnull' => false, |
|
339 |
- 'default' => '', |
|
340 |
- ]); |
|
341 |
- $table->setPrimaryKey(['id']); |
|
342 |
- $table->addUniqueIndex(['id']); |
|
343 |
- |
|
344 |
- } |
|
345 |
- |
|
346 |
- |
|
347 |
- if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
- $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
- $table->addColumn('id', Types::BIGINT, [ |
|
350 |
- 'autoincrement' => true, |
|
351 |
- 'notnull' => true, |
|
352 |
- 'length' => 11, |
|
353 |
- 'unsigned' => true, |
|
354 |
- ]); |
|
355 |
- $table->addColumn('user_id', Types::STRING, [ |
|
356 |
- 'notnull' => true, |
|
357 |
- 'length' => 128, |
|
358 |
- ]); |
|
359 |
- $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
- 'notnull' => true, |
|
361 |
- 'length' => 255, |
|
362 |
- ]); |
|
363 |
- $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
- 'notnull' => true, |
|
365 |
- 'length' => 128, |
|
366 |
- ]); |
|
367 |
- $table->addColumn('groups', Types::STRING, [ |
|
368 |
- 'notnull' => true, |
|
369 |
- 'length' => 2048, |
|
370 |
- ]); |
|
371 |
- $table->addColumn('users', Types::STRING, [ |
|
372 |
- 'notnull' => true, |
|
373 |
- 'length' => 2048, |
|
374 |
- ]); |
|
375 |
- $table->setPrimaryKey(['id']); |
|
376 |
- $table->addUniqueIndex(['id']); |
|
377 |
- |
|
378 |
- } |
|
379 |
- |
|
380 |
- return $schema; |
|
381 |
- } |
|
382 |
- |
|
383 |
- public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
- |
|
385 |
- // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade |
|
386 |
- $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`'); |
|
387 |
- $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
- |
|
389 |
- $recdatanmbrs = []; |
|
390 |
- while ($rowfetched = $getrecfromnbres->fetch()) { |
|
391 |
- $recdatanmbrs[] = $rowfetched['from']; |
|
392 |
- } |
|
393 |
- $getrecfromnbres->closeCursor(); |
|
394 |
- |
|
395 |
- if ($recdatanmbrs) { |
|
396 |
- |
|
397 |
- $recnmbrs = array_values(array_unique($recdatanmbrs)); |
|
398 |
- |
|
399 |
- $phoneDisplayPairs = []; |
|
400 |
- foreach ($recnmbrs as $rckey => $rcvalue) { |
|
401 |
- |
|
402 |
- $rcvalueprc = '%' . $rcvalue; |
|
403 |
- $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
404 |
- $getacdatares = $getacdata->execute(['phone', $rcvalueprc]); |
|
405 |
- |
|
406 |
- $acdatausers = []; |
|
407 |
- while ($acusrfetched = $getacdatares->fetch()) { |
|
408 |
- $acdatausers[] = $acusrfetched['uid']; |
|
409 |
- } |
|
410 |
- $getacdatares->closeCursor(); |
|
411 |
- |
|
412 |
- |
|
413 |
- if ($acdatausers) { |
|
414 |
- |
|
415 |
- $acdatausrdn = []; |
|
416 |
- foreach ($acdatausers as $dnkey => $dnvalue) { |
|
417 |
- |
|
418 |
- $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
419 |
- $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
420 |
- |
|
421 |
- while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
422 |
- $acdatausrdn[] = $acusrdnfetched['value']; |
|
423 |
- } |
|
424 |
- $getacdatadnres->closeCursor(); |
|
425 |
- } |
|
426 |
- |
|
427 |
- if ($acdatausrdn) { |
|
428 |
- |
|
429 |
- if (count($acdatausrdn) == 1) { |
|
430 |
- |
|
431 |
- $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1]; |
|
432 |
- |
|
433 |
- } elseif (count($acdatausrdn) > 1) { |
|
434 |
- |
|
435 |
- $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1]; |
|
436 |
- } |
|
437 |
- |
|
438 |
- } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
439 |
- |
|
440 |
- } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
441 |
- } |
|
442 |
- |
|
443 |
- foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) { |
|
444 |
- |
|
445 |
- if (is_array($pdpvalue)) { |
|
446 |
- $pdpkeyprc = '%' . $pdpkey; |
|
447 |
- $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?'); |
|
448 |
- $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]); |
|
449 |
- $updaterecmsres->closeCursor(); |
|
450 |
- } |
|
451 |
- } |
|
452 |
- } |
|
453 |
- |
|
454 |
- |
|
455 |
- // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade |
|
456 |
- $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`'); |
|
457 |
- $getsentfromnbres = $getsentfromnb->execute(); |
|
458 |
- |
|
459 |
- $sentdatanmbrs = []; |
|
460 |
- while ($rowfetchedst = $getsentfromnbres->fetch()) { |
|
461 |
- |
|
462 |
- $sentdatanmbrspre = $rowfetchedst['from']; |
|
463 |
- $sentdatanmbrsarr = explode("+", $sentdatanmbrspre); |
|
464 |
- if (count($sentdatanmbrsarr) > 1) { |
|
465 |
- $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1]; |
|
466 |
- } else { |
|
467 |
- $sentdatanmbrs[] = $sentdatanmbrsarr[0]; |
|
468 |
- } |
|
469 |
- } |
|
470 |
- $getsentfromnbres->closeCursor(); |
|
471 |
- |
|
472 |
- if ($sentdatanmbrs) { |
|
473 |
- |
|
474 |
- $sentnmbrs = array_values(array_unique($sentdatanmbrs)); |
|
475 |
- |
|
476 |
- $phoneDisplayPairsst = []; |
|
477 |
- foreach ($sentnmbrs as $stkey => $stvalue) { |
|
478 |
- |
|
479 |
- $stvalueprc = '%' . $stvalue; |
|
480 |
- $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
481 |
- $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]); |
|
482 |
- |
|
483 |
- $acdatausersst = []; |
|
484 |
- while ($acusrstfetched = $getacdatastres->fetch()) { |
|
485 |
- $acdatausersst[] = $acusrstfetched['uid']; |
|
486 |
- } |
|
487 |
- $getacdatastres->closeCursor(); |
|
488 |
- |
|
489 |
- if ($acdatausersst) { |
|
490 |
- |
|
491 |
- $acdatausrdnst = []; |
|
492 |
- foreach ($acdatausersst as $dnstkey => $dnstvalue) { |
|
493 |
- |
|
494 |
- $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
495 |
- $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']); |
|
496 |
- |
|
497 |
- while ($acusrdnstfetched = $getacdatadnstres->fetch()) { |
|
498 |
- $acdatausrdnst[] = $acusrdnstfetched['value']; |
|
499 |
- } |
|
500 |
- $getacdatadnstres->closeCursor(); |
|
501 |
- } |
|
502 |
- |
|
503 |
- if ($acdatausrdnst) { |
|
504 |
- |
|
505 |
- if (count($acdatausrdnst) == 1) { |
|
506 |
- |
|
507 |
- $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]]; |
|
508 |
- |
|
509 |
- } elseif (count($acdatausrdnst) > 1) { |
|
510 |
- |
|
511 |
- $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)]; |
|
512 |
- } |
|
513 |
- |
|
514 |
- } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
515 |
- |
|
516 |
- } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
517 |
- } |
|
518 |
- |
|
519 |
- foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) { |
|
520 |
- |
|
521 |
- if (is_array($pstvalue)) { |
|
522 |
- $contfield = "%" . $pstkey; |
|
523 |
- $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?'); |
|
524 |
- $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]); |
|
525 |
- $updatesentmsres->closeCursor(); |
|
526 |
- } |
|
527 |
- } |
|
528 |
- } |
|
529 |
- |
|
530 |
- return null; |
|
531 |
- } |
|
532 |
- |
|
533 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,533 @@ |
1 |
+<?php |
|
2 |
+/** |
|
3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
+ * |
|
5 |
+ * @author Double Bastion LLC |
|
6 |
+ * |
|
7 |
+ * @license GNU AGPL version 3 or any later version |
|
8 |
+ * |
|
9 |
+ * This program is free software; you can redistribute it and/or |
|
10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
+ * License as published by the Free Software Foundation; either |
|
12 |
+ * version 3 of the License, or any later version. |
|
13 |
+ * |
|
14 |
+ * This program is distributed in the hope that it will be useful, |
|
15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
+ * |
|
19 |
+ * You should have received a copy of the GNU Affero General Public |
|
20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
+ * |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+declare(strict_types=1); |
|
25 |
+ |
|
26 |
+namespace OCA\SMSRelentless\Migration; |
|
27 |
+ |
|
28 |
+use Closure; |
|
29 |
+use OCP\DB\Types; |
|
30 |
+use OCP\DB\ISchemaWrapper; |
|
31 |
+use OCP\IDBConnection; |
|
32 |
+use OCP\Migration\IOutput; |
|
33 |
+use OCP\Migration\SimpleMigrationStep; |
|
34 |
+ |
|
35 |
+ |
|
36 |
+class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
+ |
|
38 |
+ /** @var IDBConnection */ |
|
39 |
+ private $connection; |
|
40 |
+ |
|
41 |
+ /** |
|
42 |
+ * @param IDBConnection $connection |
|
43 |
+ */ |
|
44 |
+ public function __construct(IDBConnection $connection) { |
|
45 |
+ $this->connection = $connection; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ /** |
|
49 |
+ * @param IOutput $output |
|
50 |
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
+ * @param array $options |
|
52 |
+ * @return null|ISchemaWrapper |
|
53 |
+ */ |
|
54 |
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
+ /** @var ISchemaWrapper $schema */ |
|
56 |
+ $schema = $schemaClosure(); |
|
57 |
+ |
|
58 |
+ if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
+ $table = $schema->createTable('sms_relent_settings'); |
|
60 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
61 |
+ 'autoincrement' => true, |
|
62 |
+ 'notnull' => true, |
|
63 |
+ 'length' => 11, |
|
64 |
+ 'unsigned' => true, |
|
65 |
+ ]); |
|
66 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
67 |
+ 'notnull' => true, |
|
68 |
+ 'length' => 128, |
|
69 |
+ ]); |
|
70 |
+ $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
+ 'notnull' => true, |
|
72 |
+ 'length' => 512, |
|
73 |
+ ]); |
|
74 |
+ $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
+ 'notnull' => true, |
|
76 |
+ 'length' => 512, |
|
77 |
+ ]); |
|
78 |
+ $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
+ 'notnull' => true, |
|
80 |
+ 'length' => 512, |
|
81 |
+ ]); |
|
82 |
+ $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
+ 'notnull' => true, |
|
84 |
+ 'length' => 512, |
|
85 |
+ ]); |
|
86 |
+ $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
+ 'notnull' => true, |
|
88 |
+ 'length' => 512, |
|
89 |
+ ]); |
|
90 |
+ $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
+ 'notnull' => true, |
|
92 |
+ 'length' => 512, |
|
93 |
+ ]); |
|
94 |
+ $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
+ 'notnull' => true, |
|
96 |
+ 'length' => 512, |
|
97 |
+ ]); |
|
98 |
+ $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
+ 'notnull' => true, |
|
100 |
+ 'length' => 512, |
|
101 |
+ ]); |
|
102 |
+ $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
+ 'notnull' => true, |
|
104 |
+ 'length' => 512, |
|
105 |
+ ]); |
|
106 |
+ $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
+ 'notnull' => true, |
|
108 |
+ 'length' => 512, |
|
109 |
+ ]); |
|
110 |
+ $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
+ 'notnull' => true, |
|
112 |
+ 'length' => 512, |
|
113 |
+ ]); |
|
114 |
+ $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
+ 'notnull' => true, |
|
116 |
+ 'length' => 512, |
|
117 |
+ ]); |
|
118 |
+ $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
+ 'notnull' => true, |
|
120 |
+ 'length' => 512, |
|
121 |
+ ]); |
|
122 |
+ $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
+ 'notnull' => true, |
|
124 |
+ 'length' => 512, |
|
125 |
+ ]); |
|
126 |
+ $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
+ 'notnull' => true, |
|
128 |
+ 'length' => 512, |
|
129 |
+ ]); |
|
130 |
+ $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
+ 'notnull' => true, |
|
132 |
+ 'length' => 512, |
|
133 |
+ ]); |
|
134 |
+ $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
+ 'notnull' => true, |
|
136 |
+ 'length' => 512, |
|
137 |
+ ]); |
|
138 |
+ $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
+ 'notnull' => false, |
|
140 |
+ 'length' => 48, |
|
141 |
+ 'default' => '', |
|
142 |
+ ]); |
|
143 |
+ $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
+ 'notnull' => false, |
|
145 |
+ 'length' => 48, |
|
146 |
+ 'default' => '', |
|
147 |
+ ]); |
|
148 |
+ $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
+ 'notnull' => false, |
|
150 |
+ 'length' => 48, |
|
151 |
+ 'default' => '', |
|
152 |
+ ]); |
|
153 |
+ $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
+ 'notnull' => false, |
|
155 |
+ 'length' => 48, |
|
156 |
+ 'default' => '', |
|
157 |
+ ]); |
|
158 |
+ $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
+ 'notnull' => false, |
|
160 |
+ 'length' => 11, |
|
161 |
+ 'unsigned' => true, |
|
162 |
+ ]); |
|
163 |
+ $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
+ 'notnull' => false, |
|
165 |
+ 'length' => 1, |
|
166 |
+ ]); |
|
167 |
+ $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
+ 'notnull' => false, |
|
169 |
+ 'length' => 512, |
|
170 |
+ 'default' => '', |
|
171 |
+ ]); |
|
172 |
+ $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
+ 'notnull' => false, |
|
174 |
+ 'length' => 1, |
|
175 |
+ ]); |
|
176 |
+ $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
+ 'notnull' => false, |
|
178 |
+ 'length' => 1, |
|
179 |
+ ]); |
|
180 |
+ $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
+ 'notnull' => false, |
|
182 |
+ 'length' => 1, |
|
183 |
+ ]); |
|
184 |
+ $table->setPrimaryKey(['id']); |
|
185 |
+ $table->addUniqueIndex(['id']); |
|
186 |
+ |
|
187 |
+ } |
|
188 |
+ |
|
189 |
+ |
|
190 |
+ if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
+ $table = $schema->createTable('sms_relent_received'); |
|
192 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
193 |
+ 'autoincrement' => true, |
|
194 |
+ 'notnull' => true, |
|
195 |
+ 'length' => 11, |
|
196 |
+ 'unsigned' => true, |
|
197 |
+ ]); |
|
198 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
199 |
+ 'notnull' => true, |
|
200 |
+ 'length' => 64, |
|
201 |
+ ]); |
|
202 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
203 |
+ 'notnull' => true, |
|
204 |
+ 'length' => 512, |
|
205 |
+ ]); |
|
206 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
207 |
+ 'notnull' => true, |
|
208 |
+ ]); |
|
209 |
+ $table->addColumn('from', Types::STRING, [ |
|
210 |
+ 'notnull' => true, |
|
211 |
+ 'length' => 128, |
|
212 |
+ ]); |
|
213 |
+ $table->addColumn('to', Types::STRING, [ |
|
214 |
+ 'notnull' => true, |
|
215 |
+ 'length' => 128, |
|
216 |
+ ]); |
|
217 |
+ $table->addColumn('message', Types::TEXT, [ |
|
218 |
+ 'notnull' => false, |
|
219 |
+ 'default' => '', |
|
220 |
+ ]); |
|
221 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
+ 'notnull' => true, |
|
223 |
+ 'length' => 255, |
|
224 |
+ ]); |
|
225 |
+ $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
+ 'notnull' => false, |
|
227 |
+ 'length' => 1, |
|
228 |
+ ]); |
|
229 |
+ $table->setPrimaryKey(['id']); |
|
230 |
+ $table->addUniqueIndex(['id']); |
|
231 |
+ |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ |
|
235 |
+ if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
+ $table = $schema->createTable('sms_relent_sent'); |
|
237 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
238 |
+ 'autoincrement' => true, |
|
239 |
+ 'notnull' => true, |
|
240 |
+ 'length' => 11, |
|
241 |
+ 'unsigned' => true, |
|
242 |
+ ]); |
|
243 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
244 |
+ 'notnull' => true, |
|
245 |
+ 'length' => 64, |
|
246 |
+ ]); |
|
247 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
248 |
+ 'notnull' => true, |
|
249 |
+ 'length' => 512, |
|
250 |
+ ]); |
|
251 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
252 |
+ 'notnull' => true, |
|
253 |
+ ]); |
|
254 |
+ $table->addColumn('from', Types::STRING, [ |
|
255 |
+ 'notnull' => true, |
|
256 |
+ 'length' => 128, |
|
257 |
+ ]); |
|
258 |
+ $table->addColumn('to', Types::STRING, [ |
|
259 |
+ 'notnull' => true, |
|
260 |
+ 'length' => 128, |
|
261 |
+ ]); |
|
262 |
+ $table->addColumn('network ', Types::STRING, [ |
|
263 |
+ 'notnull' => false, |
|
264 |
+ 'length' => 64, |
|
265 |
+ 'default' => '', |
|
266 |
+ ]); |
|
267 |
+ $table->addColumn('price', Types::STRING, [ |
|
268 |
+ 'notnull' => false, |
|
269 |
+ 'length' => 64, |
|
270 |
+ 'default' => '', |
|
271 |
+ ]); |
|
272 |
+ $table->addColumn('status', Types::STRING, [ |
|
273 |
+ 'notnull' => false, |
|
274 |
+ 'length' => 512, |
|
275 |
+ 'default' => '', |
|
276 |
+ ]); |
|
277 |
+ $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
+ 'notnull' => false, |
|
279 |
+ 'length' => 64, |
|
280 |
+ 'default' => '', |
|
281 |
+ ]); |
|
282 |
+ $table->addColumn('message', Types::TEXT, [ |
|
283 |
+ 'notnull' => false, |
|
284 |
+ 'default' => '', |
|
285 |
+ ]); |
|
286 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
+ 'notnull' => true, |
|
288 |
+ 'length' => 255, |
|
289 |
+ ]); |
|
290 |
+ $table->setPrimaryKey(['id']); |
|
291 |
+ $table->addUniqueIndex(['id']); |
|
292 |
+ |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+ |
|
296 |
+ if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
+ $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
299 |
+ 'autoincrement' => true, |
|
300 |
+ 'notnull' => true, |
|
301 |
+ 'length' => 11, |
|
302 |
+ 'unsigned' => true, |
|
303 |
+ ]); |
|
304 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
305 |
+ 'notnull' => true, |
|
306 |
+ 'length' => 128, |
|
307 |
+ ]); |
|
308 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
+ 'notnull' => true, |
|
310 |
+ 'length' => 255, |
|
311 |
+ ]); |
|
312 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
+ 'notnull' => true, |
|
314 |
+ 'length' => 128, |
|
315 |
+ ]); |
|
316 |
+ $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
+ 'notnull' => false, |
|
318 |
+ 'length' => 64, |
|
319 |
+ 'default' => '', |
|
320 |
+ ]); |
|
321 |
+ $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
+ 'notnull' => false, |
|
323 |
+ 'length' => 8, |
|
324 |
+ 'default' => '', |
|
325 |
+ ]); |
|
326 |
+ $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
+ 'notnull' => false, |
|
328 |
+ 'length' => 8, |
|
329 |
+ 'default' => '', |
|
330 |
+ ]); |
|
331 |
+ $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
+ 'notnull' => false, |
|
333 |
+ ]); |
|
334 |
+ $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
+ 'notnull' => false, |
|
336 |
+ ]); |
|
337 |
+ $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
+ 'notnull' => false, |
|
339 |
+ 'default' => '', |
|
340 |
+ ]); |
|
341 |
+ $table->setPrimaryKey(['id']); |
|
342 |
+ $table->addUniqueIndex(['id']); |
|
343 |
+ |
|
344 |
+ } |
|
345 |
+ |
|
346 |
+ |
|
347 |
+ if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
+ $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
350 |
+ 'autoincrement' => true, |
|
351 |
+ 'notnull' => true, |
|
352 |
+ 'length' => 11, |
|
353 |
+ 'unsigned' => true, |
|
354 |
+ ]); |
|
355 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
356 |
+ 'notnull' => true, |
|
357 |
+ 'length' => 128, |
|
358 |
+ ]); |
|
359 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
+ 'notnull' => true, |
|
361 |
+ 'length' => 255, |
|
362 |
+ ]); |
|
363 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
+ 'notnull' => true, |
|
365 |
+ 'length' => 128, |
|
366 |
+ ]); |
|
367 |
+ $table->addColumn('groups', Types::STRING, [ |
|
368 |
+ 'notnull' => true, |
|
369 |
+ 'length' => 2048, |
|
370 |
+ ]); |
|
371 |
+ $table->addColumn('users', Types::STRING, [ |
|
372 |
+ 'notnull' => true, |
|
373 |
+ 'length' => 2048, |
|
374 |
+ ]); |
|
375 |
+ $table->setPrimaryKey(['id']); |
|
376 |
+ $table->addUniqueIndex(['id']); |
|
377 |
+ |
|
378 |
+ } |
|
379 |
+ |
|
380 |
+ return $schema; |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
+ |
|
385 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade |
|
386 |
+ $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`'); |
|
387 |
+ $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
+ |
|
389 |
+ $recdatanmbrs = []; |
|
390 |
+ while ($rowfetched = $getrecfromnbres->fetch()) { |
|
391 |
+ $recdatanmbrs[] = $rowfetched['from']; |
|
392 |
+ } |
|
393 |
+ $getrecfromnbres->closeCursor(); |
|
394 |
+ |
|
395 |
+ if ($recdatanmbrs) { |
|
396 |
+ |
|
397 |
+ $recnmbrs = array_values(array_unique($recdatanmbrs)); |
|
398 |
+ |
|
399 |
+ $phoneDisplayPairs = []; |
|
400 |
+ foreach ($recnmbrs as $rckey => $rcvalue) { |
|
401 |
+ |
|
402 |
+ $rcvalueprc = '%' . $rcvalue; |
|
403 |
+ $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
404 |
+ $getacdatares = $getacdata->execute(['phone', $rcvalueprc]); |
|
405 |
+ |
|
406 |
+ $acdatausers = []; |
|
407 |
+ while ($acusrfetched = $getacdatares->fetch()) { |
|
408 |
+ $acdatausers[] = $acusrfetched['uid']; |
|
409 |
+ } |
|
410 |
+ $getacdatares->closeCursor(); |
|
411 |
+ |
|
412 |
+ |
|
413 |
+ if ($acdatausers) { |
|
414 |
+ |
|
415 |
+ $acdatausrdn = []; |
|
416 |
+ foreach ($acdatausers as $dnkey => $dnvalue) { |
|
417 |
+ |
|
418 |
+ $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
419 |
+ $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
420 |
+ |
|
421 |
+ while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
422 |
+ $acdatausrdn[] = $acusrdnfetched['value']; |
|
423 |
+ } |
|
424 |
+ $getacdatadnres->closeCursor(); |
|
425 |
+ } |
|
426 |
+ |
|
427 |
+ if ($acdatausrdn) { |
|
428 |
+ |
|
429 |
+ if (count($acdatausrdn) == 1) { |
|
430 |
+ |
|
431 |
+ $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1]; |
|
432 |
+ |
|
433 |
+ } elseif (count($acdatausrdn) > 1) { |
|
434 |
+ |
|
435 |
+ $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1]; |
|
436 |
+ } |
|
437 |
+ |
|
438 |
+ } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
439 |
+ |
|
440 |
+ } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
441 |
+ } |
|
442 |
+ |
|
443 |
+ foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) { |
|
444 |
+ |
|
445 |
+ if (is_array($pdpvalue)) { |
|
446 |
+ $pdpkeyprc = '%' . $pdpkey; |
|
447 |
+ $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?'); |
|
448 |
+ $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]); |
|
449 |
+ $updaterecmsres->closeCursor(); |
|
450 |
+ } |
|
451 |
+ } |
|
452 |
+ } |
|
453 |
+ |
|
454 |
+ |
|
455 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade |
|
456 |
+ $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`'); |
|
457 |
+ $getsentfromnbres = $getsentfromnb->execute(); |
|
458 |
+ |
|
459 |
+ $sentdatanmbrs = []; |
|
460 |
+ while ($rowfetchedst = $getsentfromnbres->fetch()) { |
|
461 |
+ |
|
462 |
+ $sentdatanmbrspre = $rowfetchedst['from']; |
|
463 |
+ $sentdatanmbrsarr = explode("+", $sentdatanmbrspre); |
|
464 |
+ if (count($sentdatanmbrsarr) > 1) { |
|
465 |
+ $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1]; |
|
466 |
+ } else { |
|
467 |
+ $sentdatanmbrs[] = $sentdatanmbrsarr[0]; |
|
468 |
+ } |
|
469 |
+ } |
|
470 |
+ $getsentfromnbres->closeCursor(); |
|
471 |
+ |
|
472 |
+ if ($sentdatanmbrs) { |
|
473 |
+ |
|
474 |
+ $sentnmbrs = array_values(array_unique($sentdatanmbrs)); |
|
475 |
+ |
|
476 |
+ $phoneDisplayPairsst = []; |
|
477 |
+ foreach ($sentnmbrs as $stkey => $stvalue) { |
|
478 |
+ |
|
479 |
+ $stvalueprc = '%' . $stvalue; |
|
480 |
+ $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
481 |
+ $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]); |
|
482 |
+ |
|
483 |
+ $acdatausersst = []; |
|
484 |
+ while ($acusrstfetched = $getacdatastres->fetch()) { |
|
485 |
+ $acdatausersst[] = $acusrstfetched['uid']; |
|
486 |
+ } |
|
487 |
+ $getacdatastres->closeCursor(); |
|
488 |
+ |
|
489 |
+ if ($acdatausersst) { |
|
490 |
+ |
|
491 |
+ $acdatausrdnst = []; |
|
492 |
+ foreach ($acdatausersst as $dnstkey => $dnstvalue) { |
|
493 |
+ |
|
494 |
+ $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
495 |
+ $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']); |
|
496 |
+ |
|
497 |
+ while ($acusrdnstfetched = $getacdatadnstres->fetch()) { |
|
498 |
+ $acdatausrdnst[] = $acusrdnstfetched['value']; |
|
499 |
+ } |
|
500 |
+ $getacdatadnstres->closeCursor(); |
|
501 |
+ } |
|
502 |
+ |
|
503 |
+ if ($acdatausrdnst) { |
|
504 |
+ |
|
505 |
+ if (count($acdatausrdnst) == 1) { |
|
506 |
+ |
|
507 |
+ $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]]; |
|
508 |
+ |
|
509 |
+ } elseif (count($acdatausrdnst) > 1) { |
|
510 |
+ |
|
511 |
+ $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)]; |
|
512 |
+ } |
|
513 |
+ |
|
514 |
+ } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
515 |
+ |
|
516 |
+ } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
517 |
+ } |
|
518 |
+ |
|
519 |
+ foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) { |
|
520 |
+ |
|
521 |
+ if (is_array($pstvalue)) { |
|
522 |
+ $contfield = "%" . $pstkey; |
|
523 |
+ $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?'); |
|
524 |
+ $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]); |
|
525 |
+ $updatesentmsres->closeCursor(); |
|
526 |
+ } |
|
527 |
+ } |
|
528 |
+ } |
|
529 |
+ |
|
530 |
+ return null; |
|
531 |
+ } |
|
532 |
+ |
|
533 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,533 +0,0 @@ |
1 |
-<?php |
|
2 |
-/** |
|
3 |
- * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
- * |
|
5 |
- * @author Double Bastion LLC |
|
6 |
- * |
|
7 |
- * @license GNU AGPL version 3 or any later version |
|
8 |
- * |
|
9 |
- * This program is free software; you can redistribute it and/or |
|
10 |
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
- * License as published by the Free Software Foundation; either |
|
12 |
- * version 3 of the License, or any later version. |
|
13 |
- * |
|
14 |
- * This program is distributed in the hope that it will be useful, |
|
15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU Affero General Public |
|
20 |
- * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
- * |
|
22 |
- */ |
|
23 |
- |
|
24 |
-declare(strict_types=1); |
|
25 |
- |
|
26 |
-namespace OCA\SMSRelentless\Migration; |
|
27 |
- |
|
28 |
-use Closure; |
|
29 |
-use OCP\DB\Types; |
|
30 |
-use OCP\DB\ISchemaWrapper; |
|
31 |
-use OCP\IDBConnection; |
|
32 |
-use OCP\Migration\IOutput; |
|
33 |
-use OCP\Migration\SimpleMigrationStep; |
|
34 |
- |
|
35 |
- |
|
36 |
-class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
- |
|
38 |
- /** @var IDBConnection */ |
|
39 |
- private $connection; |
|
40 |
- |
|
41 |
- /** |
|
42 |
- * @param IDBConnection $connection |
|
43 |
- */ |
|
44 |
- public function __construct(IDBConnection $connection) { |
|
45 |
- $this->connection = $connection; |
|
46 |
- } |
|
47 |
- |
|
48 |
- /** |
|
49 |
- * @param IOutput $output |
|
50 |
- * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
- * @param array $options |
|
52 |
- * @return null|ISchemaWrapper |
|
53 |
- */ |
|
54 |
- public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
- /** @var ISchemaWrapper $schema */ |
|
56 |
- $schema = $schemaClosure(); |
|
57 |
- |
|
58 |
- if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
- $table = $schema->createTable('sms_relent_settings'); |
|
60 |
- $table->addColumn('id', Types::BIGINT, [ |
|
61 |
- 'autoincrement' => true, |
|
62 |
- 'notnull' => true, |
|
63 |
- 'length' => 11, |
|
64 |
- 'unsigned' => true, |
|
65 |
- ]); |
|
66 |
- $table->addColumn('user_id', Types::STRING, [ |
|
67 |
- 'notnull' => true, |
|
68 |
- 'length' => 128, |
|
69 |
- ]); |
|
70 |
- $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
- 'notnull' => true, |
|
72 |
- 'length' => 512, |
|
73 |
- ]); |
|
74 |
- $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
- 'notnull' => true, |
|
76 |
- 'length' => 512, |
|
77 |
- ]); |
|
78 |
- $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
- 'notnull' => true, |
|
80 |
- 'length' => 512, |
|
81 |
- ]); |
|
82 |
- $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
- 'notnull' => true, |
|
84 |
- 'length' => 512, |
|
85 |
- ]); |
|
86 |
- $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
- 'notnull' => true, |
|
88 |
- 'length' => 512, |
|
89 |
- ]); |
|
90 |
- $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
- 'notnull' => true, |
|
92 |
- 'length' => 512, |
|
93 |
- ]); |
|
94 |
- $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
- 'notnull' => true, |
|
96 |
- 'length' => 512, |
|
97 |
- ]); |
|
98 |
- $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
- 'notnull' => true, |
|
100 |
- 'length' => 512, |
|
101 |
- ]); |
|
102 |
- $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
- 'notnull' => true, |
|
104 |
- 'length' => 512, |
|
105 |
- ]); |
|
106 |
- $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
- 'notnull' => true, |
|
108 |
- 'length' => 512, |
|
109 |
- ]); |
|
110 |
- $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
- 'notnull' => true, |
|
112 |
- 'length' => 512, |
|
113 |
- ]); |
|
114 |
- $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
- 'notnull' => true, |
|
116 |
- 'length' => 512, |
|
117 |
- ]); |
|
118 |
- $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
- 'notnull' => true, |
|
120 |
- 'length' => 512, |
|
121 |
- ]); |
|
122 |
- $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
- 'notnull' => true, |
|
124 |
- 'length' => 512, |
|
125 |
- ]); |
|
126 |
- $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
- 'notnull' => true, |
|
128 |
- 'length' => 512, |
|
129 |
- ]); |
|
130 |
- $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
- 'notnull' => true, |
|
132 |
- 'length' => 512, |
|
133 |
- ]); |
|
134 |
- $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
- 'notnull' => true, |
|
136 |
- 'length' => 512, |
|
137 |
- ]); |
|
138 |
- $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
- 'notnull' => false, |
|
140 |
- 'length' => 48, |
|
141 |
- 'default' => '', |
|
142 |
- ]); |
|
143 |
- $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
- 'notnull' => false, |
|
145 |
- 'length' => 48, |
|
146 |
- 'default' => '', |
|
147 |
- ]); |
|
148 |
- $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
- 'notnull' => false, |
|
150 |
- 'length' => 48, |
|
151 |
- 'default' => '', |
|
152 |
- ]); |
|
153 |
- $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
- 'notnull' => false, |
|
155 |
- 'length' => 48, |
|
156 |
- 'default' => '', |
|
157 |
- ]); |
|
158 |
- $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
- 'notnull' => false, |
|
160 |
- 'length' => 11, |
|
161 |
- 'unsigned' => true, |
|
162 |
- ]); |
|
163 |
- $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
- 'notnull' => false, |
|
165 |
- 'length' => 1, |
|
166 |
- ]); |
|
167 |
- $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
- 'notnull' => false, |
|
169 |
- 'length' => 512, |
|
170 |
- 'default' => '', |
|
171 |
- ]); |
|
172 |
- $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
- 'notnull' => false, |
|
174 |
- 'length' => 1, |
|
175 |
- ]); |
|
176 |
- $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
- 'notnull' => false, |
|
178 |
- 'length' => 1, |
|
179 |
- ]); |
|
180 |
- $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
- 'notnull' => false, |
|
182 |
- 'length' => 1, |
|
183 |
- ]); |
|
184 |
- $table->setPrimaryKey(['id']); |
|
185 |
- $table->addUniqueIndex(['id']); |
|
186 |
- |
|
187 |
- } |
|
188 |
- |
|
189 |
- |
|
190 |
- if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
- $table = $schema->createTable('sms_relent_received'); |
|
192 |
- $table->addColumn('id', Types::BIGINT, [ |
|
193 |
- 'autoincrement' => true, |
|
194 |
- 'notnull' => true, |
|
195 |
- 'length' => 11, |
|
196 |
- 'unsigned' => true, |
|
197 |
- ]); |
|
198 |
- $table->addColumn('user_id', Types::STRING, [ |
|
199 |
- 'notnull' => true, |
|
200 |
- 'length' => 64, |
|
201 |
- ]); |
|
202 |
- $table->addColumn('message_id', Types::STRING, [ |
|
203 |
- 'notnull' => true, |
|
204 |
- 'length' => 512, |
|
205 |
- ]); |
|
206 |
- $table->addColumn('date', Types::DATETIME, [ |
|
207 |
- 'notnull' => true, |
|
208 |
- ]); |
|
209 |
- $table->addColumn('from', Types::STRING, [ |
|
210 |
- 'notnull' => true, |
|
211 |
- 'length' => 128, |
|
212 |
- ]); |
|
213 |
- $table->addColumn('to', Types::STRING, [ |
|
214 |
- 'notnull' => true, |
|
215 |
- 'length' => 128, |
|
216 |
- ]); |
|
217 |
- $table->addColumn('message', Types::TEXT, [ |
|
218 |
- 'notnull' => false, |
|
219 |
- 'default' => '', |
|
220 |
- ]); |
|
221 |
- $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
- 'notnull' => true, |
|
223 |
- 'length' => 255, |
|
224 |
- ]); |
|
225 |
- $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
- 'notnull' => false, |
|
227 |
- 'length' => 1, |
|
228 |
- ]); |
|
229 |
- $table->setPrimaryKey(['id']); |
|
230 |
- $table->addUniqueIndex(['id']); |
|
231 |
- |
|
232 |
- } |
|
233 |
- |
|
234 |
- |
|
235 |
- if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
- $table = $schema->createTable('sms_relent_sent'); |
|
237 |
- $table->addColumn('id', Types::BIGINT, [ |
|
238 |
- 'autoincrement' => true, |
|
239 |
- 'notnull' => true, |
|
240 |
- 'length' => 11, |
|
241 |
- 'unsigned' => true, |
|
242 |
- ]); |
|
243 |
- $table->addColumn('user_id', Types::STRING, [ |
|
244 |
- 'notnull' => true, |
|
245 |
- 'length' => 64, |
|
246 |
- ]); |
|
247 |
- $table->addColumn('message_id', Types::STRING, [ |
|
248 |
- 'notnull' => true, |
|
249 |
- 'length' => 512, |
|
250 |
- ]); |
|
251 |
- $table->addColumn('date', Types::DATETIME, [ |
|
252 |
- 'notnull' => true, |
|
253 |
- ]); |
|
254 |
- $table->addColumn('from', Types::STRING, [ |
|
255 |
- 'notnull' => true, |
|
256 |
- 'length' => 128, |
|
257 |
- ]); |
|
258 |
- $table->addColumn('to', Types::STRING, [ |
|
259 |
- 'notnull' => true, |
|
260 |
- 'length' => 128, |
|
261 |
- ]); |
|
262 |
- $table->addColumn('network ', Types::STRING, [ |
|
263 |
- 'notnull' => false, |
|
264 |
- 'length' => 64, |
|
265 |
- 'default' => '', |
|
266 |
- ]); |
|
267 |
- $table->addColumn('price', Types::STRING, [ |
|
268 |
- 'notnull' => false, |
|
269 |
- 'length' => 64, |
|
270 |
- 'default' => '', |
|
271 |
- ]); |
|
272 |
- $table->addColumn('status', Types::STRING, [ |
|
273 |
- 'notnull' => false, |
|
274 |
- 'length' => 512, |
|
275 |
- 'default' => '', |
|
276 |
- ]); |
|
277 |
- $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
- 'notnull' => false, |
|
279 |
- 'length' => 64, |
|
280 |
- 'default' => '', |
|
281 |
- ]); |
|
282 |
- $table->addColumn('message', Types::TEXT, [ |
|
283 |
- 'notnull' => false, |
|
284 |
- 'default' => '', |
|
285 |
- ]); |
|
286 |
- $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
- 'notnull' => true, |
|
288 |
- 'length' => 255, |
|
289 |
- ]); |
|
290 |
- $table->setPrimaryKey(['id']); |
|
291 |
- $table->addUniqueIndex(['id']); |
|
292 |
- |
|
293 |
- } |
|
294 |
- |
|
295 |
- |
|
296 |
- if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
- $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
- $table->addColumn('id', Types::BIGINT, [ |
|
299 |
- 'autoincrement' => true, |
|
300 |
- 'notnull' => true, |
|
301 |
- 'length' => 11, |
|
302 |
- 'unsigned' => true, |
|
303 |
- ]); |
|
304 |
- $table->addColumn('user_id', Types::STRING, [ |
|
305 |
- 'notnull' => true, |
|
306 |
- 'length' => 128, |
|
307 |
- ]); |
|
308 |
- $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
- 'notnull' => true, |
|
310 |
- 'length' => 255, |
|
311 |
- ]); |
|
312 |
- $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
- 'notnull' => true, |
|
314 |
- 'length' => 128, |
|
315 |
- ]); |
|
316 |
- $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
- 'notnull' => false, |
|
318 |
- 'length' => 64, |
|
319 |
- 'default' => '', |
|
320 |
- ]); |
|
321 |
- $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
- 'notnull' => false, |
|
323 |
- 'length' => 8, |
|
324 |
- 'default' => '', |
|
325 |
- ]); |
|
326 |
- $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
- 'notnull' => false, |
|
328 |
- 'length' => 8, |
|
329 |
- 'default' => '', |
|
330 |
- ]); |
|
331 |
- $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
- 'notnull' => false, |
|
333 |
- ]); |
|
334 |
- $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
- 'notnull' => false, |
|
336 |
- ]); |
|
337 |
- $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
- 'notnull' => false, |
|
339 |
- 'default' => '', |
|
340 |
- ]); |
|
341 |
- $table->setPrimaryKey(['id']); |
|
342 |
- $table->addUniqueIndex(['id']); |
|
343 |
- |
|
344 |
- } |
|
345 |
- |
|
346 |
- |
|
347 |
- if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
- $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
- $table->addColumn('id', Types::BIGINT, [ |
|
350 |
- 'autoincrement' => true, |
|
351 |
- 'notnull' => true, |
|
352 |
- 'length' => 11, |
|
353 |
- 'unsigned' => true, |
|
354 |
- ]); |
|
355 |
- $table->addColumn('user_id', Types::STRING, [ |
|
356 |
- 'notnull' => true, |
|
357 |
- 'length' => 128, |
|
358 |
- ]); |
|
359 |
- $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
- 'notnull' => true, |
|
361 |
- 'length' => 255, |
|
362 |
- ]); |
|
363 |
- $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
- 'notnull' => true, |
|
365 |
- 'length' => 128, |
|
366 |
- ]); |
|
367 |
- $table->addColumn('groups', Types::STRING, [ |
|
368 |
- 'notnull' => true, |
|
369 |
- 'length' => 2048, |
|
370 |
- ]); |
|
371 |
- $table->addColumn('users', Types::STRING, [ |
|
372 |
- 'notnull' => true, |
|
373 |
- 'length' => 2048, |
|
374 |
- ]); |
|
375 |
- $table->setPrimaryKey(['id']); |
|
376 |
- $table->addUniqueIndex(['id']); |
|
377 |
- |
|
378 |
- } |
|
379 |
- |
|
380 |
- return $schema; |
|
381 |
- } |
|
382 |
- |
|
383 |
- public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
- |
|
385 |
- // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before |
|
386 |
- $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`'); |
|
387 |
- $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
- |
|
389 |
- $recdatanmbrs = []; |
|
390 |
- while ($rowfetched = $getrecfromnbres->fetch()) { |
|
391 |
- $recdatanmbrs[] = $rowfetched['from']; |
|
392 |
- } |
|
393 |
- $getrecfromnbres->closeCursor(); |
|
394 |
- |
|
395 |
- if ($recdatanmbrs) { |
|
396 |
- |
|
397 |
- $recnmbrs = array_values(array_unique($recdatanmbrs)); |
|
398 |
- |
|
399 |
- $phoneDisplayPairs = []; |
|
400 |
- foreach ($recnmbrs as $rckey => $rcvalue) { |
|
401 |
- |
|
402 |
- $rcvalueprc = '%' . $rcvalue; |
|
403 |
- $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
404 |
- $getacdatares = $getacdata->execute(['phone', $rcvalueprc]); |
|
405 |
- |
|
406 |
- $acdatausers = []; |
|
407 |
- while ($acusrfetched = $getacdatares->fetch()) { |
|
408 |
- $acdatausers[] = $acusrfetched['uid']; |
|
409 |
- } |
|
410 |
- $getacdatares->closeCursor(); |
|
411 |
- |
|
412 |
- |
|
413 |
- if ($acdatausers) { |
|
414 |
- |
|
415 |
- $acdatausrdn = []; |
|
416 |
- foreach ($acdatausers as $dnkey => $dnvalue) { |
|
417 |
- |
|
418 |
- $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
419 |
- $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
420 |
- |
|
421 |
- while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
422 |
- $acdatausrdn[] = $acusrdnfetched['value']; |
|
423 |
- } |
|
424 |
- $getacdatadnres->closeCursor(); |
|
425 |
- } |
|
426 |
- |
|
427 |
- if ($acdatausrdn) { |
|
428 |
- |
|
429 |
- if (count($acdatausrdn) == 1) { |
|
430 |
- |
|
431 |
- $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1]; |
|
432 |
- |
|
433 |
- } elseif (count($acdatausrdn) > 1) { |
|
434 |
- |
|
435 |
- $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1]; |
|
436 |
- } |
|
437 |
- |
|
438 |
- } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
439 |
- |
|
440 |
- } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
441 |
- } |
|
442 |
- |
|
443 |
- foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) { |
|
444 |
- |
|
445 |
- if (is_array($pdpvalue)) { |
|
446 |
- $pdpkeyprc = '%' . $pdpkey; |
|
447 |
- $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?'); |
|
448 |
- $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]); |
|
449 |
- $updaterecmsres->closeCursor(); |
|
450 |
- } |
|
451 |
- } |
|
452 |
- } |
|
453 |
- |
|
454 |
- |
|
455 |
- // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before |
|
456 |
- $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`'); |
|
457 |
- $getsentfromnbres = $getsentfromnb->execute(); |
|
458 |
- |
|
459 |
- $sentdatanmbrs = []; |
|
460 |
- while ($rowfetchedst = $getsentfromnbres->fetch()) { |
|
461 |
- |
|
462 |
- $sentdatanmbrspre = $rowfetchedst['from']; |
|
463 |
- $sentdatanmbrsarr = explode("+", $sentdatanmbrspre); |
|
464 |
- if (count($sentdatanmbrsarr) > 1) { |
|
465 |
- $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1]; |
|
466 |
- } else { |
|
467 |
- $sentdatanmbrs[] = $sentdatanmbrsarr[0]; |
|
468 |
- } |
|
469 |
- } |
|
470 |
- $getsentfromnbres->closeCursor(); |
|
471 |
- |
|
472 |
- if ($sentdatanmbrs) { |
|
473 |
- |
|
474 |
- $sentnmbrs = array_values(array_unique($sentdatanmbrs)); |
|
475 |
- |
|
476 |
- $phoneDisplayPairsst = []; |
|
477 |
- foreach ($sentnmbrs as $stkey => $stvalue) { |
|
478 |
- |
|
479 |
- $stvalueprc = '%' . $stvalue; |
|
480 |
- $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
481 |
- $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]); |
|
482 |
- |
|
483 |
- $acdatausersst = []; |
|
484 |
- while ($acusrstfetched = $getacdatastres->fetch()) { |
|
485 |
- $acdatausersst[] = $acusrstfetched['uid']; |
|
486 |
- } |
|
487 |
- $getacdatastres->closeCursor(); |
|
488 |
- |
|
489 |
- if ($acdatausersst) { |
|
490 |
- |
|
491 |
- $acdatausrdnst = []; |
|
492 |
- foreach ($acdatausersst as $dnstkey => $dnstvalue) { |
|
493 |
- |
|
494 |
- $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
495 |
- $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']); |
|
496 |
- |
|
497 |
- while ($acusrdnstfetched = $getacdatadnstres->fetch()) { |
|
498 |
- $acdatausrdnst[] = $acusrdnstfetched['value']; |
|
499 |
- } |
|
500 |
- $getacdatadnstres->closeCursor(); |
|
501 |
- } |
|
502 |
- |
|
503 |
- if ($acdatausrdnst) { |
|
504 |
- |
|
505 |
- if (count($acdatausrdnst) == 1) { |
|
506 |
- |
|
507 |
- $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]]; |
|
508 |
- |
|
509 |
- } elseif (count($acdatausrdnst) > 1) { |
|
510 |
- |
|
511 |
- $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)]; |
|
512 |
- } |
|
513 |
- |
|
514 |
- } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
515 |
- |
|
516 |
- } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
517 |
- } |
|
518 |
- |
|
519 |
- foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) { |
|
520 |
- |
|
521 |
- if (is_array($pstvalue)) { |
|
522 |
- $contfield = "%" . $pstkey; |
|
523 |
- $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?'); |
|
524 |
- $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]); |
|
525 |
- $updatesentmsres->closeCursor(); |
|
526 |
- } |
|
527 |
- } |
|
528 |
- } |
|
529 |
- |
|
530 |
- return null; |
|
531 |
- } |
|
532 |
- |
|
533 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,533 @@ |
1 |
+<?php |
|
2 |
+/** |
|
3 |
+ * @copyright 2021 Double Bastion LLC <www.doublebastion.com> |
|
4 |
+ * |
|
5 |
+ * @author Double Bastion LLC |
|
6 |
+ * |
|
7 |
+ * @license GNU AGPL version 3 or any later version |
|
8 |
+ * |
|
9 |
+ * This program is free software; you can redistribute it and/or |
|
10 |
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
11 |
+ * License as published by the Free Software Foundation; either |
|
12 |
+ * version 3 of the License, or any later version. |
|
13 |
+ * |
|
14 |
+ * This program is distributed in the hope that it will be useful, |
|
15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
|
18 |
+ * |
|
19 |
+ * You should have received a copy of the GNU Affero General Public |
|
20 |
+ * License along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
+ * |
|
22 |
+ */ |
|
23 |
+ |
|
24 |
+declare(strict_types=1); |
|
25 |
+ |
|
26 |
+namespace OCA\SMSRelentless\Migration; |
|
27 |
+ |
|
28 |
+use Closure; |
|
29 |
+use OCP\DB\Types; |
|
30 |
+use OCP\DB\ISchemaWrapper; |
|
31 |
+use OCP\IDBConnection; |
|
32 |
+use OCP\Migration\IOutput; |
|
33 |
+use OCP\Migration\SimpleMigrationStep; |
|
34 |
+ |
|
35 |
+ |
|
36 |
+class Version118Date20230509194216 extends SimpleMigrationStep { |
|
37 |
+ |
|
38 |
+ /** @var IDBConnection */ |
|
39 |
+ private $connection; |
|
40 |
+ |
|
41 |
+ /** |
|
42 |
+ * @param IDBConnection $connection |
|
43 |
+ */ |
|
44 |
+ public function __construct(IDBConnection $connection) { |
|
45 |
+ $this->connection = $connection; |
|
46 |
+ } |
|
47 |
+ |
|
48 |
+ /** |
|
49 |
+ * @param IOutput $output |
|
50 |
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
51 |
+ * @param array $options |
|
52 |
+ * @return null|ISchemaWrapper |
|
53 |
+ */ |
|
54 |
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
55 |
+ /** @var ISchemaWrapper $schema */ |
|
56 |
+ $schema = $schemaClosure(); |
|
57 |
+ |
|
58 |
+ if (!$schema->hasTable('sms_relent_settings')) { |
|
59 |
+ $table = $schema->createTable('sms_relent_settings'); |
|
60 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
61 |
+ 'autoincrement' => true, |
|
62 |
+ 'notnull' => true, |
|
63 |
+ 'length' => 11, |
|
64 |
+ 'unsigned' => true, |
|
65 |
+ ]); |
|
66 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
67 |
+ 'notnull' => true, |
|
68 |
+ 'length' => 128, |
|
69 |
+ ]); |
|
70 |
+ $table->addColumn('telapi_key', Types::STRING, [ |
|
71 |
+ 'notnull' => true, |
|
72 |
+ 'length' => 512, |
|
73 |
+ ]); |
|
74 |
+ $table->addColumn('tel_pub_key', Types::STRING, [ |
|
75 |
+ 'notnull' => true, |
|
76 |
+ 'length' => 512, |
|
77 |
+ ]); |
|
78 |
+ $table->addColumn('telapi_url_rec', Types::STRING, [ |
|
79 |
+ 'notnull' => true, |
|
80 |
+ 'length' => 512, |
|
81 |
+ ]); |
|
82 |
+ $table->addColumn('telapi_url', Types::STRING, [ |
|
83 |
+ 'notnull' => true, |
|
84 |
+ 'length' => 512, |
|
85 |
+ ]); |
|
86 |
+ $table->addColumn('messaging_profile_id', Types::STRING, [ |
|
87 |
+ 'notnull' => true, |
|
88 |
+ 'length' => 512, |
|
89 |
+ ]); |
|
90 |
+ $table->addColumn('nexapi_key', Types::STRING, [ |
|
91 |
+ 'notnull' => true, |
|
92 |
+ 'length' => 512, |
|
93 |
+ ]); |
|
94 |
+ $table->addColumn('nexapi_secret', Types::STRING, [ |
|
95 |
+ 'notnull' => true, |
|
96 |
+ 'length' => 512, |
|
97 |
+ ]); |
|
98 |
+ $table->addColumn('nexapi_url_rec', Types::STRING, [ |
|
99 |
+ 'notnull' => true, |
|
100 |
+ 'length' => 512, |
|
101 |
+ ]); |
|
102 |
+ $table->addColumn('nexapi_url', Types::STRING, [ |
|
103 |
+ 'notnull' => true, |
|
104 |
+ 'length' => 512, |
|
105 |
+ ]); |
|
106 |
+ $table->addColumn('twilapi_key', Types::STRING, [ |
|
107 |
+ 'notnull' => true, |
|
108 |
+ 'length' => 512, |
|
109 |
+ ]); |
|
110 |
+ $table->addColumn('twilapi_secret', Types::STRING, [ |
|
111 |
+ 'notnull' => true, |
|
112 |
+ 'length' => 512, |
|
113 |
+ ]); |
|
114 |
+ $table->addColumn('twilapi_url_rec', Types::STRING, [ |
|
115 |
+ 'notnull' => true, |
|
116 |
+ 'length' => 512, |
|
117 |
+ ]); |
|
118 |
+ $table->addColumn('twilapi_url', Types::STRING, [ |
|
119 |
+ 'notnull' => true, |
|
120 |
+ 'length' => 512, |
|
121 |
+ ]); |
|
122 |
+ $table->addColumn('flowapi_key', Types::STRING, [ |
|
123 |
+ 'notnull' => true, |
|
124 |
+ 'length' => 512, |
|
125 |
+ ]); |
|
126 |
+ $table->addColumn('flowapi_secret', Types::STRING, [ |
|
127 |
+ 'notnull' => true, |
|
128 |
+ 'length' => 512, |
|
129 |
+ ]); |
|
130 |
+ $table->addColumn('flowapi_url_rec', Types::STRING, [ |
|
131 |
+ 'notnull' => true, |
|
132 |
+ 'length' => 512, |
|
133 |
+ ]); |
|
134 |
+ $table->addColumn('flowapi_url', Types::STRING, [ |
|
135 |
+ 'notnull' => true, |
|
136 |
+ 'length' => 512, |
|
137 |
+ ]); |
|
138 |
+ $table->addColumn('tel_sender_name', Types::STRING, [ |
|
139 |
+ 'notnull' => false, |
|
140 |
+ 'length' => 48, |
|
141 |
+ 'default' => '', |
|
142 |
+ ]); |
|
143 |
+ $table->addColumn('nex_sender_name', Types::STRING, [ |
|
144 |
+ 'notnull' => false, |
|
145 |
+ 'length' => 48, |
|
146 |
+ 'default' => '', |
|
147 |
+ ]); |
|
148 |
+ $table->addColumn('twil_sender_name', Types::STRING, [ |
|
149 |
+ 'notnull' => false, |
|
150 |
+ 'length' => 48, |
|
151 |
+ 'default' => '', |
|
152 |
+ ]); |
|
153 |
+ $table->addColumn('flow_sender_name', Types::STRING, [ |
|
154 |
+ 'notnull' => false, |
|
155 |
+ 'length' => 48, |
|
156 |
+ 'default' => '', |
|
157 |
+ ]); |
|
158 |
+ $table->addColumn('messagesperpage', Types::INTEGER, [ |
|
159 |
+ 'notnull' => false, |
|
160 |
+ 'length' => 11, |
|
161 |
+ 'unsigned' => true, |
|
162 |
+ ]); |
|
163 |
+ $table->addColumn('get_notify', Types::SMALLINT, [ |
|
164 |
+ 'notnull' => false, |
|
165 |
+ 'length' => 1, |
|
166 |
+ ]); |
|
167 |
+ $table->addColumn('notification_email', Types::STRING, [ |
|
168 |
+ 'notnull' => false, |
|
169 |
+ 'length' => 512, |
|
170 |
+ 'default' => '', |
|
171 |
+ ]); |
|
172 |
+ $table->addColumn('getsmsinemail', Types::SMALLINT, [ |
|
173 |
+ 'notnull' => false, |
|
174 |
+ 'length' => 1, |
|
175 |
+ ]); |
|
176 |
+ $table->addColumn('show_all_messages', Types::SMALLINT, [ |
|
177 |
+ 'notnull' => false, |
|
178 |
+ 'length' => 1, |
|
179 |
+ ]); |
|
180 |
+ $table->addColumn('show_display_names', Types::SMALLINT, [ |
|
181 |
+ 'notnull' => false, |
|
182 |
+ 'length' => 1, |
|
183 |
+ ]); |
|
184 |
+ $table->setPrimaryKey(['id']); |
|
185 |
+ $table->addUniqueIndex(['id']); |
|
186 |
+ |
|
187 |
+ } |
|
188 |
+ |
|
189 |
+ |
|
190 |
+ if (!$schema->hasTable('sms_relent_received')) { |
|
191 |
+ $table = $schema->createTable('sms_relent_received'); |
|
192 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
193 |
+ 'autoincrement' => true, |
|
194 |
+ 'notnull' => true, |
|
195 |
+ 'length' => 11, |
|
196 |
+ 'unsigned' => true, |
|
197 |
+ ]); |
|
198 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
199 |
+ 'notnull' => true, |
|
200 |
+ 'length' => 64, |
|
201 |
+ ]); |
|
202 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
203 |
+ 'notnull' => true, |
|
204 |
+ 'length' => 512, |
|
205 |
+ ]); |
|
206 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
207 |
+ 'notnull' => true, |
|
208 |
+ ]); |
|
209 |
+ $table->addColumn('from', Types::STRING, [ |
|
210 |
+ 'notnull' => true, |
|
211 |
+ 'length' => 128, |
|
212 |
+ ]); |
|
213 |
+ $table->addColumn('to', Types::STRING, [ |
|
214 |
+ 'notnull' => true, |
|
215 |
+ 'length' => 128, |
|
216 |
+ ]); |
|
217 |
+ $table->addColumn('message', Types::TEXT, [ |
|
218 |
+ 'notnull' => false, |
|
219 |
+ 'default' => '', |
|
220 |
+ ]); |
|
221 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
222 |
+ 'notnull' => true, |
|
223 |
+ 'length' => 255, |
|
224 |
+ ]); |
|
225 |
+ $table->addColumn('internal_sender', Types::SMALLINT, [ |
|
226 |
+ 'notnull' => false, |
|
227 |
+ 'length' => 1, |
|
228 |
+ ]); |
|
229 |
+ $table->setPrimaryKey(['id']); |
|
230 |
+ $table->addUniqueIndex(['id']); |
|
231 |
+ |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ |
|
235 |
+ if (!$schema->hasTable('sms_relent_sent')) { |
|
236 |
+ $table = $schema->createTable('sms_relent_sent'); |
|
237 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
238 |
+ 'autoincrement' => true, |
|
239 |
+ 'notnull' => true, |
|
240 |
+ 'length' => 11, |
|
241 |
+ 'unsigned' => true, |
|
242 |
+ ]); |
|
243 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
244 |
+ 'notnull' => true, |
|
245 |
+ 'length' => 64, |
|
246 |
+ ]); |
|
247 |
+ $table->addColumn('message_id', Types::STRING, [ |
|
248 |
+ 'notnull' => true, |
|
249 |
+ 'length' => 512, |
|
250 |
+ ]); |
|
251 |
+ $table->addColumn('date', Types::DATETIME, [ |
|
252 |
+ 'notnull' => true, |
|
253 |
+ ]); |
|
254 |
+ $table->addColumn('from', Types::STRING, [ |
|
255 |
+ 'notnull' => true, |
|
256 |
+ 'length' => 128, |
|
257 |
+ ]); |
|
258 |
+ $table->addColumn('to', Types::STRING, [ |
|
259 |
+ 'notnull' => true, |
|
260 |
+ 'length' => 128, |
|
261 |
+ ]); |
|
262 |
+ $table->addColumn('network ', Types::STRING, [ |
|
263 |
+ 'notnull' => false, |
|
264 |
+ 'length' => 64, |
|
265 |
+ 'default' => '', |
|
266 |
+ ]); |
|
267 |
+ $table->addColumn('price', Types::STRING, [ |
|
268 |
+ 'notnull' => false, |
|
269 |
+ 'length' => 64, |
|
270 |
+ 'default' => '', |
|
271 |
+ ]); |
|
272 |
+ $table->addColumn('status', Types::STRING, [ |
|
273 |
+ 'notnull' => false, |
|
274 |
+ 'length' => 512, |
|
275 |
+ 'default' => '', |
|
276 |
+ ]); |
|
277 |
+ $table->addColumn('deliveryreceipt', Types::STRING, [ |
|
278 |
+ 'notnull' => false, |
|
279 |
+ 'length' => 64, |
|
280 |
+ 'default' => '', |
|
281 |
+ ]); |
|
282 |
+ $table->addColumn('message', Types::TEXT, [ |
|
283 |
+ 'notnull' => false, |
|
284 |
+ 'default' => '', |
|
285 |
+ ]); |
|
286 |
+ $table->addColumn('author_displayname', Types::STRING, [ |
|
287 |
+ 'notnull' => true, |
|
288 |
+ 'length' => 255, |
|
289 |
+ ]); |
|
290 |
+ $table->setPrimaryKey(['id']); |
|
291 |
+ $table->addUniqueIndex(['id']); |
|
292 |
+ |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+ |
|
296 |
+ if (!$schema->hasTable('sms_relent_autorply')) { |
|
297 |
+ $table = $schema->createTable('sms_relent_autorply'); |
|
298 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
299 |
+ 'autoincrement' => true, |
|
300 |
+ 'notnull' => true, |
|
301 |
+ 'length' => 11, |
|
302 |
+ 'unsigned' => true, |
|
303 |
+ ]); |
|
304 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
305 |
+ 'notnull' => true, |
|
306 |
+ 'length' => 128, |
|
307 |
+ ]); |
|
308 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
309 |
+ 'notnull' => true, |
|
310 |
+ 'length' => 255, |
|
311 |
+ ]); |
|
312 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
313 |
+ 'notnull' => true, |
|
314 |
+ 'length' => 128, |
|
315 |
+ ]); |
|
316 |
+ $table->addColumn('days_of_week', Types::STRING, [ |
|
317 |
+ 'notnull' => false, |
|
318 |
+ 'length' => 64, |
|
319 |
+ 'default' => '', |
|
320 |
+ ]); |
|
321 |
+ $table->addColumn('daily_start', Types::STRING, [ |
|
322 |
+ 'notnull' => false, |
|
323 |
+ 'length' => 8, |
|
324 |
+ 'default' => '', |
|
325 |
+ ]); |
|
326 |
+ $table->addColumn('daily_end', Types::STRING, [ |
|
327 |
+ 'notnull' => false, |
|
328 |
+ 'length' => 8, |
|
329 |
+ 'default' => '', |
|
330 |
+ ]); |
|
331 |
+ $table->addColumn('vacation_start', Types::DATETIME, [ |
|
332 |
+ 'notnull' => false, |
|
333 |
+ ]); |
|
334 |
+ $table->addColumn('vacation_end', Types::DATETIME, [ |
|
335 |
+ 'notnull' => false, |
|
336 |
+ ]); |
|
337 |
+ $table->addColumn('message_text', Types::TEXT, [ |
|
338 |
+ 'notnull' => false, |
|
339 |
+ 'default' => '', |
|
340 |
+ ]); |
|
341 |
+ $table->setPrimaryKey(['id']); |
|
342 |
+ $table->addUniqueIndex(['id']); |
|
343 |
+ |
|
344 |
+ } |
|
345 |
+ |
|
346 |
+ |
|
347 |
+ if (!$schema->hasTable('sms_relent_restrict')) { |
|
348 |
+ $table = $schema->createTable('sms_relent_restrict'); |
|
349 |
+ $table->addColumn('id', Types::BIGINT, [ |
|
350 |
+ 'autoincrement' => true, |
|
351 |
+ 'notnull' => true, |
|
352 |
+ 'length' => 11, |
|
353 |
+ 'unsigned' => true, |
|
354 |
+ ]); |
|
355 |
+ $table->addColumn('user_id', Types::STRING, [ |
|
356 |
+ 'notnull' => true, |
|
357 |
+ 'length' => 128, |
|
358 |
+ ]); |
|
359 |
+ $table->addColumn('saved_by_dsplname', Types::STRING, [ |
|
360 |
+ 'notnull' => true, |
|
361 |
+ 'length' => 255, |
|
362 |
+ ]); |
|
363 |
+ $table->addColumn('phone_number', Types::STRING, [ |
|
364 |
+ 'notnull' => true, |
|
365 |
+ 'length' => 128, |
|
366 |
+ ]); |
|
367 |
+ $table->addColumn('groups', Types::STRING, [ |
|
368 |
+ 'notnull' => true, |
|
369 |
+ 'length' => 2048, |
|
370 |
+ ]); |
|
371 |
+ $table->addColumn('users', Types::STRING, [ |
|
372 |
+ 'notnull' => true, |
|
373 |
+ 'length' => 2048, |
|
374 |
+ ]); |
|
375 |
+ $table->setPrimaryKey(['id']); |
|
376 |
+ $table->addUniqueIndex(['id']); |
|
377 |
+ |
|
378 |
+ } |
|
379 |
+ |
|
380 |
+ return $schema; |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
384 |
+ |
|
385 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before |
|
386 |
+ $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`'); |
|
387 |
+ $getrecfromnbres = $getrecfromnb->execute(); |
|
388 |
+ |
|
389 |
+ $recdatanmbrs = []; |
|
390 |
+ while ($rowfetched = $getrecfromnbres->fetch()) { |
|
391 |
+ $recdatanmbrs[] = $rowfetched['from']; |
|
392 |
+ } |
|
393 |
+ $getrecfromnbres->closeCursor(); |
|
394 |
+ |
|
395 |
+ if ($recdatanmbrs) { |
|
396 |
+ |
|
397 |
+ $recnmbrs = array_values(array_unique($recdatanmbrs)); |
|
398 |
+ |
|
399 |
+ $phoneDisplayPairs = []; |
|
400 |
+ foreach ($recnmbrs as $rckey => $rcvalue) { |
|
401 |
+ |
|
402 |
+ $rcvalueprc = '%' . $rcvalue; |
|
403 |
+ $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
404 |
+ $getacdatares = $getacdata->execute(['phone', $rcvalueprc]); |
|
405 |
+ |
|
406 |
+ $acdatausers = []; |
|
407 |
+ while ($acusrfetched = $getacdatares->fetch()) { |
|
408 |
+ $acdatausers[] = $acusrfetched['uid']; |
|
409 |
+ } |
|
410 |
+ $getacdatares->closeCursor(); |
|
411 |
+ |
|
412 |
+ |
|
413 |
+ if ($acdatausers) { |
|
414 |
+ |
|
415 |
+ $acdatausrdn = []; |
|
416 |
+ foreach ($acdatausers as $dnkey => $dnvalue) { |
|
417 |
+ |
|
418 |
+ $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
419 |
+ $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']); |
|
420 |
+ |
|
421 |
+ while ($acusrdnfetched = $getacdatadnres->fetch()) { |
|
422 |
+ $acdatausrdn[] = $acusrdnfetched['value']; |
|
423 |
+ } |
|
424 |
+ $getacdatadnres->closeCursor(); |
|
425 |
+ } |
|
426 |
+ |
|
427 |
+ if ($acdatausrdn) { |
|
428 |
+ |
|
429 |
+ if (count($acdatausrdn) == 1) { |
|
430 |
+ |
|
431 |
+ $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1]; |
|
432 |
+ |
|
433 |
+ } elseif (count($acdatausrdn) > 1) { |
|
434 |
+ |
|
435 |
+ $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1]; |
|
436 |
+ } |
|
437 |
+ |
|
438 |
+ } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
439 |
+ |
|
440 |
+ } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; } |
|
441 |
+ } |
|
442 |
+ |
|
443 |
+ foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) { |
|
444 |
+ |
|
445 |
+ if (is_array($pdpvalue)) { |
|
446 |
+ $pdpkeyprc = '%' . $pdpkey; |
|
447 |
+ $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?'); |
|
448 |
+ $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]); |
|
449 |
+ $updaterecmsres->closeCursor(); |
|
450 |
+ } |
|
451 |
+ } |
|
452 |
+ } |
|
453 |
+ |
|
454 |
+ |
|
455 |
+ // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before |
|
456 |
+ $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`'); |
|
457 |
+ $getsentfromnbres = $getsentfromnb->execute(); |
|
458 |
+ |
|
459 |
+ $sentdatanmbrs = []; |
|
460 |
+ while ($rowfetchedst = $getsentfromnbres->fetch()) { |
|
461 |
+ |
|
462 |
+ $sentdatanmbrspre = $rowfetchedst['from']; |
|
463 |
+ $sentdatanmbrsarr = explode("+", $sentdatanmbrspre); |
|
464 |
+ if (count($sentdatanmbrsarr) > 1) { |
|
465 |
+ $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1]; |
|
466 |
+ } else { |
|
467 |
+ $sentdatanmbrs[] = $sentdatanmbrsarr[0]; |
|
468 |
+ } |
|
469 |
+ } |
|
470 |
+ $getsentfromnbres->closeCursor(); |
|
471 |
+ |
|
472 |
+ if ($sentdatanmbrs) { |
|
473 |
+ |
|
474 |
+ $sentnmbrs = array_values(array_unique($sentdatanmbrs)); |
|
475 |
+ |
|
476 |
+ $phoneDisplayPairsst = []; |
|
477 |
+ foreach ($sentnmbrs as $stkey => $stvalue) { |
|
478 |
+ |
|
479 |
+ $stvalueprc = '%' . $stvalue; |
|
480 |
+ $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?'); |
|
481 |
+ $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]); |
|
482 |
+ |
|
483 |
+ $acdatausersst = []; |
|
484 |
+ while ($acusrstfetched = $getacdatastres->fetch()) { |
|
485 |
+ $acdatausersst[] = $acusrstfetched['uid']; |
|
486 |
+ } |
|
487 |
+ $getacdatastres->closeCursor(); |
|
488 |
+ |
|
489 |
+ if ($acdatausersst) { |
|
490 |
+ |
|
491 |
+ $acdatausrdnst = []; |
|
492 |
+ foreach ($acdatausersst as $dnstkey => $dnstvalue) { |
|
493 |
+ |
|
494 |
+ $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?'); |
|
495 |
+ $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']); |
|
496 |
+ |
|
497 |
+ while ($acusrdnstfetched = $getacdatadnstres->fetch()) { |
|
498 |
+ $acdatausrdnst[] = $acusrdnstfetched['value']; |
|
499 |
+ } |
|
500 |
+ $getacdatadnstres->closeCursor(); |
|
501 |
+ } |
|
502 |
+ |
|
503 |
+ if ($acdatausrdnst) { |
|
504 |
+ |
|
505 |
+ if (count($acdatausrdnst) == 1) { |
|
506 |
+ |
|
507 |
+ $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]]; |
|
508 |
+ |
|
509 |
+ } elseif (count($acdatausrdnst) > 1) { |
|
510 |
+ |
|
511 |
+ $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)]; |
|
512 |
+ } |
|
513 |
+ |
|
514 |
+ } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
515 |
+ |
|
516 |
+ } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; } |
|
517 |
+ } |
|
518 |
+ |
|
519 |
+ foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) { |
|
520 |
+ |
|
521 |
+ if (is_array($pstvalue)) { |
|
522 |
+ $contfield = "%" . $pstkey; |
|
523 |
+ $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?'); |
|
524 |
+ $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]); |
|
525 |
+ $updatesentmsres->closeCursor(); |
|
526 |
+ } |
|
527 |
+ } |
|
528 |
+ } |
|
529 |
+ |
|
530 |
+ return null; |
|
531 |
+ } |
|
532 |
+ |
|
533 |
+} |