Skip to content

Commit

Permalink
Add clarity and data checks to Flarum target
Browse files Browse the repository at this point in the history
  • Loading branch information
linc committed Dec 26, 2022
1 parent 6a037a0 commit 86e05ee
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions src/Target/Flarum.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public function run(ExportModel $ex)
$ex->ignoreDuplicates('users');

$this->users($ex);
$this->roles($ex); // Groups
$this->categories($ex); // Tags
$this->roles($ex); // 'Groups' in Flarum
$this->categories($ex); // 'Tags' in Flarum

// No permissions warning.
$ex->comment('Permissions are not migrated. Verify all permissions afterward.');
Expand All @@ -190,19 +190,14 @@ public function run(ExportModel $ex)
Formatter::instance($ex); // @todo Hook for pre-UGC import?
$this->discussions($ex);
$this->bookmarks($ex); // flarum/subscriptions
$this->comments($ex); // Posts
$this->bookmarks($ex); // Requires addon `flarum/subscriptions`
$this->comments($ex); // 'Posts' in Flarum

if ($ex->targetExists('PORT_Badge')) {
$this->badges($ex); // 17development/flarum-user-badges
}
if ($ex->targetExists('PORT_Poll')) {
$this->polls($ex); // fof/pollsx
}
if ($ex->targetExists('PORT_ReactionType')) {
$this->reactions($ex); //
}
$this->privateMessages($ex);
$this->badges($ex); // Requires addon `17development/flarum-user-badges`
$this->polls($ex); // Requires addon `fof/pollsx`
$this->reactions($ex); // Requires addon `fof/reactions`

$this->privateMessages($ex); // Requires addon `fof/byobu`

$this->attachments($ex); // Requires discussions, comments, and PMs have imported.
}
Expand Down Expand Up @@ -255,6 +250,12 @@ protected function users(ExportModel $ex): void
*/
protected function roles(ExportModel $ex): void
{
// Verify support.
if (!$ex->targetExists('PORT_UserRole')) {
$ex->comment('Skipping import: Roles (Source lacks support)');
return;
}

// Delete orphaned user role associations (deleted users).
$ex->pruneOrphanedRecords('PORT_UserRole', 'UserID', 'PORT_User', 'UserID');

Expand Down Expand Up @@ -388,6 +389,12 @@ protected function discussions(ExportModel $ex): void
*/
protected function bookmarks(ExportModel $ex): void
{
// Verify support.
if (!$ex->targetExists('PORT_UserDiscussion')) {
$ex->comment('Skipping import: Bookmarks (Source lacks support)');
return;
}

$structure = [
'discussion_id' => 'int',
'user_id' => 'int',
Expand Down Expand Up @@ -486,6 +493,12 @@ protected function comments(ExportModel $ex): void
*/
protected function attachments(ExportModel $ex): void
{
// Verify support.
if (!$ex->targetExists('PORT_Media')) {
$ex->comment('Skipping import: Attachments (Source lacks support)');
return;
}

$structure = [
'id' => 'int',
'actor_id' => 'int',
Expand Down Expand Up @@ -539,6 +552,12 @@ protected function attachments(ExportModel $ex): void
*/
protected function badges(ExportModel $ex): void
{
// Verify support.
if (!$ex->targetExists('PORT_Badge')) {
$ex->comment('Skipping import: Badges (Source lacks support)');
return;
}

// Badge Categories
// One category is added in postscript.

Expand Down Expand Up @@ -595,6 +614,12 @@ protected function badges(ExportModel $ex): void
*/
protected function polls(ExportModel $ex): void
{
// Verify support.
if (!$ex->targetExists('PORT_Poll')) {
$ex->comment('Skipping import: Polls (Source lacks support)');
return;
}

// Polls
$structure = [
'id' => 'int',
Expand Down Expand Up @@ -677,6 +702,12 @@ protected function polls(ExportModel $ex): void
*/
public function reactions(ExportModel $ex)
{
// Verify support.
if (!$ex->targetExists('PORT_ReactionType')) {
$ex->comment('Skipping import: Reactions (Source lacks support)');
return;
}

// Reaction Types
$structure = [
'id' => 'int',
Expand Down Expand Up @@ -752,6 +783,12 @@ public function reactions(ExportModel $ex)
*/
protected function privateMessages(ExportModel $ex)
{
// Verify support.
if (!$ex->targetExists('PORT_Conversation')) {
$ex->comment('Skipping import: Private messages (Source lacks support)');
return;
}

// Messages — Discussions
$MaxDiscussionID = $this->messageDiscussionOffset = $this->getMaxDiscussionID($ex);
$ex->comment('Discussions offset for PMs is ' . $MaxDiscussionID);
Expand Down

0 comments on commit 86e05ee

Please sign in to comment.