Skip to content

Commit 67193f4

Browse files
authored
Merge pull request #145 from TrafficLight42/fix-no-db-columns
Fix missing device columns when migrating from <1.0
2 parents 24a59b1 + 39cbf2c commit 67193f4

9 files changed

Lines changed: 443 additions & 212 deletions

File tree

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<id>phonetrack</id>
44
<name>PhoneTrack</name>
55
<summary> </summary><description> </description>
6-
<version>1.1.0</version>
6+
<version>1.2.0</version>
77
<licence>agpl</licence>
88
<author mail="julien-nc@posteo.net">Julien Veyssier</author>
99
<namespace>PhoneTrack</namespace>

composer.lock

Lines changed: 180 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Activity/ActivityManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private function createEvent($objectType, $entity, $subject, $additionalParams =
172172
->setAuthor($author ?? $this->userId ?? '')
173173
->setObject($objectType, (int)$object->getId(), $objectName)
174174
->setSubject($subject, array_merge($subjectParams, $additionalParams))
175-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'))
175+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'))
176176
->setTimestamp(time());
177177

178178
return $event;

lib/Controller/LogController.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
use OCP\IDBConnection;
3737
use OCP\IL10N;
3838
use OCP\IRequest;
39+
use OCP\IURLGenerator;
3940
use OCP\IUserManager;
4041

4142
use OCP\Mail\IMailer;
43+
use OCP\Notification\IAction;
4244
use OCP\Notification\IManager;
4345
use Psr\Log\LoggerInterface;
4446
use Throwable;
@@ -66,6 +68,7 @@ public function __construct(
6668
private ShareMapper $shareMapper,
6769
private IDBConnection $db,
6870
private IMailer $mailer,
71+
private IURLGenerator $url,
6972
private ?string $userId,
7073
) {
7174
parent::__construct($AppName, $request);
@@ -175,11 +178,11 @@ private function checkProxim(
175178

176179
$acceptAction = $notification->createAction();
177180
$acceptAction->setLabel('accept')
178-
->setLink('/apps/phonetrack', 'GET');
181+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
179182

180183
$declineAction = $notification->createAction();
181184
$declineAction->setLabel('decline')
182-
->setLink('/apps/phonetrack', 'GET');
185+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
183186

184187
$notification->setApp(Application::APP_ID)
185188
->setUser($aUserId)
@@ -307,11 +310,11 @@ private function checkProxim(
307310

308311
$acceptAction = $notification->createAction();
309312
$acceptAction->setLabel('accept')
310-
->setLink('/apps/phonetrack', 'GET');
313+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
311314

312315
$declineAction = $notification->createAction();
313316
$declineAction->setLabel('decline')
314-
->setLink('/apps/phonetrack', 'GET');
317+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
315318

316319
$notification->setApp(Application::APP_ID)
317320
->setUser($aUserId)
@@ -475,11 +478,11 @@ private function checkGeoGence(
475478

476479
$acceptAction = $notification->createAction();
477480
$acceptAction->setLabel('accept')
478-
->setLink('/apps/phonetrack', 'GET');
481+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
479482

480483
$declineAction = $notification->createAction();
481484
$declineAction->setLabel('decline')
482-
->setLink('/apps/phonetrack', 'GET');
485+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
483486

484487
$notification->setApp(Application::APP_ID)
485488
->setUser($aUserId)
@@ -597,11 +600,11 @@ private function checkGeoGence(
597600

598601
$acceptAction = $notification->createAction();
599602
$acceptAction->setLabel('accept')
600-
->setLink('/apps/phonetrack', 'GET');
603+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
601604

602605
$declineAction = $notification->createAction();
603606
$declineAction->setLabel('decline')
604-
->setLink('/apps/phonetrack', 'GET');
607+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
605608

606609
$notification->setApp(Application::APP_ID)
607610
->setUser($aUserId)
@@ -705,11 +708,11 @@ private function checkQuota(int $deviceidToInsert, string $userid, string $devic
705708

706709
$acceptAction = $notification->createAction();
707710
$acceptAction->setLabel('accept')
708-
->setLink('/apps/phonetrack', 'GET');
711+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
709712

710713
$declineAction = $notification->createAction();
711714
$declineAction->setLabel('decline')
712-
->setLink('/apps/phonetrack', 'GET');
715+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
713716

714717
$notification->setApp(Application::APP_ID)
715718
->setUser($userid)

lib/Controller/OldPageController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use OCP\IRequest;
4242
use OCP\IURLGenerator;
4343
use OCP\IUserManager;
44+
use OCP\Notification\IAction;
4445
use OCP\Notification\IManager as INotificationManager;
4546
use Psr\Log\LoggerInterface;
4647
use XMLParser;
@@ -2606,11 +2607,11 @@ public function addUserShare($token, $userId) {
26062607

26072608
$acceptAction = $notification->createAction();
26082609
$acceptAction->setLabel('accept')
2609-
->setLink('/apps/phonetrack', 'GET');
2610+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
26102611

26112612
$declineAction = $notification->createAction();
26122613
$declineAction->setLabel('decline')
2613-
->setLink('/apps/phonetrack', 'GET');
2614+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
26142615

26152616
$notification->setApp(Application::APP_ID)
26162617
->setUser($userId)
@@ -2768,11 +2769,11 @@ public function deleteUserShare($token, $userId) {
27682769

27692770
$acceptAction = $notification->createAction();
27702771
$acceptAction->setLabel('accept')
2771-
->setLink('/apps/phonetrack', 'GET');
2772+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
27722773

27732774
$declineAction = $notification->createAction();
27742775
$declineAction->setLabel('decline')
2775-
->setLink('/apps/phonetrack', 'GET');
2776+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'), IAction::TYPE_GET);
27762777

27772778
$notification->setApp(Application::APP_ID)
27782779
->setUser($userId)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\PhoneTrack\Migration;
6+
7+
use Closure;
8+
use Doctrine\DBAL\Types\Type;
9+
use OCP\DB\Types;
10+
use OCP\Migration\IOutput;
11+
use OCP\Migration\SimpleMigrationStep;
12+
13+
class Version010200Date20260416223500 extends SimpleMigrationStep {
14+
15+
/**
16+
* Add the missing database columns for the Device and Session models
17+
* that weren't added when upgrading from <1 to 1.0
18+
* If they are already there, make sure they have the right type and make them unsigned
19+
*/
20+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
21+
$schema = $schemaClosure();
22+
$schemaChanged = false;
23+
24+
if ($schema->hasTable('phonetrack_devices')) {
25+
$table = $schema->getTable('phonetrack_devices');
26+
27+
if (!$table->hasColumn('line_enabled')) {
28+
$table->addColumn('line_enabled', Types::INTEGER, [
29+
'notnull' => true,
30+
'default' => 0,
31+
'unsigned' => true,
32+
]);
33+
$schemaChanged = true;
34+
} else {
35+
$column = $table->getColumn('line_enabled');
36+
if ($column->getType() !== Types::INTEGER || !$column->getUnsigned()) {
37+
$column->setType(Type::getType(Types::INTEGER));
38+
$column->setUnsigned(true);
39+
$schemaChanged = true;
40+
}
41+
}
42+
43+
if (!$table->hasColumn('auto_zoom')) {
44+
$table->addColumn('auto_zoom', Types::INTEGER, [
45+
'notnull' => true,
46+
'default' => 0,
47+
'unsigned' => true,
48+
]);
49+
$schemaChanged = true;
50+
} else {
51+
$column = $table->getColumn('auto_zoom');
52+
if ($column->getType() !== Types::INTEGER || !$column->getUnsigned()) {
53+
$column->setType(Type::getType(Types::INTEGER));
54+
$column->setUnsigned(true);
55+
$schemaChanged = true;
56+
}
57+
}
58+
59+
if (!$table->hasColumn('color_criteria')) {
60+
$table->addColumn('color_criteria', Types::INTEGER, [
61+
'notnull' => true,
62+
'default' => 0,
63+
'unsigned' => true,
64+
]);
65+
$schemaChanged = true;
66+
} else {
67+
$column = $table->getColumn('color_criteria');
68+
if ($column->getType() !== Types::INTEGER || !$column->getUnsigned()) {
69+
$column->setType(Type::getType(Types::INTEGER));
70+
$column->setUnsigned(true);
71+
$schemaChanged = true;
72+
}
73+
}
74+
75+
if (!$table->hasColumn('enabled')) {
76+
$table->addColumn('enabled', Types::INTEGER, [
77+
'notnull' => true,
78+
'default' => 0,
79+
'unsigned' => true,
80+
]);
81+
$schemaChanged = true;
82+
} else {
83+
$column = $table->getColumn('enabled');
84+
if ($column->getType() !== Types::INTEGER || !$column->getUnsigned()) {
85+
$column->setType(Type::getType(Types::INTEGER));
86+
$column->setUnsigned(true);
87+
$schemaChanged = true;
88+
}
89+
}
90+
}
91+
92+
if ($schema->hasTable('phonetrack_sessions')) {
93+
$table = $schema->getTable('phonetrack_sessions');
94+
95+
if (!$table->hasColumn('enabled')) {
96+
$table->addColumn('enabled', Types::INTEGER, [
97+
'notnull' => true,
98+
'default' => 0,
99+
'unsigned' => true,
100+
]);
101+
$schemaChanged = true;
102+
} else {
103+
$column = $table->getColumn('enabled');
104+
if ($column->getType() !== Types::INTEGER || !$column->getUnsigned()) {
105+
$column->setType(Type::getType(Types::INTEGER));
106+
$column->setUnsigned(true);
107+
$schemaChanged = true;
108+
}
109+
}
110+
}
111+
112+
return $schemaChanged ? $schema : null;
113+
}
114+
}

lib/Notification/Notifier.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public function prepare(INotification $notification, string $languageCode): INot
5151

5252
$notification->setParsedSubject($content)
5353
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
54-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
54+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
5555
return $notification;
5656
case 'leave_geofence':
5757
$p = $notification->getSubjectParameters();
5858
$content = $l10n->t('In session "%s", device "%s" exited geofencing zone "%s".', [$p[0], $p[1], $p[2]]);
5959

6060
$notification->setParsedSubject($content)
6161
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
62-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
62+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
6363
return $notification;
6464

6565
case 'close_proxim':
@@ -68,15 +68,15 @@ public function prepare(INotification $notification, string $languageCode): INot
6868

6969
$notification->setParsedSubject($content)
7070
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
71-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
71+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
7272
return $notification;
7373
case 'far_proxim':
7474
$p = $notification->getSubjectParameters();
7575
$content = $l10n->t('Device "%s" is now farther than %sm from "%s".', [$p[0], $p[1], $p[2]]);
7676

7777
$notification->setParsedSubject($content)
7878
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
79-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
79+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
8080
return $notification;
8181

8282
case 'quota_reached':
@@ -85,7 +85,7 @@ public function prepare(INotification $notification, string $languageCode): INot
8585

8686
$notification->setParsedSubject($content)
8787
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
88-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
88+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
8989
return $notification;
9090

9191
case 'add_user_share':
@@ -94,7 +94,7 @@ public function prepare(INotification $notification, string $languageCode): INot
9494

9595
$notification->setParsedSubject($content)
9696
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
97-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
97+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
9898
return $notification;
9999

100100
case 'delete_user_share':
@@ -103,7 +103,7 @@ public function prepare(INotification $notification, string $languageCode): INot
103103

104104
$notification->setParsedSubject($content)
105105
->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app_black.svg')))
106-
->setLink($this->url->linkToRouteAbsolute('phonetrack.page.index'));
106+
->setLink($this->url->linkToRouteAbsolute(Application::APP_ID . '.page.index'));
107107
return $notification;
108108

109109
default:

tests/php/controller/OldPageControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ protected function setUp(): void {
179179
Server::get(ShareMapper::class),
180180
Server::get(IDBConnection::class),
181181
Server::get(IMailer::class),
182+
Server::get(IURLGenerator::class),
182183
'test'
183184
);
184185

@@ -200,6 +201,7 @@ protected function setUp(): void {
200201
Server::get(ShareMapper::class),
201202
Server::get(IDBConnection::class),
202203
Server::get(IMailer::class),
204+
Server::get(IURLGenerator::class),
203205
'test2'
204206
);
205207

0 commit comments

Comments
 (0)