Skip to content

Commit 772d30c

Browse files
committed
import comments
1 parent 511a8fb commit 772d30c

6 files changed

Lines changed: 219 additions & 3 deletions

File tree

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

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public function getQueue()
8989
}
9090
if (\in_array('dev.hanashi.wsdb.links.comment', $this->selectedData)) {
9191
$queue[] = 'dev.hanashi.wsdb.links.comment';
92-
}
93-
if (\in_array('dev.hanashi.wsdb.links.comment.response', $this->selectedData)) {
94-
$queue[] = 'dev.hanashi.wsdb.links.comment.response';
92+
if (\in_array('dev.hanashi.wsdb.links.comment.response', $this->selectedData)) {
93+
$queue[] = 'dev.hanashi.wsdb.links.comment.response';
94+
}
9595
}
9696
}
9797
}
@@ -533,6 +533,118 @@ public function exportOptionValues(int $offset, int $limit): void
533533
}
534534
}
535535

536+
public function countComments(): int
537+
{
538+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
539+
'com.woltlab.wcf.comment.commentableContent',
540+
'de.pehbeh.links.linkEntryComment'
541+
);
542+
if ($objectType === null) {
543+
return 0;
544+
}
545+
546+
$sql = "SELECT COUNT(*)
547+
FROM wcf1_comment
548+
WHERE objectTypeID = ?";
549+
$statement = $this->database->prepare($sql);
550+
$statement->execute([$objectType->objectTypeID]);
551+
552+
return $statement->fetchSingleColumn();
553+
}
554+
555+
public function exportComments(int $offset, int $limit): void
556+
{
557+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
558+
'com.woltlab.wcf.comment.commentableContent',
559+
'de.pehbeh.links.linkEntryComment'
560+
);
561+
if ($objectType === null) {
562+
return;
563+
}
564+
565+
$sql = "SELECT *
566+
FROM wcf1_comment
567+
WHERE objectTypeID = ?
568+
ORDER BY commentID";
569+
$statement = $this->database->prepare($sql, $limit, $offset);
570+
$statement->execute([$objectType->objectTypeID]);
571+
while ($row = $statement->fetchArray()) {
572+
$data = [
573+
'objectID' => $row['objectID'],
574+
'userID' => $row['userID'],
575+
'username' => $row['username'],
576+
'message' => $row['message'],
577+
'time' => $row['time'],
578+
'enableHtml' => (isset($row['enableHtml'])) ? $row['enableHtml'] : 0,
579+
'isDisabled' => (isset($row['isDisabled'])) ? $row['isDisabled'] : 0,
580+
];
581+
582+
ImportHandler::getInstance()
583+
->getImporter('dev.hanashi.wsdb.links.comment')
584+
->import($row['commentID'], $data);
585+
}
586+
}
587+
588+
public function countCommentResponses(): int
589+
{
590+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
591+
'com.woltlab.wcf.comment.commentableContent',
592+
'de.pehbeh.links.linkEntryComment'
593+
);
594+
if ($objectType === null) {
595+
return 0;
596+
}
597+
598+
$sql = "SELECT COUNT(*) AS count
599+
FROM wcf1_comment_response
600+
WHERE commentID IN (
601+
SELECT commentID
602+
FROM wcf1_comment
603+
WHERE objectTypeID = ?
604+
)";
605+
$statement = $this->database->prepare($sql);
606+
$statement->execute([$objectType->objectTypeID]);
607+
608+
return $statement->fetchSingleColumn();
609+
}
610+
611+
public function exportCommentResponses(int $offset, int $limit): void
612+
{
613+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
614+
'com.woltlab.wcf.comment.commentableContent',
615+
'de.pehbeh.links.linkEntryComment'
616+
);
617+
if ($objectType === null) {
618+
return;
619+
}
620+
621+
$sql = "SELECT *
622+
FROM wcf1_comment_response
623+
WHERE commentID IN (
624+
SELECT commentID
625+
FROM wcf1_comment
626+
WHERE objectTypeID = ?
627+
)
628+
ORDER BY responseID";
629+
$statement = $this->database->prepareUnmanaged($sql, $limit, $offset);
630+
$statement->execute([$objectType->objectTypeID]);
631+
while ($row = $statement->fetchArray()) {
632+
$data = [
633+
'commentID' => $row['commentID'],
634+
'time' => $row['time'],
635+
'userID' => $row['userID'],
636+
'username' => $row['username'],
637+
'message' => $row['message'],
638+
'enableHtml' => (isset($row['enableHtml'])) ? $row['enableHtml'] : 0,
639+
'isDisabled' => (isset($row['isDisabled'])) ? $row['isDisabled'] : 0,
640+
];
641+
642+
ImportHandler::getInstance()
643+
->getImporter('dev.hanashi.wsdb.links.comment.response')
644+
->import($row['responseID'], $data);
645+
}
646+
}
647+
536648
/**
537649
* @return array<int, string[]>
538650
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace wcf\system\wsdb\importer;
4+
5+
use wcf\data\comment\CommentEditor;
6+
use wcf\data\object\type\ObjectTypeCache;
7+
use wcf\system\importer\AbstractCommentImporter;
8+
use wcf\system\importer\ImportHandler;
9+
10+
final class LinkCommentImporter extends AbstractCommentImporter
11+
{
12+
/**
13+
* @inheritDoc
14+
*/
15+
protected $objectTypeName = 'dev.hanashi.wsdb.links.comment';
16+
17+
public function __construct()
18+
{
19+
$databaseID = ImportHandler::getInstance()->getNewID('dev.hanashi.wsdb.links', 1);
20+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
21+
'com.woltlab.wcf.comment.commentableContent',
22+
'com.woltlab.wsdb.db' . $databaseID . '.comment'
23+
);
24+
$this->objectTypeID = $objectType->objectTypeID;
25+
}
26+
27+
#[\Override]
28+
public function import($oldID, array $data, array $additionalData = [])
29+
{
30+
$recordID = ImportHandler::getInstance()->getNewID('dev.hanashi.wsdb.links.links', $data['objectID']);
31+
if (!$recordID) {
32+
return 0;
33+
}
34+
$data['objectID'] = $recordID;
35+
36+
$comment = CommentEditor::create(\array_merge($data, ['objectTypeID' => $this->objectTypeID]));
37+
38+
ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $comment->commentID);
39+
40+
return $comment->commentID;
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace wcf\system\wsdb\importer;
4+
5+
use wcf\data\comment\response\CommentResponseEditor;
6+
use wcf\system\importer\AbstractCommentResponseImporter;
7+
use wcf\system\importer\ImportHandler;
8+
use wcf\system\WCF;
9+
10+
final class LinkCommentResponseImporter extends AbstractCommentResponseImporter
11+
{
12+
/**
13+
* @inheritDoc
14+
*/
15+
protected $objectTypeName = 'dev.hanashi.wsdb.links.comment';
16+
17+
#[\Override]
18+
public function import($oldID, array $data, array $additionalData = [])
19+
{
20+
$data['commentID'] = ImportHandler::getInstance()->getNewID($this->objectTypeName, $data['commentID']);
21+
if (!$data['commentID']) {
22+
return 0;
23+
}
24+
25+
$response = CommentResponseEditor::create($data);
26+
27+
$sql = "SELECT responseID
28+
FROM wcf1_comment_response
29+
WHERE commentID = ?
30+
ORDER BY time ASC, responseID ASC";
31+
$statement = WCF::getDB()->prepare($sql, 5);
32+
$statement->execute([$response->commentID]);
33+
$responseIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
34+
35+
// update parent comment
36+
$sql = "UPDATE wcf1_comment
37+
SET responseIDs = ?,
38+
responses = responses + 1
39+
WHERE commentID = ?";
40+
$statement = WCF::getDB()->prepare($sql);
41+
$statement->execute([
42+
\serialize($responseIDs),
43+
$response->commentID,
44+
]);
45+
46+
return $response->responseID;
47+
}
48+
}

