Skip to content

Commit e199905

Browse files
committed
add acl import
1 parent fcaa673 commit e199905

5 files changed

Lines changed: 165 additions & 1 deletion

File tree

files/lib/system/wsdb/exporter/LinkDatabaseExporter.class.php

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class LinkDatabaseExporter extends AbstractExporter
2020
'dev.hanashi.wsdb.links' => 'Database',
2121
'dev.hanashi.wsdb.links.permission' => 'Permissions',
2222
'dev.hanashi.wsdb.links.category' => 'Categories',
23-
'dev.hanashi.wsdb.links.category.acl' => 'CategoryACL',
23+
'dev.hanashi.wsdb.links.category.acl' => 'CategoryACLs',
2424
'dev.hanashi.wsdb.links.option' => 'Option',
2525
'dev.hanashi.wsdb.links.links' => 'Links',
2626
'dev.hanashi.wsdb.links.comment' => 'Comment',
@@ -69,8 +69,12 @@ public function getQueue()
6969
if (\in_array('dev.hanashi.wsdb.links.permission', $this->selectedData)) {
7070
$queue[] = 'dev.hanashi.wsdb.links.permission';
7171
}
72+
7273
if (\in_array('dev.hanashi.wsdb.links.category', $this->selectedData)) {
7374
$queue[] = 'dev.hanashi.wsdb.links.category';
75+
if (\in_array('dev.hanashi.wsdb.links.category.acl', $this->selectedData)) {
76+
$queue[] = 'dev.hanashi.wsdb.links.category.acl';
77+
}
7478
}
7579
}
7680

@@ -292,6 +296,100 @@ public function exportCategories(int $offset, int $limit): void
292296
}
293297
}
294298

