Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/showsmstables.js lib/Migration/Version116Date20230508212745.php lib/Migration/Version117Date20230509183517.php lib/Migration/Version118Date20230509194216.php lib/Migration/Version120Date20230520072431.php lib/Migration/Version121Date20230523201743.php lib/Migration/Version123Date20230524182156.php

DoubleBastionAdmin authored on 24/05/2023 14:49:31
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,545 @@
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 Version120Date20230520072431 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
+		if (!$schema->hasTable('sms_relent_subac')) {
381
+			$table = $schema->createTable('sms_relent_subac');
382
+			$table->addColumn('id', Types::BIGINT, [
383
+				'autoincrement' => true,
384
+				'notnull' => true,
385
+                                'length' => 11,
386
+                                'unsigned' => true,
387
+			]);
388
+			$table->addColumn('user_id', Types::STRING, [
389
+				'notnull' => true,
390
+				'length' => 128,
391
+			]);
392
+			$table->addColumn('tnx_groups_allowed', Types::TEXT, [
393
+				'notnull' => false,
394
+                                'default' => '',
395
+			]);
396
+			$table->addColumn('tnx_users_allowed', Types::TEXT, [
397
+				'notnull' => false,
398
+                                'default' => '',
399
+			]);
400
+			$table->addColumn('plv_groups_allowed', Types::TEXT, [
401
+				'notnull' => false,
402
+                                'default' => '',
403
+			]);
404
+			$table->addColumn('plv_users_allowed', Types::TEXT, [
405
+				'notnull' => false,
406
+                                'default' => '',
407
+			]);
408
+			$table->addColumn('twl_groups_allowed', Types::TEXT, [
409
+				'notnull' => false,
410
+                                'default' => '',
411
+			]);
412
+			$table->addColumn('twl_users_allowed', Types::TEXT, [
413
+				'notnull' => false,
414
+                                'default' => '',
415
+			]);
416
+			$table->addColumn('flr_groups_allowed', Types::TEXT, [
417
+				'notnull' => false,
418
+                                'default' => '',
419
+			]);
420
+			$table->addColumn('flr_users_allowed', Types::TEXT, [
421
+				'notnull' => false,
422
+                                'default' => '',
423
+			]);
424
+                        $table->setPrimaryKey(['id']);
425
+                        $table->addUniqueIndex(['id']);
426
+		}
427
+
428
+
429
+		return $schema;
430
+	}
431
+
432
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
433
+
434
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
435
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
436
+	        $getrecfromnbres = $getrecfromnb->execute();
437
+
438
+                $recdatauids = [];
439
+                $idsent = [];
440
+                while ($rowfetched = $getrecfromnbres->fetch()) {
441
+                       $recdatauids[] = $rowfetched['user_id'];
442
+                       $idsent[] = $rowfetched['id'];
443
+                }
444
+                $getrecfromnbres->closeCursor();
445
+
446
+                if ($recdatauids) {
447
+
448
+                    $recuids = array_values(array_unique($recdatauids));
449
+                    $acdatausrdn = [];
450
+
451
+                    foreach ($recuids as $dnkey => $dnvalue) {
452
+		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
453
+			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
454
+
455
+			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
456
+				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
457
+			     }
458
+			     $getacdatadnres->closeCursor();
459
+                    }
460
+
461
+                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
462
+
463
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
464
+			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
465
+			     $updaterecmsres->closeCursor();
466
+                    }
467
+                }
468
+
469
+
470
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
471
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
472
+	        $getrecfromnbres = $getrecfromnb->execute();
473
+
474
+                $recdatanmbrs = [];
475
+                $idsrc = [];
476
+                $daterec = [];
477
+                while ($rowfetched = $getrecfromnbres->fetch()) {
478
+                       $recdatanmbrs[] = $rowfetched['from'];
479
+                       $idsrc[] = $rowfetched['id'];
480
+                       $daterecarr = explode(":", $rowfetched['date']);
481
+                       $daterec[] = $daterecarr[0];
482
+                }
483
+                $getrecfromnbres->closeCursor();
484
+
485
+                if ($recdatanmbrs) {
486
+
487
+                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
488
+
489
+			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
490
+			     $recmsgfromprc = '%' . $rcvalue;
491
+                             $recdataprc = $daterec[$rckey] . '%';
492
+			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
493
+			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
494
+
495
+			     $dispnamearr = [];
496
+			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
497
+				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
498
+			     }
499
+			     $getdspnmstres->closeCursor();
500
+
501
+			     if ($dispnamearr) {
502
+				 $descdspnmarr = array_reverse($dispnamearr);
503
+				 $authorDisplayNm = $descdspnmarr[0];
504
+				 $internalSender = 1;
505
+
506
+			     } else {
507
+
508
+                                 $authorDisplayNm = '';
509
+
510
+			         $getfrom = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? LIMIT 1');
511
+			         $getfromres = $getfrom->execute([$recmsgfromprc]);
512
+                                 $fromfetched = $getfromres->fetch();
513
+
514
+                                 if ($fromfetched) { $internalSender = 1; } else { $internalSender = 0; }
515
+
516
+
517
+				 // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table
518
+				 $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?');
519
+				 $getdspnmres = $getdspnm->execute([$rcvalue]);
520
+
521
+				 $dspnmearr = [];
522
+				 while ($dspnmfetched = $getdspnmres->fetch()) {
523
+				        if ($dspnmfetched['author_displayname']) {
524
+				            $dspnmearr[] = $dspnmfetched['author_displayname'];
525
+				        }
526
+				 }
527
+				 $getdspnmres->closeCursor();
528
+
529
+				 if ($dspnmearr) {
530
+				     $descdisplaynmarr = array_reverse($dspnmearr);
531
+				     $authorDisplayNm = $descdisplaynmarr[0];
532
+				 } else { $authorDisplayNm = ''; }
533
+			     }
534
+
535
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
536
+                                                                        WHERE `from` LIKE ? AND `id` = ?');
537
+			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $recmsgfromprc, $idsrc[$rckey]]);
538
+			     $updaterecmsres->closeCursor();
539
+                    }
540
+                }
541
+
542
+                return null;
543
+        }
544
+
545
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json js/showsmstables.js lib/Migration/Version116Date20230508212745.php lib/Migration/Version117Date20230509183517.php lib/Migration/Version118Date20230509194216.php lib/Migration/Version120Date20230520072431.php lib/Migration/Version121Date20230523201743.php

