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,510 @@
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 Version116Date20230508212745 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
+		} else {
188
+
189
+                        $table = $schema->getTable('sms_relent_settings');
190
+
191
+			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
+				'notnull' => false,
193
+				'length' => 1,
194
+			]);
195
+			$table->addColumn('show_display_names', Types::SMALLINT, [
196
+				'notnull' => false,
197
+				'length' => 1,
198
+			]);
199
+                }
200
+
201
+
202
+		if (!$schema->hasTable('sms_relent_received')) {
203
+			$table = $schema->createTable('sms_relent_received');
204
+			$table->addColumn('id', Types::BIGINT, [
205
+				'autoincrement' => true,
206
+				'notnull' => true,
207
+                                'length' => 11,
208
+                                'unsigned' => true,
209
+			]);
210
+			$table->addColumn('user_id', Types::STRING, [
211
+				'notnull' => true,
212
+				'length' => 64,
213
+			]);
214
+			$table->addColumn('message_id', Types::STRING, [
215
+				'notnull' => true,
216
+				'length' => 512,
217
+			]);
218
+			$table->addColumn('date', Types::DATETIME, [
219
+				'notnull' => true,
220
+			]);
221
+			$table->addColumn('from', Types::STRING, [
222
+				'notnull' => true,
223
+				'length' => 128,
224
+			]);
225
+			$table->addColumn('to', Types::STRING, [
226
+				'notnull' => true,
227
+				'length' => 128,
228
+			]);
229
+			$table->addColumn('message', Types::TEXT, [
230
+				'notnull' => false,
231
+				'default' => '',
232
+			]);
233
+			$table->addColumn('author_displayname', Types::STRING, [
234
+				'notnull' => true,
235
+				'length' => 255,
236
+			]);
237
+			$table->addColumn('internal_sender', Types::SMALLINT, [
238
+				'notnull' => false,
239
+				'length' => 1,
240
+			]);
241
+                        $table->setPrimaryKey(['id']);
242
+                        $table->addUniqueIndex(['id']);
243
+
244
+		} else {
245
+
246
+                        $table = $schema->getTable('sms_relent_received');
247
+
248
+			$table->addColumn('author_displayname', Types::STRING, [
249
+				'notnull' => true,
250
+				'length' => 255,
251
+			]);
252
+			$table->addColumn('internal_sender', Types::SMALLINT, [
253
+				'notnull' => false,
254
+				'length' => 1,
255
+			]);
256
+                }
257
+
258
+
259
+		if (!$schema->hasTable('sms_relent_sent')) {
260
+			$table = $schema->createTable('sms_relent_sent');
261
+			$table->addColumn('id', Types::BIGINT, [
262
+				'autoincrement' => true,
263
+				'notnull' => true,
264
+                                'length' => 11,
265
+                                'unsigned' => true,
266
+			]);
267
+			$table->addColumn('user_id', Types::STRING, [
268
+				'notnull' => true,
269
+				'length' => 64,
270
+			]);
271
+			$table->addColumn('message_id', Types::STRING, [
272
+				'notnull' => true,
273
+				'length' => 512,
274
+			]);
275
+			$table->addColumn('date', Types::DATETIME, [
276
+				'notnull' => true,
277
+			]);
278
+			$table->addColumn('from', Types::STRING, [
279
+				'notnull' => true,
280
+				'length' => 128,
281
+			]);
282
+			$table->addColumn('to', Types::STRING, [
283
+				'notnull' => true,
284
+				'length' => 128,
285
+			]);
286
+			$table->addColumn('network ', Types::STRING, [
287
+				'notnull' => false,
288
+				'length' => 64,
289
+				'default' => '',
290
+			]);
291
+			$table->addColumn('price', Types::STRING, [
292
+				'notnull' => false,
293
+				'length' => 64,
294
+				'default' => '',
295
+			]);
296
+			$table->addColumn('status', Types::STRING, [
297
+				'notnull' => false,
298
+				'length' => 512,
299
+				'default' => '',
300
+			]);
301
+			$table->addColumn('deliveryreceipt', Types::STRING, [
302
+				'notnull' => false,
303
+				'length' => 64,
304
+				'default' => '',
305
+			]);
306
+			$table->addColumn('message', Types::TEXT, [
307
+				'notnull' => false,
308
+                                'default' => '',
309
+			]);
310
+			$table->addColumn('author_displayname', Types::STRING, [
311
+				'notnull' => true,
312
+				'length' => 255,
313
+			]);
314
+                        $table->setPrimaryKey(['id']);
315
+                        $table->addUniqueIndex(['id']);
316
+
317
+		} else {
318
+
319
+                        $table = $schema->getTable('sms_relent_sent');
320
+
321
+			$table->addColumn('author_displayname', Types::STRING, [
322
+				'notnull' => true,
323
+				'length' => 255,
324
+			]);
325
+                }
326
+
327
+
328
+		if (!$schema->hasTable('sms_relent_autorply')) {
329
+			$table = $schema->createTable('sms_relent_autorply');
330
+			$table->addColumn('id', Types::BIGINT, [
331
+				'autoincrement' => true,
332
+				'notnull' => true,
333
+                                'length' => 11,
334
+                                'unsigned' => true,
335
+			]);
336
+			$table->addColumn('user_id', Types::STRING, [
337
+				'notnull' => true,
338
+				'length' => 128,
339
+			]);
340
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
+				'notnull' => true,
342
+				'length' => 255,
343
+			]);
344
+			$table->addColumn('phone_number', Types::STRING, [
345
+				'notnull' => true,
346
+				'length' => 128,
347
+			]);
348
+			$table->addColumn('days_of_week', Types::STRING, [
349
+				'notnull' => false,
350
+				'length' => 64,
351
+                                'default' => '',
352
+			]);
353
+			$table->addColumn('daily_start', Types::STRING, [
354
+				'notnull' => false,
355
+				'length' => 8,
356
+                                'default' => '',
357
+			]);
358
+			$table->addColumn('daily_end', Types::STRING, [
359
+				'notnull' => false,
360
+				'length' => 8,
361
+                                'default' => '',
362
+			]);
363
+			$table->addColumn('vacation_start', Types::DATETIME, [
364
+				'notnull' => false,
365
+			]);
366
+			$table->addColumn('vacation_end', Types::DATETIME, [
367
+				'notnull' => false,
368
+			]);
369
+			$table->addColumn('message_text', Types::TEXT, [
370
+				'notnull' => false,
371
+                                'default' => '',
372
+			]);
373
+                        $table->setPrimaryKey(['id']);
374
+                        $table->addUniqueIndex(['id']);
375
+
376
+		}
377
+
378
+
379
+		if (!$schema->hasTable('sms_relent_restrict')) {
380
+			$table = $schema->createTable('sms_relent_restrict');
381
+			$table->addColumn('id', Types::BIGINT, [
382
+				'autoincrement' => true,
383
+				'notnull' => true,
384
+                                'length' => 11,
385
+                                'unsigned' => true,
386
+			]);
387
+			$table->addColumn('user_id', Types::STRING, [
388
+				'notnull' => true,
389
+				'length' => 128,
390
+			]);
391
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
+				'notnull' => true,
393
+				'length' => 255,
394
+			]);
395
+			$table->addColumn('phone_number', Types::STRING, [
396
+				'notnull' => true,
397
+				'length' => 128,
398
+			]);
399
+			$table->addColumn('groups', Types::STRING, [
400
+				'notnull' => true,
401
+				'length' => 2048,
402
+			]);
403
+			$table->addColumn('users', Types::STRING, [
404
+				'notnull' => true,
405
+				'length' => 2048,
406
+			]);
407
+                        $table->setPrimaryKey(['id']);
408
+                        $table->addUniqueIndex(['id']);
409
+
410
+		}
411
+
412
+		return $schema;
413
+	}
414
+
415
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
+
417
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
418
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
419
+	        $getrecfromnbres = $getrecfromnb->execute();
420
+
421
+                $recdatauids = [];
422
+                $idsent = [];
423
+                while ($rowfetched = $getrecfromnbres->fetch()) {
424
+                       $recdatauids[] = $rowfetched['user_id'];
425
+                       $idsent[] = $rowfetched['id'];
426
+                }
427
+                $getrecfromnbres->closeCursor();
428
+
429
+                if ($recdatauids) {
430
+
431
+                    $recuids = array_values(array_unique($recdatauids));
432
+                    $acdatausrdn = [];
433
+
434
+                    foreach ($recuids as $dnkey => $dnvalue) {
435
+		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
436
+			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
437
+
438
+			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
439
+				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
440
+			     }
441
+			     $getacdatadnres->closeCursor();
442
+                    }
443
+
444
+                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
445
+
446
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
447
+			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
448
+			     $updaterecmsres->closeCursor();
449
+                    }
450
+                }
451
+
452
+
453
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
454
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
455
+	        $getrecfromnbres = $getrecfromnb->execute();
456
+
457
+                $recdatanmbrs = [];
458
+                $idsrc = [];
459
+                $daterec = [];
460
+                while ($rowfetched = $getrecfromnbres->fetch()) {
461
+                       $recdatanmbrs[] = $rowfetched['from'];
462
+                       $idsrc[] = $rowfetched['id'];
463
+                       $daterecarr = explode(":", $rowfetched['date']);
464
+                       $daterec[] = $daterecarr[0];
465
+                }
466
+                $getrecfromnbres->closeCursor();
467
+
468
+                if ($recdatanmbrs) {
469
+
470
+                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
471
+
472
+			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
473
+			     $recmsgfromprc = '%' . $rcvalue;
474
+                             $recdataprc = $daterec[$rckey] . '%';
475
+			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
476
+			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
477
+
478
+			     $dispnamearr = [];
479
+			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
480
+				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
481
+			     }
482
+			     $getdspnmstres->closeCursor();
483
+
484
+			     if ($dispnamearr) {
485
+				 $descdspnmarr = array_reverse($dispnamearr);
486
+				 $authorDisplayNm = $descdspnmarr[0];
487
+				 $internalSender = 1;
488
+
489
+			     } else {
490
+
491
+                                 $authorDisplayNm = '';
492
+
493
+			         $getfrom = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? LIMIT 1');
494
+			         $getfromres = $getfrom->execute([$recmsgfromprc]);
495
+                                 $fromfetched = $getfromres->fetch();
496
+
497
+                                 if ($fromfetched) { $internalSender = 1; } else { $internalSender = 0; }
498
+			     }
499
+
500
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
501
+                                                                        WHERE `from` LIKE ? AND `id` = ?');
502
+			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $recmsgfromprc, $idsrc[$rckey]]);
503
+			     $updaterecmsres->closeCursor();
504
+                    }
505
+                }
506
+
507
+                return null;
508
+        }
509
+
510
+}
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,504 +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 Version116Date20230508212745 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
-		} else {
188
-
189
-                        $table = $schema->getTable('sms_relent_settings');
190
-
191
-			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
-				'notnull' => false,
193
-				'length' => 1,
194
-			]);
195
-			$table->addColumn('show_display_names', Types::SMALLINT, [
196
-				'notnull' => false,
197
-				'length' => 1,
198
-			]);
199
-                }
200
-
201
-
202
-		if (!$schema->hasTable('sms_relent_received')) {
203
-			$table = $schema->createTable('sms_relent_received');
204
-			$table->addColumn('id', Types::BIGINT, [
205
-				'autoincrement' => true,
206
-				'notnull' => true,
207
-                                'length' => 11,
208
-                                'unsigned' => true,
209
-			]);
210
-			$table->addColumn('user_id', Types::STRING, [
211
-				'notnull' => true,
212
-				'length' => 64,
213
-			]);
214
-			$table->addColumn('message_id', Types::STRING, [
215
-				'notnull' => true,
216
-				'length' => 512,
217
-			]);
218
-			$table->addColumn('date', Types::DATETIME, [
219
-				'notnull' => true,
220
-			]);
221
-			$table->addColumn('from', Types::STRING, [
222
-				'notnull' => true,
223
-				'length' => 128,
224
-			]);
225
-			$table->addColumn('to', Types::STRING, [
226
-				'notnull' => true,
227
-				'length' => 128,
228
-			]);
229
-			$table->addColumn('message', Types::TEXT, [
230
-				'notnull' => false,
231
-				'default' => '',
232
-			]);
233
-			$table->addColumn('author_displayname', Types::STRING, [
234
-				'notnull' => true,
235
-				'length' => 255,
236
-			]);
237
-			$table->addColumn('internal_sender', Types::SMALLINT, [
238
-				'notnull' => false,
239
-				'length' => 1,
240
-			]);
241
-                        $table->setPrimaryKey(['id']);
242
-                        $table->addUniqueIndex(['id']);
243
-
244
-		} else {
245
-
246
-                        $table = $schema->getTable('sms_relent_received');
247
-
248
-			$table->addColumn('author_displayname', Types::STRING, [
249
-				'notnull' => true,
250
-				'length' => 255,
251
-			]);
252
-			$table->addColumn('internal_sender', Types::SMALLINT, [
253
-				'notnull' => false,
254
-				'length' => 1,
255
-			]);
256
-                }
257
-
258
-
259
-		if (!$schema->hasTable('sms_relent_sent')) {
260
-			$table = $schema->createTable('sms_relent_sent');
261
-			$table->addColumn('id', Types::BIGINT, [
262
-				'autoincrement' => true,
263
-				'notnull' => true,
264
-                                'length' => 11,
265
-                                'unsigned' => true,
266
-			]);
267
-			$table->addColumn('user_id', Types::STRING, [
268
-				'notnull' => true,
269
-				'length' => 64,
270
-			]);
271
-			$table->addColumn('message_id', Types::STRING, [
272
-				'notnull' => true,
273
-				'length' => 512,
274
-			]);
275
-			$table->addColumn('date', Types::DATETIME, [
276
-				'notnull' => true,
277
-			]);
278
-			$table->addColumn('from', Types::STRING, [
279
-				'notnull' => true,
280
-				'length' => 128,
281
-			]);
282
-			$table->addColumn('to', Types::STRING, [
283
-				'notnull' => true,
284
-				'length' => 128,
285
-			]);
286
-			$table->addColumn('network ', Types::STRING, [
287
-				'notnull' => false,
288
-				'length' => 64,
289
-				'default' => '',
290
-			]);
291
-			$table->addColumn('price', Types::STRING, [
292
-				'notnull' => false,
293
-				'length' => 64,
294
-				'default' => '',
295
-			]);
296
-			$table->addColumn('status', Types::STRING, [
297
-				'notnull' => false,
298
-				'length' => 512,
299
-				'default' => '',
300
-			]);
301
-			$table->addColumn('deliveryreceipt', Types::STRING, [
302
-				'notnull' => false,
303
-				'length' => 64,
304
-				'default' => '',
305
-			]);
306
-			$table->addColumn('message', Types::TEXT, [
307
-				'notnull' => false,
308
-                                'default' => '',
309
-			]);
310
-			$table->addColumn('author_displayname', Types::STRING, [
311
-				'notnull' => true,
312
-				'length' => 255,
313
-			]);
314
-                        $table->setPrimaryKey(['id']);
315
-                        $table->addUniqueIndex(['id']);
316
-
317
-		} else {
318
-
319
-                        $table = $schema->getTable('sms_relent_sent');
320
-
321
-			$table->addColumn('author_displayname', Types::STRING, [
322
-				'notnull' => true,
323
-				'length' => 255,
324
-			]);
325
-                }
326
-
327
-
328
-		if (!$schema->hasTable('sms_relent_autorply')) {
329
-			$table = $schema->createTable('sms_relent_autorply');
330
-			$table->addColumn('id', Types::BIGINT, [
331
-				'autoincrement' => true,
332
-				'notnull' => true,
333
-                                'length' => 11,
334
-                                'unsigned' => true,
335
-			]);
336
-			$table->addColumn('user_id', Types::STRING, [
337
-				'notnull' => true,
338
-				'length' => 128,
339
-			]);
340
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
-				'notnull' => true,
342
-				'length' => 255,
343
-			]);
344
-			$table->addColumn('phone_number', Types::STRING, [
345
-				'notnull' => true,
346
-				'length' => 128,
347
-			]);
348
-			$table->addColumn('days_of_week', Types::STRING, [
349
-				'notnull' => false,
350
-				'length' => 64,
351
-                                'default' => '',
352
-			]);
353
-			$table->addColumn('daily_start', Types::STRING, [
354
-				'notnull' => false,
355
-				'length' => 8,
356
-                                'default' => '',
357
-			]);
358
-			$table->addColumn('daily_end', Types::STRING, [
359
-				'notnull' => false,
360
-				'length' => 8,
361
-                                'default' => '',
362
-			]);
363
-			$table->addColumn('vacation_start', Types::DATETIME, [
364
-				'notnull' => false,
365
-			]);
366
-			$table->addColumn('vacation_end', Types::DATETIME, [
367
-				'notnull' => false,
368
-			]);
369
-			$table->addColumn('message_text', Types::TEXT, [
370
-				'notnull' => false,
371
-                                'default' => '',
372
-			]);
373
-                        $table->setPrimaryKey(['id']);
374
-                        $table->addUniqueIndex(['id']);
375
-
376
-		}
377
-
378
-
379
-		if (!$schema->hasTable('sms_relent_restrict')) {
380
-			$table = $schema->createTable('sms_relent_restrict');
381
-			$table->addColumn('id', Types::BIGINT, [
382
-				'autoincrement' => true,
383
-				'notnull' => true,
384
-                                'length' => 11,
385
-                                'unsigned' => true,
386
-			]);
387
-			$table->addColumn('user_id', Types::STRING, [
388
-				'notnull' => true,
389
-				'length' => 128,
390
-			]);
391
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
-				'notnull' => true,
393
-				'length' => 255,
394
-			]);
395
-			$table->addColumn('phone_number', Types::STRING, [
396
-				'notnull' => true,
397
-				'length' => 128,
398
-			]);
399
-			$table->addColumn('groups', Types::STRING, [
400
-				'notnull' => true,
401
-				'length' => 2048,
402
-			]);
403
-			$table->addColumn('users', Types::STRING, [
404
-				'notnull' => true,
405
-				'length' => 2048,
406
-			]);
407
-                        $table->setPrimaryKey(['id']);
408
-                        $table->addUniqueIndex(['id']);
409
-
410
-		}
411
-
412
-		return $schema;
413
-	}
414
-
415
-        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
-
417
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
418
-                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
419
-	        $getrecfromnbres = $getrecfromnb->execute();
420
-
421
-                $recdatauids = [];
422
-                $idsent = [];
423
-                while ($rowfetched = $getrecfromnbres->fetch()) {
424
-                       $recdatauids[] = $rowfetched['user_id'];
425
-                       $idsent[] = $rowfetched['id'];
426
-                }
427
-                $getrecfromnbres->closeCursor();
428
-
429
-                if ($recdatauids) {
430
-
431
-                    $recuids = array_values(array_unique($recdatauids));
432
-                    $acdatausrdn = [];
433
-
434
-                    foreach ($recuids as $dnkey => $dnvalue) {
435
-		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
436
-			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
437
-
438
-			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
439
-				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
440
-			     }
441
-			     $getacdatadnres->closeCursor();
442
-                    }
443
-
444
-                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
445
-
446
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
447
-			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
448
-			     $updaterecmsres->closeCursor();
449
-                    }
450
-                }
451
-
452
-
453
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
454
-                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
455
-	        $getrecfromnbres = $getrecfromnb->execute();
456
-
457
-                $recdatanmbrs = [];
458
-                $idsrc = [];
459
-                $daterec = [];
460
-                while ($rowfetched = $getrecfromnbres->fetch()) {
461
-                       $recdatanmbrs[] = $rowfetched['from'];
462
-                       $idsrc[] = $rowfetched['id'];
463
-                       $daterecarr = explode(":", $rowfetched['date']);
464
-                       $daterec[] = $daterecarr[0];
465
-                }
466
-                $getrecfromnbres->closeCursor();
467
-
468
-                if ($recdatanmbrs) {
469
-
470
-                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
471
-
472
-			     $authorDisplayNm = '';
473
-			     $internalSender = 0;
474
-
475
-			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
476
-			     $recmsgfromprc = '%' . $rcvalue;
477
-                             $recdataprc = $daterec[$rckey] . '%';
478
-			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
479
-			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
480
-
481
-			     $dispnamearr = [];
482
-			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
483
-				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
484
-			     }
485
-			     $getdspnmstres->closeCursor();
486
-
487
-			     if ($dispnamearr) {
488
-				 $descdspnmarr = array_reverse($dispnamearr);
489
-				 $authorDisplayNm = $descdspnmarr[0];
490
-				 $internalSender = 1;
491
-			     } else { $authorDisplayNm = ''; $internalSender = 0; }
492
-
493
-                             $pdpkeyprc = '%' . $rcvalue;
494
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
495
-                                                                        WHERE `from` LIKE ? AND `id` = ?');
496
-			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $pdpkeyprc, $idsrc[$rckey]]);
497
-			     $updaterecmsres->closeCursor();
498
-                    }
499
-                }
500
-
501
-                return null;
502
-        }
503
-
504
-}
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,504 @@
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 Version116Date20230508212745 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
+		} else {
188
+
189
+                        $table = $schema->getTable('sms_relent_settings');
190
+
191
+			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
+				'notnull' => false,
193
+				'length' => 1,
194
+			]);
195
+			$table->addColumn('show_display_names', Types::SMALLINT, [
196
+				'notnull' => false,
197
+				'length' => 1,
198
+			]);
199
+                }
200
+
201
+
202
+		if (!$schema->hasTable('sms_relent_received')) {
203
+			$table = $schema->createTable('sms_relent_received');
204
+			$table->addColumn('id', Types::BIGINT, [
205
+				'autoincrement' => true,
206
+				'notnull' => true,
207
+                                'length' => 11,
208
+                                'unsigned' => true,
209
+			]);
210
+			$table->addColumn('user_id', Types::STRING, [
211
+				'notnull' => true,
212
+				'length' => 64,
213
+			]);
214
+			$table->addColumn('message_id', Types::STRING, [
215
+				'notnull' => true,
216
+				'length' => 512,
217
+			]);
218
+			$table->addColumn('date', Types::DATETIME, [
219
+				'notnull' => true,
220
+			]);
221
+			$table->addColumn('from', Types::STRING, [
222
+				'notnull' => true,
223
+				'length' => 128,
224
+			]);
225
+			$table->addColumn('to', Types::STRING, [
226
+				'notnull' => true,
227
+				'length' => 128,
228
+			]);
229
+			$table->addColumn('message', Types::TEXT, [
230
+				'notnull' => false,
231
+				'default' => '',
232
+			]);
233
+			$table->addColumn('author_displayname', Types::STRING, [
234
+				'notnull' => true,
235
+				'length' => 255,
236
+			]);
237
+			$table->addColumn('internal_sender', Types::SMALLINT, [
238
+				'notnull' => false,
239
+				'length' => 1,
240
+			]);
241
+                        $table->setPrimaryKey(['id']);
242
+                        $table->addUniqueIndex(['id']);
243
+
244
+		} else {
245
+
246
+                        $table = $schema->getTable('sms_relent_received');
247
+
248
+			$table->addColumn('author_displayname', Types::STRING, [
249
+				'notnull' => true,
250
+				'length' => 255,
251
+			]);
252
+			$table->addColumn('internal_sender', Types::SMALLINT, [
253
+				'notnull' => false,
254
+				'length' => 1,
255
+			]);
256
+                }
257
+
258
+
259
+		if (!$schema->hasTable('sms_relent_sent')) {
260
+			$table = $schema->createTable('sms_relent_sent');
261
+			$table->addColumn('id', Types::BIGINT, [
262
+				'autoincrement' => true,
263
+				'notnull' => true,
264
+                                'length' => 11,
265
+                                'unsigned' => true,
266
+			]);
267
+			$table->addColumn('user_id', Types::STRING, [
268
+				'notnull' => true,
269
+				'length' => 64,
270
+			]);
271
+			$table->addColumn('message_id', Types::STRING, [
272
+				'notnull' => true,
273
+				'length' => 512,
274
+			]);
275
+			$table->addColumn('date', Types::DATETIME, [
276
+				'notnull' => true,
277
+			]);
278
+			$table->addColumn('from', Types::STRING, [
279
+				'notnull' => true,
280
+				'length' => 128,
281
+			]);
282
+			$table->addColumn('to', Types::STRING, [
283
+				'notnull' => true,
284
+				'length' => 128,
285
+			]);
286
+			$table->addColumn('network ', Types::STRING, [
287
+				'notnull' => false,
288
+				'length' => 64,
289
+				'default' => '',
290
+			]);
291
+			$table->addColumn('price', Types::STRING, [
292
+				'notnull' => false,
293
+				'length' => 64,
294
+				'default' => '',
295
+			]);
296
+			$table->addColumn('status', Types::STRING, [
297
+				'notnull' => false,
298
+				'length' => 512,
299
+				'default' => '',
300
+			]);
301
+			$table->addColumn('deliveryreceipt', Types::STRING, [
302
+				'notnull' => false,
303
+				'length' => 64,
304
+				'default' => '',
305
+			]);
306
+			$table->addColumn('message', Types::TEXT, [
307
+				'notnull' => false,
308
+                                'default' => '',
309
+			]);
310
+			$table->addColumn('author_displayname', Types::STRING, [
311
+				'notnull' => true,
312
+				'length' => 255,
313
+			]);
314
+                        $table->setPrimaryKey(['id']);
315
+                        $table->addUniqueIndex(['id']);
316
+
317
+		} else {
318
+
319
+                        $table = $schema->getTable('sms_relent_sent');
320
+
321
+			$table->addColumn('author_displayname', Types::STRING, [
322
+				'notnull' => true,
323
+				'length' => 255,
324
+			]);
325
+                }
326
+
327
+
328
+		if (!$schema->hasTable('sms_relent_autorply')) {
329
+			$table = $schema->createTable('sms_relent_autorply');
330
+			$table->addColumn('id', Types::BIGINT, [
331
+				'autoincrement' => true,
332
+				'notnull' => true,
333
+                                'length' => 11,
334
+                                'unsigned' => true,
335
+			]);
336
+			$table->addColumn('user_id', Types::STRING, [
337
+				'notnull' => true,
338
+				'length' => 128,
339
+			]);
340
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
+				'notnull' => true,
342
+				'length' => 255,
343
+			]);
344
+			$table->addColumn('phone_number', Types::STRING, [
345
+				'notnull' => true,
346
+				'length' => 128,
347
+			]);
348
+			$table->addColumn('days_of_week', Types::STRING, [
349
+				'notnull' => false,
350
+				'length' => 64,
351
+                                'default' => '',
352
+			]);
353
+			$table->addColumn('daily_start', Types::STRING, [
354
+				'notnull' => false,
355
+				'length' => 8,
356
+                                'default' => '',
357
+			]);
358
+			$table->addColumn('daily_end', Types::STRING, [
359
+				'notnull' => false,
360
+				'length' => 8,
361
+                                'default' => '',
362
+			]);
363
+			$table->addColumn('vacation_start', Types::DATETIME, [
364
+				'notnull' => false,
365
+			]);
366
+			$table->addColumn('vacation_end', Types::DATETIME, [
367
+				'notnull' => false,
368
+			]);
369
+			$table->addColumn('message_text', Types::TEXT, [
370
+				'notnull' => false,
371
+                                'default' => '',
372
+			]);
373
+                        $table->setPrimaryKey(['id']);
374
+                        $table->addUniqueIndex(['id']);
375
+
376
+		}
377
+
378
+
379
+		if (!$schema->hasTable('sms_relent_restrict')) {
380
+			$table = $schema->createTable('sms_relent_restrict');
381
+			$table->addColumn('id', Types::BIGINT, [
382
+				'autoincrement' => true,
383
+				'notnull' => true,
384
+                                'length' => 11,
385
+                                'unsigned' => true,
386
+			]);
387
+			$table->addColumn('user_id', Types::STRING, [
388
+				'notnull' => true,
389
+				'length' => 128,
390
+			]);
391
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
+				'notnull' => true,
393
+				'length' => 255,
394
+			]);
395
+			$table->addColumn('phone_number', Types::STRING, [
396
+				'notnull' => true,
397
+				'length' => 128,
398
+			]);
399
+			$table->addColumn('groups', Types::STRING, [
400
+				'notnull' => true,
401
+				'length' => 2048,
402
+			]);
403
+			$table->addColumn('users', Types::STRING, [
404
+				'notnull' => true,
405
+				'length' => 2048,
406
+			]);
407
+                        $table->setPrimaryKey(['id']);
408
+                        $table->addUniqueIndex(['id']);
409
+
410
+		}
411
+
412
+		return $schema;
413
+	}
414
+
415
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
+
417
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
418
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `user_id` FROM `*PREFIX*sms_relent_sent`');
419
+	        $getrecfromnbres = $getrecfromnb->execute();
420
+
421
+                $recdatauids = [];
422
+                $idsent = [];
423
+                while ($rowfetched = $getrecfromnbres->fetch()) {
424
+                       $recdatauids[] = $rowfetched['user_id'];
425
+                       $idsent[] = $rowfetched['id'];
426
+                }
427
+                $getrecfromnbres->closeCursor();
428
+
429
+                if ($recdatauids) {
430
+
431
+                    $recuids = array_values(array_unique($recdatauids));
432
+                    $acdatausrdn = [];
433
+
434
+                    foreach ($recuids as $dnkey => $dnvalue) {
435
+		             $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
436
+			     $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
437
+
438
+			     while ($acusrdnfetched = $getacdatadnres->fetch()) {
439
+				    $acdatausrdn[$dnvalue] = $acusrdnfetched['value'];
440
+			     }
441
+			     $getacdatadnres->closeCursor();
442
+                    }
443
+
444
+                    foreach ($recdatauids as $pdpkey => $pdpvalue) {
445
+
446
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `user_id` = ? AND `id` = ?');
447
+			     $updaterecmsres = $updaterecms->execute([$acdatausrdn[$pdpvalue], $pdpvalue, $idsent[$pdpkey]]);
448
+			     $updaterecmsres->closeCursor();
449
+                    }
450
+                }
451
+
452
+
453
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
454
+                $getrecfromnb = $this->connection->prepare('SELECT `id`, `date`, `from` FROM `*PREFIX*sms_relent_received`');
455
+	        $getrecfromnbres = $getrecfromnb->execute();
456
+
457
+                $recdatanmbrs = [];
458
+                $idsrc = [];
459
+                $daterec = [];
460
+                while ($rowfetched = $getrecfromnbres->fetch()) {
461
+                       $recdatanmbrs[] = $rowfetched['from'];
462
+                       $idsrc[] = $rowfetched['id'];
463
+                       $daterecarr = explode(":", $rowfetched['date']);
464
+                       $daterec[] = $daterecarr[0];
465
+                }
466
+                $getrecfromnbres->closeCursor();
467
+
468
+                if ($recdatanmbrs) {
469
+
470
+                    foreach ($recdatanmbrs as $rckey => $rcvalue) {
471
+
472
+			     $authorDisplayNm = '';
473
+			     $internalSender = 0;
474
+
475
+			     // Search for the associated Display Name in the previous messages sent from the same phone number, in the 'sms_relent_sent' table
476
+			     $recmsgfromprc = '%' . $rcvalue;
477
+                             $recdataprc = $daterec[$rckey] . '%';
478
+			     $getdspnmst = $this->connection->prepare('SELECT `date`, `from`, `author_displayname` FROM `*PREFIX*sms_relent_sent` WHERE `from` LIKE ? AND `date` LIKE ?');
479
+			     $getdspnmstres = $getdspnmst->execute([$recmsgfromprc, $recdataprc]);
480
+
481
+			     $dispnamearr = [];
482
+			     while ($dspnmstfetched = $getdspnmstres->fetch()) {
483
+				    $dispnamearr[] = $dspnmstfetched['author_displayname'];
484
+			     }
485
+			     $getdspnmstres->closeCursor();
486
+
487
+			     if ($dispnamearr) {
488
+				 $descdspnmarr = array_reverse($dispnamearr);
489
+				 $authorDisplayNm = $descdspnmarr[0];
490
+				 $internalSender = 1;
491
+			     } else { $authorDisplayNm = ''; $internalSender = 0; }
492
+
493
+                             $pdpkeyprc = '%' . $rcvalue;
494
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ?
495
+                                                                        WHERE `from` LIKE ? AND `id` = ?');
496
+			     $updaterecmsres = $updaterecms->execute([$authorDisplayNm, $internalSender, $pdpkeyprc, $idsrc[$rckey]]);
497
+			     $updaterecmsres->closeCursor();
498
+                    }
499
+                }
500
+
501
+                return null;
502
+        }
503
+
504
+}
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,570 +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 Version116Date20230508212745 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
-		} else {
188
-
189
-                        $table = $schema->getTable('sms_relent_settings');
190
-
191
-			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
-				'notnull' => false,
193
-				'length' => 1,
194
-			]);
195
-			$table->addColumn('show_display_names', Types::SMALLINT, [
196
-				'notnull' => false,
197
-				'length' => 1,
198
-			]);
199
-                }
200
-
201
-
202
-		if (!$schema->hasTable('sms_relent_received')) {
203
-			$table = $schema->createTable('sms_relent_received');
204
-			$table->addColumn('id', Types::BIGINT, [
205
-				'autoincrement' => true,
206
-				'notnull' => true,
207
-                                'length' => 11,
208
-                                'unsigned' => true,
209
-			]);
210
-			$table->addColumn('user_id', Types::STRING, [
211
-				'notnull' => true,
212
-				'length' => 64,
213
-			]);
214
-			$table->addColumn('message_id', Types::STRING, [
215
-				'notnull' => true,
216
-				'length' => 512,
217
-			]);
218
-			$table->addColumn('date', Types::DATETIME, [
219
-				'notnull' => true,
220
-			]);
221
-			$table->addColumn('from', Types::STRING, [
222
-				'notnull' => true,
223
-				'length' => 128,
224
-			]);
225
-			$table->addColumn('to', Types::STRING, [
226
-				'notnull' => true,
227
-				'length' => 128,
228
-			]);
229
-			$table->addColumn('message', Types::TEXT, [
230
-				'notnull' => false,
231
-				'default' => '',
232
-			]);
233
-			$table->addColumn('author_displayname', Types::STRING, [
234
-				'notnull' => true,
235
-				'length' => 255,
236
-			]);
237
-			$table->addColumn('internal_sender', Types::SMALLINT, [
238
-				'notnull' => false,
239
-				'length' => 1,
240
-			]);
241
-                        $table->setPrimaryKey(['id']);
242
-                        $table->addUniqueIndex(['id']);
243
-
244
-		} else {
245
-
246
-                        $table = $schema->getTable('sms_relent_received');
247
-
248
-			$table->addColumn('author_displayname', Types::STRING, [
249
-				'notnull' => true,
250
-				'length' => 255,
251
-			]);
252
-			$table->addColumn('internal_sender', Types::SMALLINT, [
253
-				'notnull' => false,
254
-				'length' => 1,
255
-			]);
256
-                }
257
-
258
-
259
-		if (!$schema->hasTable('sms_relent_sent')) {
260
-			$table = $schema->createTable('sms_relent_sent');
261
-			$table->addColumn('id', Types::BIGINT, [
262
-				'autoincrement' => true,
263
-				'notnull' => true,
264
-                                'length' => 11,
265
-                                'unsigned' => true,
266
-			]);
267
-			$table->addColumn('user_id', Types::STRING, [
268
-				'notnull' => true,
269
-				'length' => 64,
270
-			]);
271
-			$table->addColumn('message_id', Types::STRING, [
272
-				'notnull' => true,
273
-				'length' => 512,
274
-			]);
275
-			$table->addColumn('date', Types::DATETIME, [
276
-				'notnull' => true,
277
-			]);
278
-			$table->addColumn('from', Types::STRING, [
279
-				'notnull' => true,
280
-				'length' => 128,
281
-			]);
282
-			$table->addColumn('to', Types::STRING, [
283
-				'notnull' => true,
284
-				'length' => 128,
285
-			]);
286
-			$table->addColumn('network ', Types::STRING, [
287
-				'notnull' => false,
288
-				'length' => 64,
289
-				'default' => '',
290
-			]);
291
-			$table->addColumn('price', Types::STRING, [
292
-				'notnull' => false,
293
-				'length' => 64,
294
-				'default' => '',
295
-			]);
296
-			$table->addColumn('status', Types::STRING, [
297
-				'notnull' => false,
298
-				'length' => 512,
299
-				'default' => '',
300
-			]);
301
-			$table->addColumn('deliveryreceipt', Types::STRING, [
302
-				'notnull' => false,
303
-				'length' => 64,
304
-				'default' => '',
305
-			]);
306
-			$table->addColumn('message', Types::TEXT, [
307
-				'notnull' => false,
308
-                                'default' => '',
309
-			]);
310
-			$table->addColumn('author_displayname', Types::STRING, [
311
-				'notnull' => true,
312
-				'length' => 255,
313
-			]);
314
-                        $table->setPrimaryKey(['id']);
315
-                        $table->addUniqueIndex(['id']);
316
-
317
-		} else {
318
-
319
-                        $table = $schema->getTable('sms_relent_sent');
320
-
321
-			$table->addColumn('author_displayname', Types::STRING, [
322
-				'notnull' => true,
323
-				'length' => 255,
324
-			]);
325
-                }
326
-
327
-
328
-		if (!$schema->hasTable('sms_relent_autorply')) {
329
-			$table = $schema->createTable('sms_relent_autorply');
330
-			$table->addColumn('id', Types::BIGINT, [
331
-				'autoincrement' => true,
332
-				'notnull' => true,
333
-                                'length' => 11,
334
-                                'unsigned' => true,
335
-			]);
336
-			$table->addColumn('user_id', Types::STRING, [
337
-				'notnull' => true,
338
-				'length' => 128,
339
-			]);
340
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
-				'notnull' => true,
342
-				'length' => 255,
343
-			]);
344
-			$table->addColumn('phone_number', Types::STRING, [
345
-				'notnull' => true,
346
-				'length' => 128,
347
-			]);
348
-			$table->addColumn('days_of_week', Types::STRING, [
349
-				'notnull' => false,
350
-				'length' => 64,
351
-                                'default' => '',
352
-			]);
353
-			$table->addColumn('daily_start', Types::STRING, [
354
-				'notnull' => false,
355
-				'length' => 8,
356
-                                'default' => '',
357
-			]);
358
-			$table->addColumn('daily_end', Types::STRING, [
359
-				'notnull' => false,
360
-				'length' => 8,
361
-                                'default' => '',
362
-			]);
363
-			$table->addColumn('vacation_start', Types::DATETIME, [
364
-				'notnull' => false,
365
-			]);
366
-			$table->addColumn('vacation_end', Types::DATETIME, [
367
-				'notnull' => false,
368
-			]);
369
-			$table->addColumn('message_text', Types::TEXT, [
370
-				'notnull' => false,
371
-                                'default' => '',
372
-			]);
373
-                        $table->setPrimaryKey(['id']);
374
-                        $table->addUniqueIndex(['id']);
375
-
376
-		}
377
-
378
-
379
-		if (!$schema->hasTable('sms_relent_restrict')) {
380
-			$table = $schema->createTable('sms_relent_restrict');
381
-			$table->addColumn('id', Types::BIGINT, [
382
-				'autoincrement' => true,
383
-				'notnull' => true,
384
-                                'length' => 11,
385
-                                'unsigned' => true,
386
-			]);
387
-			$table->addColumn('user_id', Types::STRING, [
388
-				'notnull' => true,
389
-				'length' => 128,
390
-			]);
391
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
-				'notnull' => true,
393
-				'length' => 255,
394
-			]);
395
-			$table->addColumn('phone_number', Types::STRING, [
396
-				'notnull' => true,
397
-				'length' => 128,
398
-			]);
399
-			$table->addColumn('groups', Types::STRING, [
400
-				'notnull' => true,
401
-				'length' => 2048,
402
-			]);
403
-			$table->addColumn('users', Types::STRING, [
404
-				'notnull' => true,
405
-				'length' => 2048,
406
-			]);
407
-                        $table->setPrimaryKey(['id']);
408
-                        $table->addUniqueIndex(['id']);
409
-
410
-		}
411
-
412
-		return $schema;
413
-	}
414
-
415
-        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
-
417
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
418
-                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
419
-	        $getrecfromnbres = $getrecfromnb->execute();
420
-
421
-                $recdatanmbrs = [];
422
-                while ($rowfetched = $getrecfromnbres->fetch()) {
423
-                       $recdatanmbrs[] = $rowfetched['from'];
424
-                }
425
-                $getrecfromnbres->closeCursor();
426
-
427
-                if ($recdatanmbrs) {
428
-
429
-                    $recnmbrs = array_values(array_unique($recdatanmbrs));
430
-
431
-                    $phoneDisplayPairs = [];
432
-                    foreach ($recnmbrs as $rckey => $rcvalue) {
433
-
434
-                         $rcvalueprc = '%' . $rcvalue;
435
-                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
436
-	                 $getacdatares = $getacdata->execute(['phone', $rcvalueprc]);
437
-
438
-		         $acdatausers = [];
439
-		         while ($acusrfetched = $getacdatares->fetch()) {
440
-		                $acdatausers[] = $acusrfetched['uid'];
441
-		         }
442
-		         $getacdatares->closeCursor();
443
-
444
-
445
-                         if ($acdatausers) {
446
-
447
-		             $acdatausrdn = [];
448
-                             foreach ($acdatausers as $dnkey => $dnvalue) {
449
-
450
-		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
451
-			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
452
-
453
-				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
454
-				         $acdatausrdn[] = $acusrdnfetched['value'];
455
-				  }
456
-				  $getacdatadnres->closeCursor();
457
-                             }
458
-
459
-                             if ($acdatausrdn) {
460
-
461
-                                 if (count($acdatausrdn) == 1) {
462
-
463
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
464
-
465
-                                 } elseif (count($acdatausrdn) > 1) {
466
-
467
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
468
-                                 }
469
-
470
-                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
471
-
472
-                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
473
-                    }
474
-
475
-                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
476
-
477
-                         if (is_array($pdpvalue)) {
478
-                             $pdpkeyprc = '%' . $pdpkey;
479
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?');
480
-			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]);
481
-			     $updaterecmsres->closeCursor();
482
-                         }
483
-                    }
484
-                }
485
-
486
-
487
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
488
-                $getsentfromnb = $this->connection->prepare('SELECT `user_id`, `from` FROM `*PREFIX*sms_relent_sent`');
489
-	        $getsentfromnbres = $getsentfromnb->execute();
490
-
491
-                $sentdatanmbrs = [];
492
-                $sentdatanmbrsusr = [];
493
-                while ($rowfetchedst = $getsentfromnbres->fetch()) {
494
-
495
-                       $sentdatanmbrspre = $rowfetchedst['from'];
496
-                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
497
-                       if (count($sentdatanmbrsarr) > 1) {
498
-                           $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
499
-                           $sentdatanmbrsusr[] = $rowfetchedst['user_id'];
500
-                       } else {
501
-                           $sentdatanmbrs[] = $sentdatanmbrsarr[0];
502
-                           $sentdatanmbrsusr[] = $rowfetchedst['user_id'];
503
-                       }
504
-                }
505
-                $getsentfromnbres->closeCursor();
506
-
507
-                if ($sentdatanmbrs && $sentdatanmbrsusr) {
508
-
509
-                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
510
-
511
-                    $phoneDisplayPairsst = [];
512
-
513
-	            $acdatausrdnst = [];
514
-                    for ($k = 0; $k < count($sentnmbrs); $k++) {
515
-
516
-                         $nmbusernames = [];
517
-                         for ($j = 0; $j < count($sentdatanmbrs); $j++) {
518
-                              if ($sentnmbrs[$k] == $sentdatanmbrs[$j]) {                                  
519
-                                  $nmbusernames[] = $sentdatanmbrsusr[$j];
520
-                              }
521
-                         }
522
-                         $acdatausrdnst[$sentnmbrs[$k]] = $nmbusernames;
523
-                    }
524
-
525
-                    foreach ($acdatausrdnst as $ukey => $uvalue) {
526
-
527
-                         if (is_array($uvalue)) {
528
-
529
-                             $dispnamearr = [];
530
-                             foreach ($uvalue as $dskey => $dsvalue) {
531
-			              $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
532
-				      $getacdatadnstres = $getacdatadnst->execute([$dsvalue, 'displayname']);
533
-		                      $fetchdspname = $getacdatadnstres->fetch();                              
534
-
535
-		                      if ($fetchdspname) {
536
-		                          $dispnamearr[] = $fetchdspname['value']];
537
-		                      }
538
-				      $getacdatadnstres->closeCursor();
539
-                             }
540
-
541
-	                     if ($dispnamearr) {
542
-
543
-	                         if (count($dispnamearr) == 1) {
544
-
545
-	                             $phoneDisplayPairsst[$ukey] = ['author_displayname' => $dispnamearr[0]];
546
-
547
-	                         } elseif (count($dispnamearr) > 1) {
548
-
549
-	                             $phoneDisplayPairsst[$ukey] = ['author_displayname' => implode("/", $dispnamearr)];
550
-	                         }
551
-
552
-	                     } else { $phoneDisplayPairsst[$ukey] = ['author_displayname' => '']; }
553
-                         }
554
-                    }
555
-
556
-                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
557
-
558
-                         if (is_array($pstvalue)) {
559
-                             $contfield = "%" . $pstkey;
560
-			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
561
-			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
562
-			     $updatesentmsres->closeCursor();
563
-                         }
564
-                    }
565
-                }
566
-
567
-                return null;
568
-        }
569
-
570
-}
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,570 @@
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 Version116Date20230508212745 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
+		} else {
188
+
189
+                        $table = $schema->getTable('sms_relent_settings');
190
+
191
+			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
+				'notnull' => false,
193
+				'length' => 1,
194
+			]);
195
+			$table->addColumn('show_display_names', Types::SMALLINT, [
196
+				'notnull' => false,
197
+				'length' => 1,
198
+			]);
199
+                }
200
+
201
+
202
+		if (!$schema->hasTable('sms_relent_received')) {
203
+			$table = $schema->createTable('sms_relent_received');
204
+			$table->addColumn('id', Types::BIGINT, [
205
+				'autoincrement' => true,
206
+				'notnull' => true,
207
+                                'length' => 11,
208
+                                'unsigned' => true,
209
+			]);
210
+			$table->addColumn('user_id', Types::STRING, [
211
+				'notnull' => true,
212
+				'length' => 64,
213
+			]);
214
+			$table->addColumn('message_id', Types::STRING, [
215
+				'notnull' => true,
216
+				'length' => 512,
217
+			]);
218
+			$table->addColumn('date', Types::DATETIME, [
219
+				'notnull' => true,
220
+			]);
221
+			$table->addColumn('from', Types::STRING, [
222
+				'notnull' => true,
223
+				'length' => 128,
224
+			]);
225
+			$table->addColumn('to', Types::STRING, [
226
+				'notnull' => true,
227
+				'length' => 128,
228
+			]);
229
+			$table->addColumn('message', Types::TEXT, [
230
+				'notnull' => false,
231
+				'default' => '',
232
+			]);
233
+			$table->addColumn('author_displayname', Types::STRING, [
234
+				'notnull' => true,
235
+				'length' => 255,
236
+			]);
237
+			$table->addColumn('internal_sender', Types::SMALLINT, [
238
+				'notnull' => false,
239
+				'length' => 1,
240
+			]);
241
+                        $table->setPrimaryKey(['id']);
242
+                        $table->addUniqueIndex(['id']);
243
+
244
+		} else {
245
+
246
+                        $table = $schema->getTable('sms_relent_received');
247
+
248
+			$table->addColumn('author_displayname', Types::STRING, [
249
+				'notnull' => true,
250
+				'length' => 255,
251
+			]);
252
+			$table->addColumn('internal_sender', Types::SMALLINT, [
253
+				'notnull' => false,
254
+				'length' => 1,
255
+			]);
256
+                }
257
+
258
+
259
+		if (!$schema->hasTable('sms_relent_sent')) {
260
+			$table = $schema->createTable('sms_relent_sent');
261
+			$table->addColumn('id', Types::BIGINT, [
262
+				'autoincrement' => true,
263
+				'notnull' => true,
264
+                                'length' => 11,
265
+                                'unsigned' => true,
266
+			]);
267
+			$table->addColumn('user_id', Types::STRING, [
268
+				'notnull' => true,
269
+				'length' => 64,
270
+			]);
271
+			$table->addColumn('message_id', Types::STRING, [
272
+				'notnull' => true,
273
+				'length' => 512,
274
+			]);
275
+			$table->addColumn('date', Types::DATETIME, [
276
+				'notnull' => true,
277
+			]);
278
+			$table->addColumn('from', Types::STRING, [
279
+				'notnull' => true,
280
+				'length' => 128,
281
+			]);
282
+			$table->addColumn('to', Types::STRING, [
283
+				'notnull' => true,
284
+				'length' => 128,
285
+			]);
286
+			$table->addColumn('network ', Types::STRING, [
287
+				'notnull' => false,
288
+				'length' => 64,
289
+				'default' => '',
290
+			]);
291
+			$table->addColumn('price', Types::STRING, [
292
+				'notnull' => false,
293
+				'length' => 64,
294
+				'default' => '',
295
+			]);
296
+			$table->addColumn('status', Types::STRING, [
297
+				'notnull' => false,
298
+				'length' => 512,
299
+				'default' => '',
300
+			]);
301
+			$table->addColumn('deliveryreceipt', Types::STRING, [
302
+				'notnull' => false,
303
+				'length' => 64,
304
+				'default' => '',
305
+			]);
306
+			$table->addColumn('message', Types::TEXT, [
307
+				'notnull' => false,
308
+                                'default' => '',
309
+			]);
310
+			$table->addColumn('author_displayname', Types::STRING, [
311
+				'notnull' => true,
312
+				'length' => 255,
313
+			]);
314
+                        $table->setPrimaryKey(['id']);
315
+                        $table->addUniqueIndex(['id']);
316
+
317
+		} else {
318
+
319
+                        $table = $schema->getTable('sms_relent_sent');
320
+
321
+			$table->addColumn('author_displayname', Types::STRING, [
322
+				'notnull' => true,
323
+				'length' => 255,
324
+			]);
325
+                }
326
+
327
+
328
+		if (!$schema->hasTable('sms_relent_autorply')) {
329
+			$table = $schema->createTable('sms_relent_autorply');
330
+			$table->addColumn('id', Types::BIGINT, [
331
+				'autoincrement' => true,
332
+				'notnull' => true,
333
+                                'length' => 11,
334
+                                'unsigned' => true,
335
+			]);
336
+			$table->addColumn('user_id', Types::STRING, [
337
+				'notnull' => true,
338
+				'length' => 128,
339
+			]);
340
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
+				'notnull' => true,
342
+				'length' => 255,
343
+			]);
344
+			$table->addColumn('phone_number', Types::STRING, [
345
+				'notnull' => true,
346
+				'length' => 128,
347
+			]);
348
+			$table->addColumn('days_of_week', Types::STRING, [
349
+				'notnull' => false,
350
+				'length' => 64,
351
+                                'default' => '',
352
+			]);
353
+			$table->addColumn('daily_start', Types::STRING, [
354
+				'notnull' => false,
355
+				'length' => 8,
356
+                                'default' => '',
357
+			]);
358
+			$table->addColumn('daily_end', Types::STRING, [
359
+				'notnull' => false,
360
+				'length' => 8,
361
+                                'default' => '',
362
+			]);
363
+			$table->addColumn('vacation_start', Types::DATETIME, [
364
+				'notnull' => false,
365
+			]);
366
+			$table->addColumn('vacation_end', Types::DATETIME, [
367
+				'notnull' => false,
368
+			]);
369
+			$table->addColumn('message_text', Types::TEXT, [
370
+				'notnull' => false,
371
+                                'default' => '',
372
+			]);
373
+                        $table->setPrimaryKey(['id']);
374
+                        $table->addUniqueIndex(['id']);
375
+
376
+		}
377
+
378
+
379
+		if (!$schema->hasTable('sms_relent_restrict')) {
380
+			$table = $schema->createTable('sms_relent_restrict');
381
+			$table->addColumn('id', Types::BIGINT, [
382
+				'autoincrement' => true,
383
+				'notnull' => true,
384
+                                'length' => 11,
385
+                                'unsigned' => true,
386
+			]);
387
+			$table->addColumn('user_id', Types::STRING, [
388
+				'notnull' => true,
389
+				'length' => 128,
390
+			]);
391
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
+				'notnull' => true,
393
+				'length' => 255,
394
+			]);
395
+			$table->addColumn('phone_number', Types::STRING, [
396
+				'notnull' => true,
397
+				'length' => 128,
398
+			]);
399
+			$table->addColumn('groups', Types::STRING, [
400
+				'notnull' => true,
401
+				'length' => 2048,
402
+			]);
403
+			$table->addColumn('users', Types::STRING, [
404
+				'notnull' => true,
405
+				'length' => 2048,
406
+			]);
407
+                        $table->setPrimaryKey(['id']);
408
+                        $table->addUniqueIndex(['id']);
409
+
410
+		}
411
+
412
+		return $schema;
413
+	}
414
+
415
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
+
417
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before the upgrade
418
+                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
419
+	        $getrecfromnbres = $getrecfromnb->execute();
420
+
421
+                $recdatanmbrs = [];
422
+                while ($rowfetched = $getrecfromnbres->fetch()) {
423
+                       $recdatanmbrs[] = $rowfetched['from'];
424
+                }
425
+                $getrecfromnbres->closeCursor();
426
+
427
+                if ($recdatanmbrs) {
428
+
429
+                    $recnmbrs = array_values(array_unique($recdatanmbrs));
430
+
431
+                    $phoneDisplayPairs = [];
432
+                    foreach ($recnmbrs as $rckey => $rcvalue) {
433
+
434
+                         $rcvalueprc = '%' . $rcvalue;
435
+                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
436
+	                 $getacdatares = $getacdata->execute(['phone', $rcvalueprc]);
437
+
438
+		         $acdatausers = [];
439
+		         while ($acusrfetched = $getacdatares->fetch()) {
440
+		                $acdatausers[] = $acusrfetched['uid'];
441
+		         }
442
+		         $getacdatares->closeCursor();
443
+
444
+
445
+                         if ($acdatausers) {
446
+
447
+		             $acdatausrdn = [];
448
+                             foreach ($acdatausers as $dnkey => $dnvalue) {
449
+
450
+		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
451
+			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
452
+
453
+				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
454
+				         $acdatausrdn[] = $acusrdnfetched['value'];
455
+				  }
456
+				  $getacdatadnres->closeCursor();
457
+                             }
458
+
459
+                             if ($acdatausrdn) {
460
+
461
+                                 if (count($acdatausrdn) == 1) {
462
+
463
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
464
+
465
+                                 } elseif (count($acdatausrdn) > 1) {
466
+
467
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
468
+                                 }
469
+
470
+                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
471
+
472
+                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
473
+                    }
474
+
475
+                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
476
+
477
+                         if (is_array($pdpvalue)) {
478
+                             $pdpkeyprc = '%' . $pdpkey;
479
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` LIKE ?');
480
+			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkeyprc]);
481
+			     $updaterecmsres->closeCursor();
482
+                         }
483
+                    }
484
+                }
485
+
486
+
487
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before the upgrade
488
+                $getsentfromnb = $this->connection->prepare('SELECT `user_id`, `from` FROM `*PREFIX*sms_relent_sent`');
489
+	        $getsentfromnbres = $getsentfromnb->execute();
490
+
491
+                $sentdatanmbrs = [];
492
+                $sentdatanmbrsusr = [];
493
+                while ($rowfetchedst = $getsentfromnbres->fetch()) {
494
+
495
+                       $sentdatanmbrspre = $rowfetchedst['from'];
496
+                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
497
+                       if (count($sentdatanmbrsarr) > 1) {
498
+                           $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
499
+                           $sentdatanmbrsusr[] = $rowfetchedst['user_id'];
500
+                       } else {
501
+                           $sentdatanmbrs[] = $sentdatanmbrsarr[0];
502
+                           $sentdatanmbrsusr[] = $rowfetchedst['user_id'];
503
+                       }
504
+                }
505
+                $getsentfromnbres->closeCursor();
506
+
507
+                if ($sentdatanmbrs && $sentdatanmbrsusr) {
508
+
509
+                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
510
+
511
+                    $phoneDisplayPairsst = [];
512
+
513
+	            $acdatausrdnst = [];
514
+                    for ($k = 0; $k < count($sentnmbrs); $k++) {
515
+
516
+                         $nmbusernames = [];
517
+                         for ($j = 0; $j < count($sentdatanmbrs); $j++) {
518
+                              if ($sentnmbrs[$k] == $sentdatanmbrs[$j]) {                                  
519
+                                  $nmbusernames[] = $sentdatanmbrsusr[$j];
520
+                              }
521
+                         }
522
+                         $acdatausrdnst[$sentnmbrs[$k]] = $nmbusernames;
523
+                    }
524
+
525
+                    foreach ($acdatausrdnst as $ukey => $uvalue) {
526
+
527
+                         if (is_array($uvalue)) {
528
+
529
+                             $dispnamearr = [];
530
+                             foreach ($uvalue as $dskey => $dsvalue) {
531
+			              $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
532
+				      $getacdatadnstres = $getacdatadnst->execute([$dsvalue, 'displayname']);
533
+		                      $fetchdspname = $getacdatadnstres->fetch();                              
534
+
535
+		                      if ($fetchdspname) {
536
+		                          $dispnamearr[] = $fetchdspname['value']];
537
+		                      }
538
+				      $getacdatadnstres->closeCursor();
539
+                             }
540
+
541
+	                     if ($dispnamearr) {
542
+
543
+	                         if (count($dispnamearr) == 1) {
544
+
545
+	                             $phoneDisplayPairsst[$ukey] = ['author_displayname' => $dispnamearr[0]];
546
+
547
+	                         } elseif (count($dispnamearr) > 1) {
548
+
549
+	                             $phoneDisplayPairsst[$ukey] = ['author_displayname' => implode("/", $dispnamearr)];
550
+	                         }
551
+
552
+	                     } else { $phoneDisplayPairsst[$ukey] = ['author_displayname' => '']; }
553
+                         }
554
+                    }
555
+
556
+                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
557
+
558
+                         if (is_array($pstvalue)) {
559
+                             $contfield = "%" . $pstkey;
560
+			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
561
+			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
562
+			     $updatesentmsres->closeCursor();
563
+                         }
564
+                    }
565
+                }
566
+
567
+                return null;
568
+        }
569
+
570
+}
Browse code

removed files to implement auto-reply fix, etc.

DoubleBastionAdmin authored on 20/05/2023 00:46:30
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,564 +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 Version116Date20230508212745 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
-		} else {
188
-
189
-                        $table = $schema->getTable('sms_relent_settings');
190
-
191
-			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
-				'notnull' => false,
193
-				'length' => 1,
194
-			]);
195
-			$table->addColumn('show_display_names', Types::SMALLINT, [
196
-				'notnull' => false,
197
-				'length' => 1,
198
-			]);
199
-                }
200
-
201
-
202
-		if (!$schema->hasTable('sms_relent_received')) {
203
-			$table = $schema->createTable('sms_relent_received');
204
-			$table->addColumn('id', Types::BIGINT, [
205
-				'autoincrement' => true,
206
-				'notnull' => true,
207
-                                'length' => 11,
208
-                                'unsigned' => true,
209
-			]);
210
-			$table->addColumn('user_id', Types::STRING, [
211
-				'notnull' => true,
212
-				'length' => 64,
213
-			]);
214
-			$table->addColumn('message_id', Types::STRING, [
215
-				'notnull' => true,
216
-				'length' => 512,
217
-			]);
218
-			$table->addColumn('date', Types::DATETIME, [
219
-				'notnull' => true,
220
-			]);
221
-			$table->addColumn('from', Types::STRING, [
222
-				'notnull' => true,
223
-				'length' => 128,
224
-			]);
225
-			$table->addColumn('to', Types::STRING, [
226
-				'notnull' => true,
227
-				'length' => 128,
228
-			]);
229
-			$table->addColumn('message', Types::TEXT, [
230
-				'notnull' => false,
231
-				'default' => '',
232
-			]);
233
-			$table->addColumn('author_displayname', Types::STRING, [
234
-				'notnull' => true,
235
-				'length' => 255,
236
-			]);
237
-			$table->addColumn('internal_sender', Types::SMALLINT, [
238
-				'notnull' => false,
239
-				'length' => 1,
240
-			]);
241
-                        $table->setPrimaryKey(['id']);
242
-                        $table->addUniqueIndex(['id']);
243
-
244
-		} else {
245
-
246
-                        $table = $schema->getTable('sms_relent_received');
247
-
248
-			$table->addColumn('author_displayname', Types::STRING, [
249
-				'notnull' => true,
250
-				'length' => 255,
251
-			]);
252
-			$table->addColumn('internal_sender', Types::SMALLINT, [
253
-				'notnull' => false,
254
-				'length' => 1,
255
-			]);
256
-                }
257
-
258
-
259
-		if (!$schema->hasTable('sms_relent_sent')) {
260
-			$table = $schema->createTable('sms_relent_sent');
261
-			$table->addColumn('id', Types::BIGINT, [
262
-				'autoincrement' => true,
263
-				'notnull' => true,
264
-                                'length' => 11,
265
-                                'unsigned' => true,
266
-			]);
267
-			$table->addColumn('user_id', Types::STRING, [
268
-				'notnull' => true,
269
-				'length' => 64,
270
-			]);
271
-			$table->addColumn('message_id', Types::STRING, [
272
-				'notnull' => true,
273
-				'length' => 512,
274
-			]);
275
-			$table->addColumn('date', Types::DATETIME, [
276
-				'notnull' => true,
277
-			]);
278
-			$table->addColumn('from', Types::STRING, [
279
-				'notnull' => true,
280
-				'length' => 128,
281
-			]);
282
-			$table->addColumn('to', Types::STRING, [
283
-				'notnull' => true,
284
-				'length' => 128,
285
-			]);
286
-			$table->addColumn('network ', Types::STRING, [
287
-				'notnull' => false,
288
-				'length' => 64,
289
-				'default' => '',
290
-			]);
291
-			$table->addColumn('price', Types::STRING, [
292
-				'notnull' => false,
293
-				'length' => 64,
294
-				'default' => '',
295
-			]);
296
-			$table->addColumn('status', Types::STRING, [
297
-				'notnull' => false,
298
-				'length' => 512,
299
-				'default' => '',
300
-			]);
301
-			$table->addColumn('deliveryreceipt', Types::STRING, [
302
-				'notnull' => false,
303
-				'length' => 64,
304
-				'default' => '',
305
-			]);
306
-			$table->addColumn('message', Types::TEXT, [
307
-				'notnull' => false,
308
-                                'default' => '',
309
-			]);
310
-			$table->addColumn('author_displayname', Types::STRING, [
311
-				'notnull' => true,
312
-				'length' => 255,
313
-			]);
314
-                        $table->setPrimaryKey(['id']);
315
-                        $table->addUniqueIndex(['id']);
316
-
317
-		} else {
318
-
319
-                        $table = $schema->getTable('sms_relent_sent');
320
-
321
-			$table->addColumn('author_displayname', Types::STRING, [
322
-				'notnull' => true,
323
-				'length' => 255,
324
-			]);
325
-                }
326
-
327
-
328
-		if (!$schema->hasTable('sms_relent_autorply')) {
329
-			$table = $schema->createTable('sms_relent_autorply');
330
-			$table->addColumn('id', Types::BIGINT, [
331
-				'autoincrement' => true,
332
-				'notnull' => true,
333
-                                'length' => 11,
334
-                                'unsigned' => true,
335
-			]);
336
-			$table->addColumn('user_id', Types::STRING, [
337
-				'notnull' => true,
338
-				'length' => 128,
339
-			]);
340
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
-				'notnull' => true,
342
-				'length' => 255,
343
-			]);
344
-			$table->addColumn('phone_number', Types::STRING, [
345
-				'notnull' => true,
346
-				'length' => 128,
347
-			]);
348
-			$table->addColumn('days_of_week', Types::STRING, [
349
-				'notnull' => false,
350
-				'length' => 64,
351
-                                'default' => '',
352
-			]);
353
-			$table->addColumn('daily_start', Types::STRING, [
354
-				'notnull' => false,
355
-				'length' => 8,
356
-                                'default' => '',
357
-			]);
358
-			$table->addColumn('daily_end', Types::STRING, [
359
-				'notnull' => false,
360
-				'length' => 8,
361
-                                'default' => '',
362
-			]);
363
-			$table->addColumn('vacation_start', Types::DATETIME, [
364
-				'notnull' => false,
365
-			]);
366
-			$table->addColumn('vacation_end', Types::DATETIME, [
367
-				'notnull' => false,
368
-			]);
369
-			$table->addColumn('message_text', Types::TEXT, [
370
-				'notnull' => false,
371
-                                'default' => '',
372
-			]);
373
-                        $table->setPrimaryKey(['id']);
374
-                        $table->addUniqueIndex(['id']);
375
-
376
-		}
377
-
378
-
379
-		if (!$schema->hasTable('sms_relent_restrict')) {
380
-			$table = $schema->createTable('sms_relent_restrict');
381
-			$table->addColumn('id', Types::BIGINT, [
382
-				'autoincrement' => true,
383
-				'notnull' => true,
384
-                                'length' => 11,
385
-                                'unsigned' => true,
386
-			]);
387
-			$table->addColumn('user_id', Types::STRING, [
388
-				'notnull' => true,
389
-				'length' => 128,
390
-			]);
391
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
-				'notnull' => true,
393
-				'length' => 255,
394
-			]);
395
-			$table->addColumn('phone_number', Types::STRING, [
396
-				'notnull' => true,
397
-				'length' => 128,
398
-			]);
399
-			$table->addColumn('groups', Types::STRING, [
400
-				'notnull' => true,
401
-				'length' => 2048,
402
-			]);
403
-			$table->addColumn('users', Types::STRING, [
404
-				'notnull' => true,
405
-				'length' => 2048,
406
-			]);
407
-                        $table->setPrimaryKey(['id']);
408
-                        $table->addUniqueIndex(['id']);
409
-
410
-		}
411
-
412
-		return $schema;
413
-	}
414
-
415
-        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
-
417
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before
418
-                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
419
-	        $getrecfromnbres = $getrecfromnb->execute();
420
-
421
-                $recdatanmbrs = [];
422
-                while ($rowfetched = $getrecfromnbres->fetch()) {
423
-                       $recdatanmbrs[] = $rowfetched['from'];
424
-                }
425
-                $getrecfromnbres->closeCursor();
426
-
427
-                if ($recdatanmbrs) {
428
-
429
-                    $recnmbrs = array_values(array_unique($recdatanmbrs));
430
-
431
-                    $phoneDisplayPairs = [];
432
-                    foreach ($recnmbrs as $rckey => $rcvalue) {
433
-
434
-                         $rcvalueprc = '%' . $rcvalue;
435
-                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
436
-	                 $getacdatares = $getacdata->execute(['phone', $rcvalueprc]);
437
-
438
-		         $acdatausers = [];
439
-		         while ($acusrfetched = $getacdatares->fetch()) {
440
-		                $acdatausers[] = $acusrfetched['uid'];
441
-		         }
442
-		         $getacdatares->closeCursor();
443
-
444
-
445
-                         if ($acdatausers) {
446
-
447
-		             $acdatausrdn = [];
448
-                             foreach ($acdatausers as $dnkey => $dnvalue) {
449
-
450
-		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
451
-			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
452
-
453
-				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
454
-				         $acdatausrdn[] = $acusrdnfetched['value'];
455
-				  }
456
-				  $getacdatadnres->closeCursor();
457
-                             }
458
-
459
-                             if ($acdatausrdn) {
460
-
461
-                                 if (count($acdatausrdn) == 1) {
462
-
463
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
464
-
465
-                                 } elseif (count($acdatausrdn) > 1) {
466
-
467
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
468
-                                 }
469
-
470
-                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
471
-
472
-                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
473
-                    }
474
-
475
-                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
476
-
477
-                         if (is_array($pdpvalue)) {
478
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` = ?');
479
-			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkey]);
480
-			     $updaterecmsres->closeCursor();
481
-                         }
482
-                    }
483
-                }
484
-
485
-
486
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before
487
-                $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`');
488
-	        $getsentfromnbres = $getsentfromnb->execute();
489
-
490
-                $sentdatanmbrs = [];
491
-                while ($rowfetchedst = $getsentfromnbres->fetch()) {
492
-
493
-                       $sentdatanmbrspre = $rowfetchedst['from'];
494
-                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
495
-                       if (count($sentdatanmbrsarr) > 1) {
496
-                           $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
497
-                       } else {
498
-                           $sentdatanmbrs[] = $sentdatanmbrsarr[0];
499
-                       }
500
-                }
501
-                $getsentfromnbres->closeCursor();
502
-
503
-                if ($sentdatanmbrs) {
504
-
505
-                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
506
-
507
-                    $phoneDisplayPairsst = [];
508
-                    foreach ($sentnmbrs as $stkey => $stvalue) {
509
-
510
-                         $stvalueprc = '%' . $stvalue;
511
-                         $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
512
-	                 $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]);
513
-
514
-		         $acdatausersst = [];
515
-		         while ($acusrstfetched = $getacdatastres->fetch()) {
516
-		                $acdatausersst[] = $acusrstfetched['uid'];
517
-		         }
518
-		         $getacdatastres->closeCursor();
519
-
520
-                         if ($acdatausersst) {
521
-
522
-		             $acdatausrdnst = [];
523
-                             foreach ($acdatausersst as $dnstkey => $dnstvalue) {
524
-
525
-		                  $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
526
-			          $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']);
527
-
528
-				  while ($acusrdnstfetched = $getacdatadnstres->fetch()) {
529
-				         $acdatausrdnst[] = $acusrdnstfetched['value'];
530
-				  }
531
-				  $getacdatadnstres->closeCursor();
532
-                             }
533
-
534
-                             if ($acdatausrdnst) {
535
-
536
-                                 if (count($acdatausrdnst) == 1) {
537
-
538
-                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]];
539
-
540
-                                 } elseif (count($acdatausrdnst) > 1) {
541
-
542
-                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)];
543
-                                 }
544
-
545
-                             } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
546
-
547
-                         } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
548
-                    }
549
-
550
-                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
551
-
552
-                         if (is_array($pstvalue)) {
553
-                             $contfield = "%" . $pstkey;
554
-			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
555
-			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
556
-			     $updatesentmsres->closeCursor();
557
-                         }
558
-                    }
559
-                }
560
-
561
-                return null;
562
-        }
563
-
564
-}
Browse code

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

DoubleBastionAdmin authored on 09/05/2023 14:04:07
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,564 @@
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 Version116Date20230508212745 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
+		} else {
188
+
189
+                        $table = $schema->getTable('sms_relent_settings');
190
+
191
+			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
+				'notnull' => false,
193
+				'length' => 1,
194
+			]);
195
+			$table->addColumn('show_display_names', Types::SMALLINT, [
196
+				'notnull' => false,
197
+				'length' => 1,
198
+			]);
199
+                }
200
+
201
+
202
+		if (!$schema->hasTable('sms_relent_received')) {
203
+			$table = $schema->createTable('sms_relent_received');
204
+			$table->addColumn('id', Types::BIGINT, [
205
+				'autoincrement' => true,
206
+				'notnull' => true,
207
+                                'length' => 11,
208
+                                'unsigned' => true,
209
+			]);
210
+			$table->addColumn('user_id', Types::STRING, [
211
+				'notnull' => true,
212
+				'length' => 64,
213
+			]);
214
+			$table->addColumn('message_id', Types::STRING, [
215
+				'notnull' => true,
216
+				'length' => 512,
217
+			]);
218
+			$table->addColumn('date', Types::DATETIME, [
219
+				'notnull' => true,
220
+			]);
221
+			$table->addColumn('from', Types::STRING, [
222
+				'notnull' => true,
223
+				'length' => 128,
224
+			]);
225
+			$table->addColumn('to', Types::STRING, [
226
+				'notnull' => true,
227
+				'length' => 128,
228
+			]);
229
+			$table->addColumn('message', Types::TEXT, [
230
+				'notnull' => false,
231
+				'default' => '',
232
+			]);
233
+			$table->addColumn('author_displayname', Types::STRING, [
234
+				'notnull' => true,
235
+				'length' => 255,
236
+			]);
237
+			$table->addColumn('internal_sender', Types::SMALLINT, [
238
+				'notnull' => false,
239
+				'length' => 1,
240
+			]);
241
+                        $table->setPrimaryKey(['id']);
242
+                        $table->addUniqueIndex(['id']);
243
+
244
+		} else {
245
+
246
+                        $table = $schema->getTable('sms_relent_received');
247
+
248
+			$table->addColumn('author_displayname', Types::STRING, [
249
+				'notnull' => true,
250
+				'length' => 255,
251
+			]);
252
+			$table->addColumn('internal_sender', Types::SMALLINT, [
253
+				'notnull' => false,
254
+				'length' => 1,
255
+			]);
256
+                }
257
+
258
+
259
+		if (!$schema->hasTable('sms_relent_sent')) {
260
+			$table = $schema->createTable('sms_relent_sent');
261
+			$table->addColumn('id', Types::BIGINT, [
262
+				'autoincrement' => true,
263
+				'notnull' => true,
264
+                                'length' => 11,
265
+                                'unsigned' => true,
266
+			]);
267
+			$table->addColumn('user_id', Types::STRING, [
268
+				'notnull' => true,
269
+				'length' => 64,
270
+			]);
271
+			$table->addColumn('message_id', Types::STRING, [
272
+				'notnull' => true,
273
+				'length' => 512,
274
+			]);
275
+			$table->addColumn('date', Types::DATETIME, [
276
+				'notnull' => true,
277
+			]);
278
+			$table->addColumn('from', Types::STRING, [
279
+				'notnull' => true,
280
+				'length' => 128,
281
+			]);
282
+			$table->addColumn('to', Types::STRING, [
283
+				'notnull' => true,
284
+				'length' => 128,
285
+			]);
286
+			$table->addColumn('network ', Types::STRING, [
287
+				'notnull' => false,
288
+				'length' => 64,
289
+				'default' => '',
290
+			]);
291
+			$table->addColumn('price', Types::STRING, [
292
+				'notnull' => false,
293
+				'length' => 64,
294
+				'default' => '',
295
+			]);
296
+			$table->addColumn('status', Types::STRING, [
297
+				'notnull' => false,
298
+				'length' => 512,
299
+				'default' => '',
300
+			]);
301
+			$table->addColumn('deliveryreceipt', Types::STRING, [
302
+				'notnull' => false,
303
+				'length' => 64,
304
+				'default' => '',
305
+			]);
306
+			$table->addColumn('message', Types::TEXT, [
307
+				'notnull' => false,
308
+                                'default' => '',
309
+			]);
310
+			$table->addColumn('author_displayname', Types::STRING, [
311
+				'notnull' => true,
312
+				'length' => 255,
313
+			]);
314
+                        $table->setPrimaryKey(['id']);
315
+                        $table->addUniqueIndex(['id']);
316
+
317
+		} else {
318
+
319
+                        $table = $schema->getTable('sms_relent_sent');
320
+
321
+			$table->addColumn('author_displayname', Types::STRING, [
322
+				'notnull' => true,
323
+				'length' => 255,
324
+			]);
325
+                }
326
+
327
+
328
+		if (!$schema->hasTable('sms_relent_autorply')) {
329
+			$table = $schema->createTable('sms_relent_autorply');
330
+			$table->addColumn('id', Types::BIGINT, [
331
+				'autoincrement' => true,
332
+				'notnull' => true,
333
+                                'length' => 11,
334
+                                'unsigned' => true,
335
+			]);
336
+			$table->addColumn('user_id', Types::STRING, [
337
+				'notnull' => true,
338
+				'length' => 128,
339
+			]);
340
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
+				'notnull' => true,
342
+				'length' => 255,
343
+			]);
344
+			$table->addColumn('phone_number', Types::STRING, [
345
+				'notnull' => true,
346
+				'length' => 128,
347
+			]);
348
+			$table->addColumn('days_of_week', Types::STRING, [
349
+				'notnull' => false,
350
+				'length' => 64,
351
+                                'default' => '',
352
+			]);
353
+			$table->addColumn('daily_start', Types::STRING, [
354
+				'notnull' => false,
355
+				'length' => 8,
356
+                                'default' => '',
357
+			]);
358
+			$table->addColumn('daily_end', Types::STRING, [
359
+				'notnull' => false,
360
+				'length' => 8,
361
+                                'default' => '',
362
+			]);
363
+			$table->addColumn('vacation_start', Types::DATETIME, [
364
+				'notnull' => false,
365
+			]);
366
+			$table->addColumn('vacation_end', Types::DATETIME, [
367
+				'notnull' => false,
368
+			]);
369
+			$table->addColumn('message_text', Types::TEXT, [
370
+				'notnull' => false,
371
+                                'default' => '',
372
+			]);
373
+                        $table->setPrimaryKey(['id']);
374
+                        $table->addUniqueIndex(['id']);
375
+
376
+		}
377
+
378
+
379
+		if (!$schema->hasTable('sms_relent_restrict')) {
380
+			$table = $schema->createTable('sms_relent_restrict');
381
+			$table->addColumn('id', Types::BIGINT, [
382
+				'autoincrement' => true,
383
+				'notnull' => true,
384
+                                'length' => 11,
385
+                                'unsigned' => true,
386
+			]);
387
+			$table->addColumn('user_id', Types::STRING, [
388
+				'notnull' => true,
389
+				'length' => 128,
390
+			]);
391
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
+				'notnull' => true,
393
+				'length' => 255,
394
+			]);
395
+			$table->addColumn('phone_number', Types::STRING, [
396
+				'notnull' => true,
397
+				'length' => 128,
398
+			]);
399
+			$table->addColumn('groups', Types::STRING, [
400
+				'notnull' => true,
401
+				'length' => 2048,
402
+			]);
403
+			$table->addColumn('users', Types::STRING, [
404
+				'notnull' => true,
405
+				'length' => 2048,
406
+			]);
407
+                        $table->setPrimaryKey(['id']);
408
+                        $table->addUniqueIndex(['id']);
409
+
410
+		}
411
+
412
+		return $schema;
413
+	}
414
+
415
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
+
417
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before
418
+                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
419
+	        $getrecfromnbres = $getrecfromnb->execute();
420
+
421
+                $recdatanmbrs = [];
422
+                while ($rowfetched = $getrecfromnbres->fetch()) {
423
+                       $recdatanmbrs[] = $rowfetched['from'];
424
+                }
425
+                $getrecfromnbres->closeCursor();
426
+
427
+                if ($recdatanmbrs) {
428
+
429
+                    $recnmbrs = array_values(array_unique($recdatanmbrs));
430
+
431
+                    $phoneDisplayPairs = [];
432
+                    foreach ($recnmbrs as $rckey => $rcvalue) {
433
+
434
+                         $rcvalueprc = '%' . $rcvalue;
435
+                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
436
+	                 $getacdatares = $getacdata->execute(['phone', $rcvalueprc]);
437
+
438
+		         $acdatausers = [];
439
+		         while ($acusrfetched = $getacdatares->fetch()) {
440
+		                $acdatausers[] = $acusrfetched['uid'];
441
+		         }
442
+		         $getacdatares->closeCursor();
443
+
444
+
445
+                         if ($acdatausers) {
446
+
447
+		             $acdatausrdn = [];
448
+                             foreach ($acdatausers as $dnkey => $dnvalue) {
449
+
450
+		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
451
+			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
452
+
453
+				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
454
+				         $acdatausrdn[] = $acusrdnfetched['value'];
455
+				  }
456
+				  $getacdatadnres->closeCursor();
457
+                             }
458
+
459
+                             if ($acdatausrdn) {
460
+
461
+                                 if (count($acdatausrdn) == 1) {
462
+
463
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
464
+
465
+                                 } elseif (count($acdatausrdn) > 1) {
466
+
467
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
468
+                                 }
469
+
470
+                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
471
+
472
+                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
473
+                    }
474
+
475
+                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
476
+
477
+                         if (is_array($pdpvalue)) {
478
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` = ?');
479
+			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkey]);
480
+			     $updaterecmsres->closeCursor();
481
+                         }
482
+                    }
483
+                }
484
+
485
+
486
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before
487
+                $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`');
488
+	        $getsentfromnbres = $getsentfromnb->execute();
489
+
490
+                $sentdatanmbrs = [];
491
+                while ($rowfetchedst = $getsentfromnbres->fetch()) {
492
+
493
+                       $sentdatanmbrspre = $rowfetchedst['from'];
494
+                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
495
+                       if (count($sentdatanmbrsarr) > 1) {
496
+                           $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
497
+                       } else {
498
+                           $sentdatanmbrs[] = $sentdatanmbrsarr[0];
499
+                       }
500
+                }
501
+                $getsentfromnbres->closeCursor();
502
+
503
+                if ($sentdatanmbrs) {
504
+
505
+                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
506
+
507
+                    $phoneDisplayPairsst = [];
508
+                    foreach ($sentnmbrs as $stkey => $stvalue) {
509
+
510
+                         $stvalueprc = '%' . $stvalue;
511
+                         $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` LIKE ?');
512
+	                 $getacdatastres = $getacdatast->execute(['phone', $stvalueprc]);
513
+
514
+		         $acdatausersst = [];
515
+		         while ($acusrstfetched = $getacdatastres->fetch()) {
516
+		                $acdatausersst[] = $acusrstfetched['uid'];
517
+		         }
518
+		         $getacdatastres->closeCursor();
519
+
520
+                         if ($acdatausersst) {
521
+
522
+		             $acdatausrdnst = [];
523
+                             foreach ($acdatausersst as $dnstkey => $dnstvalue) {
524
+
525
+		                  $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
526
+			          $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']);
527
+
528
+				  while ($acusrdnstfetched = $getacdatadnstres->fetch()) {
529
+				         $acdatausrdnst[] = $acusrdnstfetched['value'];
530
+				  }
531
+				  $getacdatadnstres->closeCursor();
532
+                             }
533
+
534
+                             if ($acdatausrdnst) {
535
+
536
+                                 if (count($acdatausrdnst) == 1) {
537
+
538
+                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]];
539
+
540
+                                 } elseif (count($acdatausrdnst) > 1) {
541
+
542
+                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)];
543
+                                 }
544
+
545
+                             } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
546
+
547
+                         } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
548
+                    }
549
+
550
+                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
551
+
552
+                         if (is_array($pstvalue)) {
553
+                             $contfield = "%" . $pstkey;
554
+			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
555
+			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
556
+			     $updatesentmsres->closeCursor();
557
+                         }
558
+                    }
559
+                }
560
+
561
+                return null;
562
+        }
563
+
564
+}
Browse code

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