299+
public function countCategoryACLs(): int
300+
{
301+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
302+
'com.woltlab.wcf.acl',
303+
'de.pehbeh.links.category'
304+
);
305+
if ($objectType === null) {
306+
return 0;
307+
}
308+
309+
$sql = "SELECT (
310+
SELECT COUNT(*)
311+
FROM wcf1_acl_option_to_group acl_option_to_group
312+
INNER JOIN wcf1_acl_option acl_option
313+
ON acl_option.optionID = acl_option_to_group.optionID
314+
WHERE acl_option.objectTypeID = ?
315+
) + (
316+
SELECT COUNT(*)
317+
FROM wcf1_acl_option_to_user acl_option_to_user
318+
INNER JOIN wcf1_acl_option acl_option
319+
ON acl_option.optionID = acl_option_to_user.optionID
320+
WHERE acl_option.objectTypeID = ?
321+
) AS count";
322+
$statement = $this->database->prepare($sql);
323+
$statement->execute([$objectType->objectTypeID, $objectType->objectTypeID]);
324+
325+
return $statement->fetchSingleColumn();
326+
}
327+
328+
public function exportCategoryACLs(int $offset, int $limit): void
329+
{
330+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
331+
'com.woltlab.wcf.acl',
332+
'de.pehbeh.links.category'
333+
);
334+
if ($objectType === null) {
335+
return;
336+
}
337+
338+
$aclMap = [
339+
'canViewCategory' => [
340+
'canViewCategory',
341+
'canViewRecord',
342+
],
343+
'canAddLinkEntry' => [
344+
'canAddRecord',
345+
],
346+
];
347+
348+
$sql = "(
349+
SELECT acl_option.optionName, acl_option.optionID,
350+
option_to_group.objectID, option_to_group.optionValue, 0 AS userID, option_to_group.groupID
351+
FROM wcf1_acl_option_to_group option_to_group,
352+
wcf1_acl_option acl_option
353+
WHERE acl_option.optionID = option_to_group.optionID
354+
AND acl_option.objectTypeID = ?
355+
)
356+
UNION
357+
(
358+
SELECT acl_option.optionName, acl_option.optionID,
359+
option_to_user.objectID, option_to_user.optionValue, option_to_user.userID, 0 AS groupID
360+
FROM wcf1_acl_option_to_user option_to_user,
361+
wcf1_acl_option acl_option
362+
WHERE acl_option.optionID = option_to_user.optionID
363+
AND acl_option.objectTypeID = ?
364+
)
365+
ORDER BY optionID, objectID, userID, groupID";
366+
$statement = $this->database->prepareUnmanaged($sql, $limit, $offset);
367+
$statement->execute([$objectType->objectTypeID, $objectType->objectTypeID]);
368+
while ($row = $statement->fetchArray()) {
369+
$acls = $aclMap[$row['optionName']] ?? [];
370+
foreach ($acls as $acl) {
371+
$data = [
372+
'objectID' => $row['objectID'],
373+
'optionValue' => $row['optionValue'],
374+
];
375+
if ($row['userID']) {
376+
$data['userID'] = $row['userID'];
377+
}
378+
if ($row['groupID']) {
379+
$data['groupID'] = $row['groupID'];
380+
}
381+
382+
ImportHandler::getInstance()
383+
->getImporter('dev.hanashi.wsdb.links.category.acl')
384+
->import(
385+
0,
386+
$data,
387+
['optionName' => $acl]
388+
);
389+
}
390+
}
391+
}
392+
295393
/**
296394
* @param string[] $i18nValues
297395
* @return string[][][]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace wcf\system\wsdb\importer;
4+
5+
use wcf\data\object\type\ObjectTypeCache;
6+
use wcf\system\importer\AbstractACLImporter;
7+
use wcf\system\importer\ImportHandler;
8+
use wcf\system\WCF;
9+
10+
final class LinkCategoryACLImporter extends AbstractACLImporter
11+
{
12+
/**
13+
* @inheritDoc
14+
*/
15+
protected $objectTypeName = 'dev.hanashi.wsdb.links.category';
16+
17+
public function __construct()
18+
{
19+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
20+
'com.woltlab.wcf.acl',
21+
'com.woltlab.wsdb.category'
22+
);
23+
$this->objectTypeID = $objectType->objectTypeID;
24+
25+
parent::__construct();
26+
}
27+
28+
#[\Override]
29+
public function import($oldID, array $data, array $additionalData = [])
30+
{
31+
if (!isset($this->options[$additionalData['optionName']])) {
32+
return 0;
33+
}
34+
$data['optionID'] = $this->options[$additionalData['optionName']];
35+
36+
$data['objectID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['objectID']);
37+
if (!$data['objectID']) {
38+
return 0;
39+
}
40+
41+
if (!empty($data['groupID'])) {
42+
$sql = "INSERT IGNORE INTO wcf1_acl_option_to_group
43+
(optionID, objectID, groupID, optionValue)
44+
VALUES (?, ?, ?, ?)";
45+
$statement = WCF::getDB()->prepare($sql);
46+
$statement->execute([$data['optionID'], $data['objectID'], $data['groupID'], $data['optionValue']]);
47+
48+
return 1;
49+
} elseif (!empty($data['userID'])) {
50+
$sql = "INSERT IGNORE INTO wcf1_acl_option_to_user
51+
(optionID, objectID, userID, optionValue)
52+
VALUES (?, ?, ?, ?)";
53+
$statement = WCF::getDB()->prepare($sql);
54+
$statement->execute([$data['optionID'], $data['objectID'], $data['userID'], $data['optionValue']]);
55+
56+
return 1;
57+
}
58+
}
59+
}

language/de.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links"><![CDATA[Linkdatenbank]]></item>
2020
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.permission"><![CDATA[Berechtigungen]]></item>
2121
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.category"><![CDATA[Kategorien]]></item>
22+
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.category.acl"><![CDATA[Kategorie-Berechtigungen]]></item>
2223
</category>
2324
</import>
2425
</language>

language/en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links"><![CDATA[Link database]]></item>
2020
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.permission"><![CDATA[Permissions]]></item>
2121
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.category"><![CDATA[Categories]]></item>
22+
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.category.acl"><![CDATA[Category permissions]]></item>
2223
</category>
2324
</import>
2425
</language>

objectType.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,10 @@
2121
<definitionname>com.woltlab.wcf.importer</definitionname>
2222
<classname>wcf\system\wsdb\importer\LinkPermissionImporter</classname>
2323
</type>
24+
<type>
25+
<name>dev.hanashi.wsdb.links.category.acl</name>
26+
<definitionname>com.woltlab.wcf.importer</definitionname>
27+
<classname>wcf\system\wsdb\importer\LinkCategoryACLImporter</classname>
28+
</type>
2429
</import>
2530
</data>

0 commit comments

Comments
 (0)