language/de.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.option"><![CDATA[Eingabefelder]]></item>
2424
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.links"><![CDATA[Links]]></item>
2525
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.option.values"><![CDATA[Eingabefeld-Werte]]></item>
26+
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.comment"><![CDATA[Kommentare]]></item>
27+
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.comment.response"><![CDATA[Antworten auf Kommentare]]></item>
2628
</category>
2729
</import>
2830
</language>

language/en.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.option"><![CDATA[Input options]]></item>
2424
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.links"><![CDATA[Links]]></item>
2525
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.option.values"><![CDATA[Values of input fields]]></item>
26+
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.comment"><![CDATA[Comments]]></item>
27+
<item name="wcf.acp.dataImport.data.dev.hanashi.wsdb.links.comment.response"><![CDATA[Answers to comments]]></item>
2628
</category>
2729
</import>
2830
</language>

objectType.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,15 @@
4141
<definitionname>com.woltlab.wcf.importer</definitionname>
4242
<classname>wcf\system\wsdb\importer\LinkOptionValuesImporter</classname>
4343
</type>
44+
<type>
45+
<name>dev.hanashi.wsdb.links.comment</name>
46+
<definitionname>com.woltlab.wcf.importer</definitionname>
47+
<classname>wcf\system\wsdb\importer\LinkCommentImporter</classname>
48+
</type>
49+
<type>
50+
<name>dev.hanashi.wsdb.links.comment.response</name>
51+
<definitionname>com.woltlab.wcf.importer</definitionname>
52+
<classname>wcf\system\wsdb\importer\LinkCommentResponseImporter</classname>
53+
</type>
4454
</import>
4555
</data>

0 commit comments

Comments
 (0)