DoubleBastionAdmin authored on 09/05/2023 14:00:04
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,558 +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 Version116Date20230508212745 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
-		} else {
188
-
189
-                        $table = $schema->getTable('sms_relent_settings');
190
-
191
-			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
-				'notnull' => false,
193
-				'length' => 1,
194
-			]);
195
-			$table->addColumn('show_display_names', Types::SMALLINT, [
196
-				'notnull' => false,
197
-				'length' => 1,
198
-			]);
199
-                }
200
-
201
-
202
-		if (!$schema->hasTable('sms_relent_received')) {
203
-			$table = $schema->createTable('sms_relent_received');
204
-			$table->addColumn('id', Types::BIGINT, [
205
-				'autoincrement' => true,
206
-				'notnull' => true,
207
-                                'length' => 11,
208
-                                'unsigned' => true,
209
-			]);
210
-			$table->addColumn('user_id', Types::STRING, [
211
-				'notnull' => true,
212
-				'length' => 64,
213
-			]);
214
-			$table->addColumn('message_id', Types::STRING, [
215
-				'notnull' => true,
216
-				'length' => 512,
217
-			]);
218
-			$table->addColumn('date', Types::DATETIME, [
219
-				'notnull' => true,
220
-			]);
221
-			$table->addColumn('from', Types::STRING, [
222
-				'notnull' => true,
223
-				'length' => 128,
224
-			]);
225
-			$table->addColumn('to', Types::STRING, [
226
-				'notnull' => true,
227
-				'length' => 128,
228
-			]);
229
-			$table->addColumn('message', Types::TEXT, [
230
-				'notnull' => false,
231
-				'default' => '',
232
-			]);
233
-			$table->addColumn('author_displayname', Types::STRING, [
234
-				'notnull' => true,
235
-				'length' => 255,
236
-			]);
237
-			$table->addColumn('internal_sender', Types::SMALLINT, [
238
-				'notnull' => false,
239
-				'length' => 1,
240
-			]);
241
-                        $table->setPrimaryKey(['id']);
242
-                        $table->addUniqueIndex(['id']);
243
-
244
-		} else {
245
-
246
-                        $table = $schema->getTable('sms_relent_received');
247
-
248
-			$table->addColumn('author_displayname', Types::STRING, [
249
-				'notnull' => true,
250
-				'length' => 255,
251
-			]);
252
-			$table->addColumn('internal_sender', Types::SMALLINT, [
253
-				'notnull' => false,
254
-				'length' => 1,
255
-			]);
256
-                }
257
-
258
-
259
-		if (!$schema->hasTable('sms_relent_sent')) {
260
-			$table = $schema->createTable('sms_relent_sent');
261
-			$table->addColumn('id', Types::BIGINT, [
262
-				'autoincrement' => true,
263
-				'notnull' => true,
264
-                                'length' => 11,
265
-                                'unsigned' => true,
266
-			]);
267
-			$table->addColumn('user_id', Types::STRING, [
268
-				'notnull' => true,
269
-				'length' => 64,
270
-			]);
271
-			$table->addColumn('message_id', Types::STRING, [
272
-				'notnull' => true,
273
-				'length' => 512,
274
-			]);
275
-			$table->addColumn('date', Types::DATETIME, [
276
-				'notnull' => true,
277
-			]);
278
-			$table->addColumn('from', Types::STRING, [
279
-				'notnull' => true,
280
-				'length' => 128,
281
-			]);
282
-			$table->addColumn('to', Types::STRING, [
283
-				'notnull' => true,
284
-				'length' => 128,
285
-			]);
286
-			$table->addColumn('network ', Types::STRING, [
287
-				'notnull' => false,
288
-				'length' => 64,
289
-				'default' => '',
290
-			]);
291
-			$table->addColumn('price', Types::STRING, [
292
-				'notnull' => false,
293
-				'length' => 64,
294
-				'default' => '',
295
-			]);
296
-			$table->addColumn('status', Types::STRING, [
297
-				'notnull' => false,
298
-				'length' => 512,
299
-				'default' => '',
300
-			]);
301
-			$table->addColumn('deliveryreceipt', Types::STRING, [
302
-				'notnull' => false,
303
-				'length' => 64,
304
-				'default' => '',
305
-			]);
306
-			$table->addColumn('message', Types::TEXT, [
307
-				'notnull' => false,
308
-                                'default' => '',
309
-			]);
310
-			$table->addColumn('author_displayname', Types::STRING, [
311
-				'notnull' => true,
312
-				'length' => 255,
313
-			]);
314
-                        $table->setPrimaryKey(['id']);
315
-                        $table->addUniqueIndex(['id']);
316
-
317
-		} else {
318
-
319
-                        $table = $schema->getTable('sms_relent_sent');
320
-
321
-			$table->addColumn('author_displayname', Types::STRING, [
322
-				'notnull' => true,
323
-				'length' => 255,
324
-			]);
325
-                }
326
-
327
-
328
-		if (!$schema->hasTable('sms_relent_autorply')) {
329
-			$table = $schema->createTable('sms_relent_autorply');
330
-			$table->addColumn('id', Types::BIGINT, [
331
-				'autoincrement' => true,
332
-				'notnull' => true,
333
-                                'length' => 11,
334
-                                'unsigned' => true,
335
-			]);
336
-			$table->addColumn('user_id', Types::STRING, [
337
-				'notnull' => true,
338
-				'length' => 128,
339
-			]);
340
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
-				'notnull' => true,
342
-				'length' => 255,
343
-			]);
344
-			$table->addColumn('phone_number', Types::STRING, [
345
-				'notnull' => true,
346
-				'length' => 128,
347
-			]);
348
-			$table->addColumn('days_of_week', Types::STRING, [
349
-				'notnull' => false,
350
-				'length' => 64,
351
-                                'default' => '',
352
-			]);
353
-			$table->addColumn('daily_start', Types::STRING, [
354
-				'notnull' => false,
355
-				'length' => 8,
356
-                                'default' => '',
357
-			]);
358
-			$table->addColumn('daily_end', Types::STRING, [
359
-				'notnull' => false,
360
-				'length' => 8,
361
-                                'default' => '',
362
-			]);
363
-			$table->addColumn('vacation_start', Types::DATETIME, [
364
-				'notnull' => false,
365
-			]);
366
-			$table->addColumn('vacation_end', Types::DATETIME, [
367
-				'notnull' => false,
368
-			]);
369
-			$table->addColumn('message_text', Types::TEXT, [
370
-				'notnull' => false,
371
-                                'default' => '',
372
-			]);
373
-                        $table->setPrimaryKey(['id']);
374
-                        $table->addUniqueIndex(['id']);
375
-
376
-		}
377
-
378
-
379
-		if (!$schema->hasTable('sms_relent_restrict')) {
380
-			$table = $schema->createTable('sms_relent_restrict');
381
-			$table->addColumn('id', Types::BIGINT, [
382
-				'autoincrement' => true,
383
-				'notnull' => true,
384
-                                'length' => 11,
385
-                                'unsigned' => true,
386
-			]);
387
-			$table->addColumn('user_id', Types::STRING, [
388
-				'notnull' => true,
389
-				'length' => 128,
390
-			]);
391
-			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
-				'notnull' => true,
393
-				'length' => 255,
394
-			]);
395
-			$table->addColumn('phone_number', Types::STRING, [
396
-				'notnull' => true,
397
-				'length' => 128,
398
-			]);
399
-			$table->addColumn('groups', Types::STRING, [
400
-				'notnull' => true,
401
-				'length' => 2048,
402
-			]);
403
-			$table->addColumn('users', Types::STRING, [
404
-				'notnull' => true,
405
-				'length' => 2048,
406
-			]);
407
-                        $table->setPrimaryKey(['id']);
408
-                        $table->addUniqueIndex(['id']);
409
-
410
-		}
411
-
412
-		return $schema;
413
-	}
414
-
415
-        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
-
417
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before
418
-                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
419
-	        $getrecfromnbres = $getrecfromnb->execute();
420
-
421
-                $recdatanmbrs = [];
422
-                while ($rowfetched = $getrecfromnbres->fetch()) {
423
-                       $recdatanmbrs[] = $rowfetched['from'];
424
-                }
425
-                $getrecfromnbres->closeCursor();
426
-
427
-                if ($recdatanmbrs) {
428
-
429
-                    $recnmbrs = array_values(array_unique($recdatanmbrs));
430
-
431
-                    $phoneDisplayPairs = [];
432
-                    foreach ($recnmbrs as $rckey => $rcvalue) {
433
-
434
-                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` = ?');
435
-	                 $getacdatares = $getacdata->execute(['phone', $rcvalue]);
436
-
437
-		         $acdatausers = [];
438
-		         while ($acusrfetched = $getacdatares->fetch()) {
439
-		                $acdatausers[] = $acusrfetched['uid'];
440
-		         }
441
-		         $getacdatares->closeCursor();
442
-
443
-
444
-                         if ($acdatausers) {
445
-
446
-		             $acdatausrdn = [];
447
-                             foreach ($acdatausers as $dnkey => $dnvalue) {
448
-
449
-		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
450
-			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
451
-
452
-				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
453
-				         $acdatausrdn[] = $acusrdnfetched['value'];
454
-				  }
455
-				  $getacdatadnres->closeCursor();
456
-                             }
457
-
458
-                             if ($acdatausrdn) {
459
-
460
-                                 if (count($acdatausrdn) == 1) {
461
-
462
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
463
-
464
-                                 } elseif (count($acdatausrdn) > 1) {
465
-
466
-                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
467
-                                 }
468
-
469
-                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
470
-
471
-                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
472
-                    }
473
-
474
-                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
475
-
476
-                         if (is_array($pdpvalue)) {
477
-			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` = ?');
478
-			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkey]);
479
-			     $updaterecmsres->closeCursor();
480
-                         }
481
-                    }
482
-                }
483
-
484
-
485
-                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before
486
-                $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`');
487
-	        $getsentfromnbres = $getsentfromnb->execute();
488
-
489
-                $sentdatanmbrs = [];
490
-                while ($rowfetchedst = $getsentfromnbres->fetch()) {
491
-
492
-                       $sentdatanmbrspre = $rowfetchedst['from'];
493
-                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
494
-                       $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
495
-                }
496
-                $getsentfromnbres->closeCursor();
497
-
498
-                if ($sentdatanmbrs) {
499
-
500
-                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
501
-
502
-                    $phoneDisplayPairsst = [];
503
-                    foreach ($sentnmbrs as $stkey => $stvalue) {
504
-
505
-                         $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` = ?');
506
-	                 $getacdatastres = $getacdatast->execute(['phone', $stvalue]);
507
-
508
-		         $acdatausersst = [];
509
-		         while ($acusrstfetched = $getacdatastres->fetch()) {
510
-		                $acdatausersst[] = $acusrstfetched['uid'];
511
-		         }
512
-		         $getacdatastres->closeCursor();
513
-
514
-                         if ($acdatausersst) {
515
-
516
-		             $acdatausrdnst = [];
517
-                             foreach ($acdatausersst as $dnstkey => $dnstvalue) {
518
-
519
-		                  $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
520
-			          $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']);
521
-
522
-				  while ($acusrdnstfetched = $getacdatadnstres->fetch()) {
523
-				         $acdatausrdnst[] = $acusrdnstfetched['value'];
524
-				  }
525
-				  $getacdatadnstres->closeCursor();
526
-                             }
527
-
528
-                             if ($acdatausrdnst) {
529
-
530
-                                 if (count($acdatausrdnst) == 1) {
531
-
532
-                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]];
533
-
534
-                                 } elseif (count($acdatausrdnst) > 1) {
535
-
536
-                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)];
537
-                                 }
538
-
539
-                             } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
540
-
541
-                         } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
542
-                    }
543
-
544
-                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
545
-
546
-                         if (is_array($pstvalue)) {
547
-                             $contfield = "%" . $pstkey;
548
-			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
549
-			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
550
-			     $updatesentmsres->closeCursor();
551
-                         }
552
-                    }
553
-                }
554
-
555
-                return null;
556
-        }
557
-
558
-}
Browse code