DoubleBastionAdmin authored on 24/05/2023 14:40:29
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,543 +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 Version120Date20230520072431 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
-		if (!$schema->hasTable('sms_relent_subac')) {
381
-			$table = $schema->createTable('sms_relent_subac');
382
-			$table->addColumn('id', Types::BIGINT, [
383
-				'autoincrement' => true,
384
-				'notnull' => true,
385
-                                'length' => 11,
386
-                                'unsigned' => true,
387
-			]);
388
-			$table->addColumn('user_id', Types::STRING, [
389
-				'notnull' => true,
390
-				'length' => 128,
391
-			]);
392
-			$table->addColumn('tnx_groups_allowed', Types::TEXT, [
393
-				'notnull' => false,
394
-                                'default' => '',
395
-			]);
396
-			$table->addColumn('tnx_users_allowed', Types::TEXT, [
397
-				'notnull' => false,
398
-                                'default' => '',
399
-			]);
400
-			$table->addColumn('plv_groups_allowed', Types::TEXT, [
401
-				'notnull' => false,
402
-                                'default' => '',
403
-			]);
404
-			$table->addColumn('plv_users_allowed', Types::TEXT, [
405
-				'notnull' => false,
406
-                                'default' => '',
407
-			]);
408
-			$table->addColumn('twl_groups_allowed', Types::TEXT, [
409
-				'notnull' => false,
410
-                                'default' => '',
411
-			]);
412
-			$table->addColumn('twl_users_allowed', Types::TEXT, [
413
-				'notnull' => false,
414
-                                'default' => '',
415
-			]);
416
-			$table->addColumn('flr_groups_allowed', Types::TEXT, [
417
-				'notnull' => false,
418
-                                'default' => '',
419
-			]);
420
-			$table->addColumn('flr_users_allowed', Types::TEXT, [
421
-				'notnull' => false,
422
-                                'default' => '',
423
-			]);
424
-                        $table->setPrimaryKey(['id']);
425
-                        $table->addUniqueIndex(['id']);
426
-		}
427
-
428
-
429
-		return $schema;
430
-	}
431
-
432
-        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
433
-
434
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
435
-                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
436
-	        $getrecfromnbres = $getrecfromnb->execute();
437
-
438
-                $recdatauids = [];
439
-                $idsent = [];
440
-                while ($rowfetched = $getrecfromnbres->fetch()) {
441
-                       $recdatauids[] = $rowfetched['user_id'];
442
-                       $idsent[] = $rowfetched['id'];
443
-                }
444
-                $getrecfromnbres->closeCursor();
445
-
446
-                if ($recdatauids) {
447
-
448
-                    $recuids = array_values(array_unique($recdatauids));
449
-                    $acdatausrdn = [];
450
-
451
-                    foreach ($recuids as $dnkey => $dnvalue) {
452
-		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
453
-			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
454
-
455
-			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
456
-				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
457
-			     }
458
-			     $getacdatadnres->closeCursor();
459
-                    }
460
-
461
-                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
462
-
463
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
464
-			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
465
-			     $updaterecmsres->closeCursor();
466
-                    }
467
-                }
468
-
469
-
470
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
471
-                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
472
-	        $getrecfromnbres = $getrecfromnb->execute();
473
-
474
-                $recdatanmbrs = [];
475
-                $idsrc = [];
476
-                $daterec = [];
477
-                while ($rowfetched = $getrecfromnbres->fetch()) {
478
-                       $recdatanmbrs[] = $rowfetched['from'];
479
-                       $idsrc[] = $rowfetched['id'];
480
-                       $daterecarr = explode(":", $rowfetched['date']);
481
-                       $daterec[] = $daterecarr[0];
482
-                }
483
-                $getrecfromnbres->closeCursor();
484
-
485
-                if ($recdatanmbrs) {
486
-
487
-                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
488
-
489
-			     $authorDisplayNm = '';
490
-			     $internalSender = 0;
491
-
492
-			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
493
-			     $recmsgfromprc = '%' . $rcvalue;
494
-                             $recdataprc = $daterec[$rckey] . '%';
495
-			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
496
-			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
497
-
498
-			     $dispnamearr = [];
499
-			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
500
-				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
501
-			     }
502
-			     $getdspnmstres->closeCursor();
503
-
504
-			     if ($dispnamearr) {
505
-				 $descdspnmarr = array_reverse($dispnamearr);
506
-				 $authorDisplayNm = $descdspnmarr[0];
507
-				 $internalSender = 1;
508
-			     } else { $authorDisplayNm = ''; $internalSender = 0; }
509
-
510
-
511
-			     if (!$authorDisplayNm) {
512
-
513
-				 // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table
514
-				 $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?');
515
-				 $getdspnmres = $getdspnm->execute([$rcvalue]);
516
-
517
-				 $dspnmearr = [];
518
-				 while ($dspnmfetched = $getdspnmres->fetch()) {
519
-				        if ($dspnmfetched['author_displayname']) {
520
-				            $dspnmearr[] = $dspnmfetched['author_displayname'];
521
-				        }
522
-				 }
523
-				 $getdspnmres->closeCursor();
524
-
525
-				 if ($dspnmearr) {
526
-				     $descdisplaynmarr = array_reverse($dspnmearr);
527
-				     $authorDisplayNm = $descdisplaynmarr[0];
528
-				     $internalSender = 0;
529
-				 } else { $authorDisplayNm = ''; $internalSender = 0; }
530
-			     }
531
-
532
-                             $pdpkeyprc = '%' . $rcvalue;
533
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
534
-                                                                        WHERE `from` LIKE ? AND `id` = ?');
535
-			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $pdpkeyprc, $idsrc[$rckey]]);
536
-			     $updaterecmsres->closeCursor();
537
-                    }
538
-                }
539
-
540
-                return null;
541
-        }
542
-
543
-}
Browse code

added CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css img/closewnd.svg js/adminsettings.js js/deleteoldsms.js ...

DoubleBastionAdmin authored on 23/05/2023 19:00:54
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,543 @@
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 Version120Date20230520072431 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
+		if (!$schema->hasTable('sms_relent_subac')) {
381
+			$table = $schema->createTable('sms_relent_subac');
382
+			$table->addColumn('id', Types::BIGINT, [
383
+				'autoincrement' => true,
384
+				'notnull' => true,
385
+                                'length' => 11,
386
+                                'unsigned' => true,
387
+			]);
388
+			$table->addColumn('user_id', Types::STRING, [
389
+				'notnull' => true,
390
+				'length' => 128,
391
+			]);
392
+			$table->addColumn('tnx_groups_allowed', Types::TEXT, [
393
+				'notnull' => false,
394
+                                'default' => '',
395
+			]);
396
+			$table->addColumn('tnx_users_allowed', Types::TEXT, [
397
+				'notnull' => false,
398
+                                'default' => '',
399
+			]);
400
+			$table->addColumn('plv_groups_allowed', Types::TEXT, [
401
+				'notnull' => false,
402
+                                'default' => '',
403
+			]);
404
+			$table->addColumn('plv_users_allowed', Types::TEXT, [
405
+				'notnull' => false,
406
+                                'default' => '',
407
+			]);
408
+			$table->addColumn('twl_groups_allowed', Types::TEXT, [
409
+				'notnull' => false,
410
+                                'default' => '',
411
+			]);
412
+			$table->addColumn('twl_users_allowed', Types::TEXT, [
413
+				'notnull' => false,
414
+                                'default' => '',
415
+			]);
416
+			$table->addColumn('flr_groups_allowed', Types::TEXT, [
417
+				'notnull' => false,
418
+                                'default' => '',
419
+			]);
420
+			$table->addColumn('flr_users_allowed', Types::TEXT, [
421
+				'notnull' => false,
422
+                                'default' => '',
423
+			]);
424
+                        $table->setPrimaryKey(['id']);
425
+                        $table->addUniqueIndex(['id']);
426
+		}
427
+
428
+
429
+		return $schema;
430
+	}
431
+
432
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
433
+
434
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
435
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
436
+	        $getrecfromnbres = $getrecfromnb->execute();
437
+
438
+                $recdatauids = [];
439
+                $idsent = [];
440
+                while ($rowfetched = $getrecfromnbres->fetch()) {
441
+                       $recdatauids[] = $rowfetched['user_id'];
442
+                       $idsent[] = $rowfetched['id'];
443
+                }
444
+                $getrecfromnbres->closeCursor();
445
+
446
+                if ($recdatauids) {
447
+
448
+                    $recuids = array_values(array_unique($recdatauids));
449
+                    $acdatausrdn = [];
450
+
451
+                    foreach ($recuids as $dnkey => $dnvalue) {
452
+		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
453
+			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
454
+
455
+			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
456
+				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
457
+			     }
458
+			     $getacdatadnres->closeCursor();
459
+                    }
460
+
461
+                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
462
+
463
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
464
+			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
465
+			     $updaterecmsres->closeCursor();
466
+                    }
467
+                }
468
+
469
+
470
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
471
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
472
+	        $getrecfromnbres = $getrecfromnb->execute();
473
+
474
+                $recdatanmbrs = [];
475
+                $idsrc = [];
476
+                $daterec = [];
477
+                while ($rowfetched = $getrecfromnbres->fetch()) {
478
+                       $recdatanmbrs[] = $rowfetched['from'];
479
+                       $idsrc[] = $rowfetched['id'];
480
+                       $daterecarr = explode(":", $rowfetched['date']);
481
+                       $daterec[] = $daterecarr[0];
482
+                }
483
+                $getrecfromnbres->closeCursor();
484
+
485
+                if ($recdatanmbrs) {
486
+
487
+                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
488
+
489
+			     $authorDisplayNm = '';
490
+			     $internalSender = 0;
491
+
492
+			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
493
+			     $recmsgfromprc = '%' . $rcvalue;
494
+                             $recdataprc = $daterec[$rckey] . '%';
495
+			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
496
+			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
497
+
498
+			     $dispnamearr = [];
499
+			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
500
+				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
501
+			     }
502
+			     $getdspnmstres->closeCursor();
503
+
504
+			     if ($dispnamearr) {
505
+				 $descdspnmarr = array_reverse($dispnamearr);
506
+				 $authorDisplayNm = $descdspnmarr[0];
507
+				 $internalSender = 1;
508
+			     } else { $authorDisplayNm = ''; $internalSender = 0; }
509
+
510
+
511
+			     if (!$authorDisplayNm) {
512
+
513
+				 // Search for the associated Display Name in the previous messages coming from the same phone number, in the 'sms_relent_received' table
514
+				 $getdspnm = $this->connection->prepare('SELECT `from`, `author_displayname` FROM `*PREFIX*sms_relent_received` WHERE `from` = ?');
515
+				 $getdspnmres = $getdspnm->execute([$rcvalue]);
516
+
517
+				 $dspnmearr = [];
518
+				 while ($dspnmfetched = $getdspnmres->fetch()) {
519
+				        if ($dspnmfetched['author_displayname']) {
520
+				            $dspnmearr[] = $dspnmfetched['author_displayname'];
521
+				        }
522
+				 }
523
+				 $getdspnmres->closeCursor();
524
+
525
+				 if ($dspnmearr) {
526
+				     $descdisplaynmarr = array_reverse($dspnmearr);
527
+				     $authorDisplayNm = $descdisplaynmarr[0];
528
+				     $internalSender = 0;
529
+				 } else { $authorDisplayNm = ''; $internalSender = 0; }
530
+			     }
531
+
532
+                             $pdpkeyprc = '%' . $rcvalue;
533
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
534
+                                                                        WHERE `from` LIKE ? AND `id` = ?');
535
+			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $pdpkeyprc, $idsrc[$rckey]]);
536
+			     $updaterecmsres->closeCursor();
537
+                    }
538
+                }
539
+
540
+                return null;
541
+        }
542
+
543
+}
Browse code

