Skip to content

Commit f5f322d

Browse files
committed
delete connection implemented
1 parent 628fc44 commit f5f322d

7 files changed

Lines changed: 120 additions & 0 deletions

File tree

files/lib/bootstrap/dev.hanashi.wsdb.connection.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

33
use wcf\command\wsdb\database\SetConnectionDatabasePages;
4+
use wcf\event\endpoint\ControllerCollecting;
45
use wcf\event\wsdb\database\DatabaseCreated;
56
use wcf\event\wsdb\interaction\user\RecordInteractionCollecting;
7+
use wcf\system\endpoint\controller\hanashi\wsdb\records\connections\DeleteConnection;
68
use wcf\system\event\EventHandler;
79
use wcf\system\event\listener\ConnectionWsdbRecordInteractionCollectingListener;
810

@@ -15,4 +17,11 @@
1517
EventHandler::getInstance()->register(DatabaseCreated::class, static function (DatabaseCreated $event): void {
1618
(new SetConnectionDatabasePages($event->database))();
1719
});
20+
21+
EventHandler::getInstance()->register(
22+
ControllerCollecting::class,
23+
static function (ControllerCollecting $event): void {
24+
$event->register(new DeleteConnection());
25+
}
26+
);
1827
};

files/lib/data/wsdb/record/connection/RecordConnectionAction.class.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace wcf\data\wsdb\record\connection;
44

55
use wcf\data\AbstractDatabaseObjectAction;
6+
use wcf\system\WCF;
67

78
/**
89
* @extends AbstractDatabaseObjectAction<RecordConnection, RecordConnectionEditor>
@@ -26,4 +27,17 @@ public function create(): RecordConnection
2627

2728
return parent::create();
2829
}
30+
31+
#[\Override]
32+
public function delete(): int
33+
{
34+
$sql = "DELETE FROM wcf1_wsdb_record_connection WHERE recordID = ? AND referencedRecordID = ?";
35+
$statement = WCF::getDB()->prepare($sql);
36+
37+
foreach ($this->getObjects() as $object) {
38+
$statement->execute([$object->referencedRecordID, $object->recordID]);
39+
}
40+
41+
return parent::delete();
42+
}
2943
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace wcf\event\wsdb\gridView\user;
4+
5+
use wcf\event\IPsr14Event;
6+
use wcf\system\wsdb\gridView\user\ConnectionGridView;
7+
8+
final class ConnectionGridViewInitialized implements IPsr14Event
9+
{
10+
public function __construct(public readonly ConnectionGridView $gridView)
11+
{
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace wcf\event\wsdb\interaction\user;
4+
5+
use wcf\event\IPsr14Event;
6+
use wcf\system\wsdb\interaction\user\ConnectionInteractions;
7+
8+
final class ConnectionInteractionCollecting implements IPsr14Event
9+
{
10+
public function __construct(public readonly ConnectionInteractions $provider)
11+
{
12+
}
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace wcf\system\endpoint\controller\hanashi\wsdb\records\connections;
4+
5+
use Laminas\Diactoros\Response\JsonResponse;
6+
use Psr\Http\Message\ResponseInterface;
7+
use Psr\Http\Message\ServerRequestInterface;
8+
use wcf\data\wsdb\record\connection\RecordConnection;
9+
use wcf\data\wsdb\record\connection\RecordConnectionAction;
10+
use wcf\http\Helper;
11+
use wcf\system\endpoint\DeleteRequest;
12+
use wcf\system\endpoint\IController;
13+
use wcf\system\exception\PermissionDeniedException;
14+
15+
#[DeleteRequest("/hanashi/wsdb/records/connections/{id:\\d+}")]
16+
final class DeleteConnection implements IController
17+
{
18+
#[\Override]
19+
public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
20+
{
21+
$connection = Helper::fetchObjectFromRequestParameter($variables['id'], RecordConnection::class);
22+
23+
if (!$connection->getRecord()->canEdit()) {
24+
throw new PermissionDeniedException();
25+
}
26+
27+
(new RecordConnectionAction([$connection], 'delete'))->executeAction();
28+
29+
return new JsonResponse([]);
30+
}
31+
}

files/lib/system/wsdb/gridView/user/ConnectionGridView.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use wcf\data\wsdb\record\connection\RecordConnection;
99
use wcf\data\wsdb\record\connection\RecordConnectionList;
1010
use wcf\data\wsdb\record\Record;
11+
use wcf\event\wsdb\gridView\user\ConnectionGridViewInitialized;
1112
use wcf\form\WsdbConnectionAddForm;
1213
use wcf\system\gridView\AbstractGridView;
1314
use wcf\system\gridView\AbstractGridViewRowLink;
@@ -20,6 +21,7 @@
2021
use wcf\system\view\filter\TextFilter;
2122
use wcf\system\WCF;
2223
use wcf\system\wsdb\cache\runtime\RecordRuntimeCache;
24+
use wcf\system\wsdb\interaction\user\ConnectionInteractions;
2325
use wcf\util\StringUtil;
2426

2527
/**
@@ -86,6 +88,9 @@ public function render(mixed $value, DatabaseObject $row, bool $isPrimaryColumn
8688
}
8789
);
8890

91+
$provider = new ConnectionInteractions();
92+
$this->setInteractionProvider($provider);
93+
8994
$this->setDefaultSortField('title');
9095
}
9196

@@ -127,6 +132,12 @@ protected function createObjectList(): DatabaseObjectList
127132
return $list;
128133
}
129134

135+
#[\Override]
136+
protected function getInitializedEvent(): ConnectionGridViewInitialized
137+
{
138+
return new ConnectionGridViewInitialized($this);
139+
}
140+
130141
public function getConnectionAddFormLink(): string
131142
{
132143
return LinkHandler::getInstance()->getControllerLink(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace wcf\system\wsdb\interaction\user;
4+
5+
use wcf\data\wsdb\record\connection\RecordConnection;
6+
use wcf\event\wsdb\interaction\user\ConnectionInteractionCollecting;
7+
use wcf\system\event\EventHandler;
8+
use wcf\system\interaction\AbstractInteractionProvider;
9+
use wcf\system\interaction\DeleteInteraction;
10+
11+
final class ConnectionInteractions extends AbstractInteractionProvider
12+
{
13+
public function __construct()
14+
{
15+
$this->addInteractions([
16+
new DeleteInteraction("hanashi/wsdb/records/connections/%s"),
17+
]);
18+
19+
EventHandler::getInstance()->fire(
20+
new ConnectionInteractionCollecting($this)
21+
);
22+
}
23+
24+
#[\Override]
25+
public function getObjectClassName(): string
26+
{
27+
return RecordConnection::class;
28+
}
29+
}

0 commit comments

Comments
 (0)