added changes for origination, auto-reply, etc.

DoubleBastionAdmin authored on 08/05/2023 20:50:18
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,558 @@
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 Version116Date20230508212745 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
+		} else {
188
+
189
+                        $table = $schema->getTable('sms_relent_settings');
190
+
191
+			$table->addColumn('show_all_messages', Types::SMALLINT, [
192
+				'notnull' => false,
193
+				'length' => 1,
194
+			]);
195
+			$table->addColumn('show_display_names', Types::SMALLINT, [
196
+				'notnull' => false,
197
+				'length' => 1,
198
+			]);
199
+                }
200
+
201
+
202
+		if (!$schema->hasTable('sms_relent_received')) {
203
+			$table = $schema->createTable('sms_relent_received');
204
+			$table->addColumn('id', Types::BIGINT, [
205
+				'autoincrement' => true,
206
+				'notnull' => true,
207
+                                'length' => 11,
208
+                                'unsigned' => true,
209
+			]);
210
+			$table->addColumn('user_id', Types::STRING, [
211
+				'notnull' => true,
212
+				'length' => 64,
213
+			]);
214
+			$table->addColumn('message_id', Types::STRING, [
215
+				'notnull' => true,
216
+				'length' => 512,
217
+			]);
218
+			$table->addColumn('date', Types::DATETIME, [
219
+				'notnull' => true,
220
+			]);
221
+			$table->addColumn('from', Types::STRING, [
222
+				'notnull' => true,
223
+				'length' => 128,
224
+			]);
225
+			$table->addColumn('to', Types::STRING, [
226
+				'notnull' => true,
227
+				'length' => 128,
228
+			]);
229
+			$table->addColumn('message', Types::TEXT, [
230
+				'notnull' => false,
231
+				'default' => '',
232
+			]);
233
+			$table->addColumn('author_displayname', Types::STRING, [
234
+				'notnull' => true,
235
+				'length' => 255,
236
+			]);
237
+			$table->addColumn('internal_sender', Types::SMALLINT, [
238
+				'notnull' => false,
239
+				'length' => 1,
240
+			]);
241
+                        $table->setPrimaryKey(['id']);
242
+                        $table->addUniqueIndex(['id']);
243
+
244
+		} else {
245
+
246
+                        $table = $schema->getTable('sms_relent_received');
247
+
248
+			$table->addColumn('author_displayname', Types::STRING, [
249
+				'notnull' => true,
250
+				'length' => 255,
251
+			]);
252
+			$table->addColumn('internal_sender', Types::SMALLINT, [
253
+				'notnull' => false,
254
+				'length' => 1,
255
+			]);
256
+                }
257
+
258
+
259
+		if (!$schema->hasTable('sms_relent_sent')) {
260
+			$table = $schema->createTable('sms_relent_sent');
261
+			$table->addColumn('id', Types::BIGINT, [
262
+				'autoincrement' => true,
263
+				'notnull' => true,
264
+                                'length' => 11,
265
+                                'unsigned' => true,
266
+			]);
267
+			$table->addColumn('user_id', Types::STRING, [
268
+				'notnull' => true,
269
+				'length' => 64,
270
+			]);
271
+			$table->addColumn('message_id', Types::STRING, [
272
+				'notnull' => true,
273
+				'length' => 512,
274
+			]);
275
+			$table->addColumn('date', Types::DATETIME, [
276
+				'notnull' => true,
277
+			]);
278
+			$table->addColumn('from', Types::STRING, [
279
+				'notnull' => true,
280
+				'length' => 128,
281
+			]);
282
+			$table->addColumn('to', Types::STRING, [
283
+				'notnull' => true,
284
+				'length' => 128,
285
+			]);
286
+			$table->addColumn('network ', Types::STRING, [
287
+				'notnull' => false,
288
+				'length' => 64,
289
+				'default' => '',
290
+			]);
291
+			$table->addColumn('price', Types::STRING, [
292
+				'notnull' => false,
293
+				'length' => 64,
294
+				'default' => '',
295
+			]);
296
+			$table->addColumn('status', Types::STRING, [
297
+				'notnull' => false,
298
+				'length' => 512,
299
+				'default' => '',
300
+			]);
301
+			$table->addColumn('deliveryreceipt', Types::STRING, [
302
+				'notnull' => false,
303
+				'length' => 64,
304
+				'default' => '',
305
+			]);
306
+			$table->addColumn('message', Types::TEXT, [
307
+				'notnull' => false,
308
+                                'default' => '',
309
+			]);
310
+			$table->addColumn('author_displayname', Types::STRING, [
311
+				'notnull' => true,
312
+				'length' => 255,
313
+			]);
314
+                        $table->setPrimaryKey(['id']);
315
+                        $table->addUniqueIndex(['id']);
316
+
317
+		} else {
318
+
319
+                        $table = $schema->getTable('sms_relent_sent');
320
+
321
+			$table->addColumn('author_displayname', Types::STRING, [
322
+				'notnull' => true,
323
+				'length' => 255,
324
+			]);
325
+                }
326
+
327
+
328
+		if (!$schema->hasTable('sms_relent_autorply')) {
329
+			$table = $schema->createTable('sms_relent_autorply');
330
+			$table->addColumn('id', Types::BIGINT, [
331
+				'autoincrement' => true,
332
+				'notnull' => true,
333
+                                'length' => 11,
334
+                                'unsigned' => true,
335
+			]);
336
+			$table->addColumn('user_id', Types::STRING, [
337
+				'notnull' => true,
338
+				'length' => 128,
339
+			]);
340
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
341
+				'notnull' => true,
342
+				'length' => 255,
343
+			]);
344
+			$table->addColumn('phone_number', Types::STRING, [
345
+				'notnull' => true,
346
+				'length' => 128,
347
+			]);
348
+			$table->addColumn('days_of_week', Types::STRING, [
349
+				'notnull' => false,
350
+				'length' => 64,
351
+                                'default' => '',
352
+			]);
353
+			$table->addColumn('daily_start', Types::STRING, [
354
+				'notnull' => false,
355
+				'length' => 8,
356
+                                'default' => '',
357
+			]);
358
+			$table->addColumn('daily_end', Types::STRING, [
359
+				'notnull' => false,
360
+				'length' => 8,
361
+                                'default' => '',
362
+			]);
363
+			$table->addColumn('vacation_start', Types::DATETIME, [
364
+				'notnull' => false,
365
+			]);
366
+			$table->addColumn('vacation_end', Types::DATETIME, [
367
+				'notnull' => false,
368
+			]);
369
+			$table->addColumn('message_text', Types::TEXT, [
370
+				'notnull' => false,
371
+                                'default' => '',
372
+			]);
373
+                        $table->setPrimaryKey(['id']);
374
+                        $table->addUniqueIndex(['id']);
375
+
376
+		}
377
+
378
+
379
+		if (!$schema->hasTable('sms_relent_restrict')) {
380
+			$table = $schema->createTable('sms_relent_restrict');
381
+			$table->addColumn('id', Types::BIGINT, [
382
+				'autoincrement' => true,
383
+				'notnull' => true,
384
+                                'length' => 11,
385
+                                'unsigned' => true,
386
+			]);
387
+			$table->addColumn('user_id', Types::STRING, [
388
+				'notnull' => true,
389
+				'length' => 128,
390
+			]);
391
+			$table->addColumn('saved_by_dsplname', Types::STRING, [
392
+				'notnull' => true,
393
+				'length' => 255,
394
+			]);
395
+			$table->addColumn('phone_number', Types::STRING, [
396
+				'notnull' => true,
397
+				'length' => 128,
398
+			]);
399
+			$table->addColumn('groups', Types::STRING, [
400
+				'notnull' => true,
401
+				'length' => 2048,
402
+			]);
403
+			$table->addColumn('users', Types::STRING, [
404
+				'notnull' => true,
405
+				'length' => 2048,
406
+			]);
407
+                        $table->setPrimaryKey(['id']);
408
+                        $table->addUniqueIndex(['id']);
409
+
410
+		}
411
+
412
+		return $schema;
413
+	}
414
+
415
+        public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
416
+
417
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_received' table, for messages that were received before
418
+                $getrecfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_received`');
419
+	        $getrecfromnbres = $getrecfromnb->execute();
420
+
421
+                $recdatanmbrs = [];
422
+                while ($rowfetched = $getrecfromnbres->fetch()) {
423
+                       $recdatanmbrs[] = $rowfetched['from'];
424
+                }
425
+                $getrecfromnbres->closeCursor();
426
+
427
+                if ($recdatanmbrs) {
428
+
429
+                    $recnmbrs = array_values(array_unique($recdatanmbrs));
430
+
431
+                    $phoneDisplayPairs = [];
432
+                    foreach ($recnmbrs as $rckey => $rcvalue) {
433
+
434
+                         $getacdata = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` = ?');
435
+	                 $getacdatares = $getacdata->execute(['phone', $rcvalue]);
436
+
437
+		         $acdatausers = [];
438
+		         while ($acusrfetched = $getacdatares->fetch()) {
439
+		                $acdatausers[] = $acusrfetched['uid'];
440
+		         }
441
+		         $getacdatares->closeCursor();
442
+
443
+
444
+                         if ($acdatausers) {
445
+
446
+		             $acdatausrdn = [];
447
+                             foreach ($acdatausers as $dnkey => $dnvalue) {
448
+
449
+		                  $getacdatadn = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
450
+			          $getacdatadnres = $getacdatadn->execute([$dnvalue, 'displayname']);
451
+
452
+				  while ($acusrdnfetched = $getacdatadnres->fetch()) {
453
+				         $acdatausrdn[] = $acusrdnfetched['value'];
454
+				  }
455
+				  $getacdatadnres->closeCursor();
456
+                             }
457
+
458
+                             if ($acdatausrdn) {
459
+
460
+                                 if (count($acdatausrdn) == 1) {
461
+
462
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => $acdatausrdn[0], 'internal_sender' => 1];
463
+
464
+                                 } elseif (count($acdatausrdn) > 1) {
465
+
466
+                                     $phoneDisplayPairs[$rcvalue] = ['author_displayname' => implode("/", $acdatausrdn), 'internal_sender' => 1];
467
+                                 }
468
+
469
+                             } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
470
+
471
+                         } else { $phoneDisplayPairs[$rcvalue] = ['author_displayname' => '', 'internal_sender' => 0]; }
472
+                    }
473
+
474
+                    foreach ($phoneDisplayPairs as $pdpkey => $pdpvalue) {
475
+
476
+                         if (is_array($pdpvalue)) {
477
+			     $updaterecms = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_received` SET `author_displayname` = ?, `internal_sender` = ? WHERE `from` = ?');
478
+			     $updaterecmsres = $updaterecms->execute([$pdpvalue['author_displayname'], $pdpvalue['internal_sender'], $pdpkey]);
479
+			     $updaterecmsres->closeCursor();
480
+                         }
481
+                    }
482
+                }
483
+
484
+
485
+                // Enter the Nextcloud display name in the 'author_displayname' column of the 'sms_relent_sent' table, for messages that were sent before
486
+                $getsentfromnb = $this->connection->prepare('SELECT `from` FROM `*PREFIX*sms_relent_sent`');
487
+	        $getsentfromnbres = $getsentfromnb->execute();
488
+
489
+                $sentdatanmbrs = [];
490
+                while ($rowfetchedst = $getsentfromnbres->fetch()) {
491
+
492
+                       $sentdatanmbrspre = $rowfetchedst['from'];
493
+                       $sentdatanmbrsarr = explode("+", $sentdatanmbrspre);
494
+                       $sentdatanmbrs[] = "+" . $sentdatanmbrsarr[1];
495
+                }
496
+                $getsentfromnbres->closeCursor();
497
+
498
+                if ($sentdatanmbrs) {
499
+
500
+                    $sentnmbrs = array_values(array_unique($sentdatanmbrs));
501
+
502
+                    $phoneDisplayPairsst = [];
503
+                    foreach ($sentnmbrs as $stkey => $stvalue) {
504
+
505
+                         $getacdatast = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `name` = ? AND `value` = ?');
506
+	                 $getacdatastres = $getacdatast->execute(['phone', $stvalue]);
507
+
508
+		         $acdatausersst = [];
509
+		         while ($acusrstfetched = $getacdatastres->fetch()) {
510
+		                $acdatausersst[] = $acusrstfetched['uid'];
511
+		         }
512
+		         $getacdatastres->closeCursor();
513
+
514
+                         if ($acdatausersst) {
515
+
516
+		             $acdatausrdnst = [];
517
+                             foreach ($acdatausersst as $dnstkey => $dnstvalue) {
518
+
519
+		                  $getacdatadnst = $this->connection->prepare('SELECT `uid`, `name`, `value` FROM `*PREFIX*accounts_data` WHERE `uid` = ? AND `name` = ?');
520
+			          $getacdatadnstres = $getacdatadnst->execute([$dnstvalue, 'displayname']);
521
+
522
+				  while ($acusrdnstfetched = $getacdatadnstres->fetch()) {
523
+				         $acdatausrdnst[] = $acusrdnstfetched['value'];
524
+				  }
525
+				  $getacdatadnstres->closeCursor();
526
+                             }
527
+
528
+                             if ($acdatausrdnst) {
529
+
530
+                                 if (count($acdatausrdnst) == 1) {
531
+
532
+                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => $acdatausrdnst[0]];
533
+
534
+                                 } elseif (count($acdatausrdnst) > 1) {
535
+
536
+                                     $phoneDisplayPairsst[$stvalue] = ['author_displayname' => implode("/", $acdatausrdnst)];
537
+                                 }
538
+
539
+                             } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
540
+
541
+                         } else { $phoneDisplayPairsst[$stvalue] = ['author_displayname' => '']; }
542
+                    }
543
+
544
+                    foreach ($phoneDisplayPairsst as $pstkey => $pstvalue) {
545
+
546
+                         if (is_array($pstvalue)) {
547
+                             $contfield = "%" . $pstkey;
548
+			     $updatesentmsst = $this->connection->prepare('UPDATE `*PREFIX*sms_relent_sent` SET `author_displayname` = ? WHERE `from` LIKE ?');
549
+			     $updatesentmsres = $updatesentmsst->execute([$pstvalue['author_displayname'], $contfield]);
550
+			     $updatesentmsres->closeCursor();
551
+                         }
552
+                    }
553
+                }
554
+
555
+                return null;
556
+        }
557
+
558
+}