removed CHANGELOG.txt appinfo/info.xml appinfo/signature.json css/style.css img/closewnd.svg ...

DoubleBastionAdmin authored on 23/05/2023 18:50:19
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,582 +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 Version120Date20230520072431 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
-		if (!$schema->hasTable('sms_relent_subac')) {
381
-			$table = $schema->createTable('sms_relent_subac');
382
-			$table->addColumn('id', Types::BIGINT, [
383
-				'autoincrement' => true,
384
-				'notnull' => true,
385
-                                'length' => 11,
386
-                                'unsigned' => true,
387
-			]);
388
-			$table->addColumn('user_id', Types::STRING, [
389
-				'notnull' => true,
390
-				'length' => 128,
391
-			]);
392
-			$table->addColumn('tnx_groups_allowed', Types::TEXT, [
393
-				'notnull' => false,
394
-                                'default' => '',
395
-			]);
396
-			$table->addColumn('tnx_users_allowed', Types::TEXT, [
397
-				'notnull' => false,
398
-                                'default' => '',
399
-			]);
400
-			$table->addColumn('plv_groups_allowed', Types::TEXT, [
401
-				'notnull' => false,
402
-                                'default' => '',
403
-			]);
404
-			$table->addColumn('plv_users_allowed', Types::TEXT, [
405
-				'notnull' => false,
406
-                                'default' => '',
407
-			]);
408
-			$table->addColumn('twl_groups_allowed', Types::TEXT, [
409
-				'notnull' => false,
410
-                                'default' => '',
411
-			]);
412
-			$table->addColumn('twl_users_allowed', Types::TEXT, [
413
-				'notnull' => false,
414
-                                'default' => '',
415
-			]);
416
-			$table->addColumn('flr_groups_allowed', Types::TEXT, [
417
-				'notnull' => false,
418
-                                'default' => '',
419
-			]);
420
-			$table->addColumn('flr_users_allowed', Types::TEXT, [
421
-				'notnull' => false,
422
-                                'default' => '',
423
-			]);
424
-                        $table->setPrimaryKey(['id']);
425
-                        $table->addUniqueIndex(['id']);
426
-		}
427
-
428
-
429
-		return $schema;
430
-	}
431
-
432
-        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
433
-
434
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
435
-                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
436
-	        $getrecfromnbres = $getrecfromnb->execute();
437
-
438
-                $recdatanmbrs = [];
439
-                while ($rowfetched = $getrecfromnbres->fetch()) {
440
-                       $recdatanmbrs[] = $rowfetched['from'];
441
-                }
442
-                $getrecfromnbres->closeCursor();
443
-
444
-                if ($recdatanmbrs) {
445
-
446
-                    $recnmbrs = array_values(array_unique($recdatanmbrs));
447
-
448
-                    $phoneDisplayPairs = [];
449
-                    foreach ($recnmbrs as $rckey => $rcvalue) {
450
-
451
-                         $rcvalueprc = '%' . $rcvalue;
452
-                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
453
-	                 $getacdatares = $getacdata->execute(['phone', $rcvalueprc]);
454
-
455
-		         $acdatausers = [];
456
-		         while ($acusrfetched = $getacdatares->fetch()) {
457
-		                $acdatausers[] = $acusrfetched['uid'];
458
-		         }
459
-		         $getacdatares->closeCursor();
460
-
461
-
462
-                         if ($acdatausers) {
463
-
464
-		             $acdatausrdn = [];
465
-                             foreach ($acdatausers as $dnkey => $dnvalue) {
466
-
467
-		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
468
-			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
469
-
470
-				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
471
-				         $acdatausrdn[] = $acusrdnfetched['value'];
472
-				  }
473
-				  $getacdatadnres->closeCursor();
474
-                             }
475
-
476
-                             if ($acdatausrdn) {
477
-
478
-                                 if (count($acdatausrdn) == 1) {
479
-
480
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
481
-
482
-                                 } elseif (count($acdatausrdn) > 1) {
483
-
484
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
485
-                                 }
486
-
487
-                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
488
-
489
-                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
490
-                    }
491
-
492
-                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
493
-
494
-                         if (is_array($pdpvalue)) {
495
-                             $pdpkeyprc = '%' . $pdpkey;
496
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?');
497
-			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]);
498
-			     $updaterecmsres->closeCursor();
499
-                         }
500
-                    }
501
-                }
502
-
503
-
504
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
505
-                $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`');
506
-	        $getsentfromnbres = $getsentfromnb->execute();
507
-
508
-                $sentdatanmbrs = [];
509
-                while ($rowfetchedst = $getsentfromnbres->fetch()) {
510
-
511
-                       $sentdatanmbrspre = $rowfetchedst['from'];
512
-                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
513
-                       if (count($sentdatanmbrsarr) > 1) {
514
-                           $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
515
-                       } else {
516
-                           $sentdatanmbrs[] = $sentdatanmbrsarr[0];
517
-                       }
518
-                }
519
-                $getsentfromnbres->closeCursor();
520
-
521
-                if ($sentdatanmbrs) {
522
-
523
-                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
524
-
525
-                    $phoneDisplayPairsst = [];
526
-                    foreach ($sentnmbrs as $stkey => $stvalue) {
527
-
528
-                         $stvalueprc = '%' . $stvalue;
529
-                         $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
530
-	                 $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]);
531
-
532
-		         $acdatausersst = [];
533
-		         while ($acusrstfetched = $getacdatastres->fetch()) {
534
-		                $acdatausersst[] = $acusrstfetched['uid'];
535
-		         }
536
-		         $getacdatastres->closeCursor();
537
-
538
-                         if ($acdatausersst) {
539
-
540
-		             $acdatausrdnst = [];
541
-                             foreach ($acdatausersst as $dnstkey => $dnstvalue) {
542
-
543
-		                  $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
544
-			          $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']);
545
-
546
-				  while ($acusrdnstfetched = $getacdatadnstres->fetch()) {
547
-				         $acdatausrdnst[] = $acusrdnstfetched['value'];
548
-				  }
549
-				  $getacdatadnstres->closeCursor();
550
-                             }
551
-
552
-                             if ($acdatausrdnst) {
553
-
554
-                                 if (count($acdatausrdnst) == 1) {
555
-
556
-                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]];
557
-
558
-                                 } elseif (count($acdatausrdnst) > 1) {
559
-
560
-                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)];
561
-                                 }
562
-
563
-                             } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
564
-
565
-                         } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
566
-                    }
567
-
568
-                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
569
-
570
-                         if (is_array($pstvalue)) {
571
-                             $contfield = "%" . $pstkey;
572
-			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
573
-			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
574
-			     $updatesentmsres->closeCursor();
575
-                         }
576
-                    }
577
-                }
578
-
579
-                return null;
580
-        }
581
-
582
-}
Browse code

added files to implement pop-up windows, etc.

DoubleBastionAdmin authored on 20/05/2023 01:06:57
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,582 @@
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 Version120Date20230520072431 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
+		if (!$schema->hasTable('sms_relent_subac')) {
381
+			$table = $schema->createTable('sms_relent_subac');
382
+			$table->addColumn('id', Types::BIGINT, [
383
+				'autoincrement' => true,
384
+				'notnull' => true,
385
+                                'length' => 11,
386
+                                'unsigned' => true,
387
+			]);
388
+			$table->addColumn('user_id', Types::STRING, [
389
+				'notnull' => true,
390
+				'length' => 128,
391
+			]);
392
+			$table->addColumn('tnx_groups_allowed', Types::TEXT, [
393
+				'notnull' => false,
394
+                                'default' => '',
395
+			]);
396
+			$table->addColumn('tnx_users_allowed', Types::TEXT, [
397
+				'notnull' => false,
398
+                                'default' => '',
399
+			]);
400
+			$table->addColumn('plv_groups_allowed', Types::TEXT, [
401
+				'notnull' => false,
402
+                                'default' => '',
403
+			]);
404
+			$table->addColumn('plv_users_allowed', Types::TEXT, [
405
+				'notnull' => false,
406
+                                'default' => '',
407
+			]);
408
+			$table->addColumn('twl_groups_allowed', Types::TEXT, [
409
+				'notnull' => false,
410
+                                'default' => '',
411
+			]);
412
+			$table->addColumn('twl_users_allowed', Types::TEXT, [
413
+				'notnull' => false,
414
+                                'default' => '',
415
+			]);
416
+			$table->addColumn('flr_groups_allowed', Types::TEXT, [
417
+				'notnull' => false,
418
+                                'default' => '',
419
+			]);
420
+			$table->addColumn('flr_users_allowed', Types::TEXT, [
421
+				'notnull' => false,
422
+                                'default' => '',
423
+			]);
424
+                        $table->setPrimaryKey(['id']);
425
+                        $table->addUniqueIndex(['id']);
426
+		}
427
+
428
+
429
+		return $schema;
430
+	}
431
+
432
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
433
+
434
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
435
+                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
436
+	        $getrecfromnbres = $getrecfromnb->execute();
437
+
438
+                $recdatanmbrs = [];
439
+                while ($rowfetched = $getrecfromnbres->fetch()) {
440
+                       $recdatanmbrs[] = $rowfetched['from'];
441
+                }
442
+                $getrecfromnbres->closeCursor();
443
+
444
+                if ($recdatanmbrs) {
445
+
446
+                    $recnmbrs = array_values(array_unique($recdatanmbrs));
447
+
448
+                    $phoneDisplayPairs = [];
449
+                    foreach ($recnmbrs as $rckey => $rcvalue) {
450
+
451
+                         $rcvalueprc = '%' . $rcvalue;
452
+                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
453
+	                 $getacdatares = $getacdata->execute(['phone', $rcvalueprc]);
454
+
455
+		         $acdatausers = [];
456
+		         while ($acusrfetched = $getacdatares->fetch()) {
457
+		                $acdatausers[] = $acusrfetched['uid'];
458
+		         }
459
+		         $getacdatares->closeCursor();
460
+
461
+
462
+                         if ($acdatausers) {
463
+
464
+		             $acdatausrdn = [];
465
+                             foreach ($acdatausers as $dnkey => $dnvalue) {
466
+
467
+		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
468
+			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
469
+
470
+				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
471
+				         $acdatausrdn[] = $acusrdnfetched['value'];
472
+				  }
473
+				  $getacdatadnres->closeCursor();
474
+                             }
475
+
476
+                             if ($acdatausrdn) {
477
+
478
+                                 if (count($acdatausrdn) == 1) {
479
+
480
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
481
+
482
+                                 } elseif (count($acdatausrdn) > 1) {
483
+
484
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
485
+                                 }
486
+
487
+                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
488
+
489
+                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
490
+                    }
491
+
492
+                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
493
+
494
+                         if (is_array($pdpvalue)) {
495
+                             $pdpkeyprc = '%' . $pdpkey;
496
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?');
497
+			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]);
498
+			     $updaterecmsres->closeCursor();
499
+                         }
500
+                    }
501
+                }
502
+
503
+
504
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
505
+                $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`');
506
+	        $getsentfromnbres = $getsentfromnb->execute();
507
+
508
+                $sentdatanmbrs = [];
509
+                while ($rowfetchedst = $getsentfromnbres->fetch()) {
510
+
511
+                       $sentdatanmbrspre = $rowfetchedst['from'];
512
+                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
513
+                       if (count($sentdatanmbrsarr) > 1) {
514
+                           $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
515
+                       } else {
516
+                           $sentdatanmbrs[] = $sentdatanmbrsarr[0];
517
+                       }
518
+                }
519
+                $getsentfromnbres->closeCursor();
520
+
521
+                if ($sentdatanmbrs) {
522
+
523
+                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
524
+
525
+                    $phoneDisplayPairsst = [];
526
+                    foreach ($sentnmbrs as $stkey => $stvalue) {
527
+
528
+                         $stvalueprc = '%' . $stvalue;
529
+                         $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
530
+	                 $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]);
531
+
532
+		         $acdatausersst = [];
533
+		         while ($acusrstfetched = $getacdatastres->fetch()) {
534
+		                $acdatausersst[] = $acusrstfetched['uid'];
535
+		         }
536
+		         $getacdatastres->closeCursor();
537
+
538
+                         if ($acdatausersst) {
539
+
540
+		             $acdatausrdnst = [];
541
+                             foreach ($acdatausersst as $dnstkey => $dnstvalue) {
542
+
543
+		                  $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
544
+			          $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']);
545
+
546
+				  while ($acusrdnstfetched = $getacdatadnstres->fetch()) {
547
+				         $acdatausrdnst[] = $acusrdnstfetched['value'];
548
+				  }
549
+				  $getacdatadnstres->closeCursor();
550
+                             }
551
+
552
+                             if ($acdatausrdnst) {
553
+
554
+                                 if (count($acdatausrdnst) == 1) {
555
+
556
+                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]];
557
+
558
+                                 } elseif (count($acdatausrdnst) > 1) {
559
+
560
+                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)];
561
+                                 }
562
+
563
+                             } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
564
+
565
+                         } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
566
+                    }
567
+
568
+                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
569
+
570
+                         if (is_array($pstvalue)) {
571
+                             $contfield = "%" . $pstkey;
572
+			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
573
+			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
574
+			     $updatesentmsres->closeCursor();
575
+                         }
576
+                    }
577
+                }
578
+
579
+                return null;
580
+        }
581
+
582
+}