[dw-free] Allow importing of your journal from another LiveJournal-based site.
[commit: http://hg.dwscoalition.org/dw-free/rev/76012a72e138]
http://bugs.dwscoalition.org/show_bug.cgi?id=114
Tonight's work on the importer: enable entry importing, disable ESN events
for imported entries, make polls links and not just removing them.
Patch by
mark.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=114
Tonight's work on the importer: enable entry importing, disable ESN events
for imported entries, make polls links and not just removing them.
Patch by
Files modified:
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm
- cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm
- cgi-bin/ljprotocol.pl
- htdocs/misc/import.bml
--------------------------------------------------------------------------------
diff -r fe1d3e12654a -r 76012a72e138 cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm Fri Feb 27 07:44:45 2009 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Entries.pm Fri Feb 27 10:29:16 2009 +0000
@@ -123,11 +123,9 @@ sub try_work {
my $event = $evt->{event};
- if ( $event =~ m/<.+?-poll-.+?>/ ) {
- $event =~ s/<.+?-poll-.+?>//g;
-
- push @item_errors, "Entry contained a poll, please manually re-add the poll.";
- }
+ # we just link polls to the original site
+# FIXME: this URL should be from some method and not manually constructed
+ $event =~ s!<.+?-poll-(\d+?)>![<a href="http://www.$data->{hostname}/poll/?id=$1">Poll #$1</a>]!g;
if ( $event =~ m/<.+?-embed-.+?>/ ) {
$event =~ s/<.+?-embed-.+?>//g;
diff -r fe1d3e12654a -r 76012a72e138 cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm Fri Feb 27 07:44:45 2009 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/FriendGroups.pm Fri Feb 27 10:29:16 2009 +0000
@@ -66,7 +66,8 @@ sub try_work {
# FIXME: what do we do on error case? well, hopefully that will be rare...
$dbh->do(
q{UPDATE import_items SET status = 'ready'
- WHERE userid = ? AND item = 'lj_friends' AND import_data_id = ? AND status = 'init'},
+ WHERE userid = ? AND item IN ('lj_friends', 'lj_entries')
+ AND import_data_id = ? AND status = 'init'},
undef, $u->id, $opts->{import_data_id}
);
diff -r fe1d3e12654a -r 76012a72e138 cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm
--- a/cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm Fri Feb 27 07:44:45 2009 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm Fri Feb 27 10:29:16 2009 +0000
@@ -138,6 +138,7 @@ sub post_event {
{
u => $u,
noauth => 1,
+ nonotify => 1,
}
);
diff -r fe1d3e12654a -r 76012a72e138 cgi-bin/ljprotocol.pl
--- a/cgi-bin/ljprotocol.pl Fri Feb 27 07:44:45 2009 +0000
+++ b/cgi-bin/ljprotocol.pl Fri Feb 27 10:29:16 2009 +0000
@@ -1553,8 +1553,12 @@ sub postevent
$res->{'anum'} = $anum;
$res->{'url'} = $entry->url;
- push @jobs, LJ::Event::JournalNewEntry->new($entry)->fire_job;
- push @jobs, LJ::Event::UserNewEntry->new($entry)->fire_job if (!$LJ::DISABLED{'esn-userevents'} || $LJ::_T_FIRE_USERNEWENTRY);
+ # if the caller told us not to fire events (importer?) then skip the user events,
+ # but still fire the logging events
+ unless ( $flags->{nonotify} ) {
+ push @jobs, LJ::Event::JournalNewEntry->new($entry)->fire_job;
+ push @jobs, LJ::Event::UserNewEntry->new($entry)->fire_job if (!$LJ::DISABLED{'esn-userevents'} || $LJ::_T_FIRE_USERNEWENTRY);
+ }
push @jobs, LJ::EventLogRecord::NewEntry->new($entry)->fire_job;
my $sclient = LJ::theschwartz();
diff -r fe1d3e12654a -r 76012a72e138 htdocs/misc/import.bml
--- a/htdocs/misc/import.bml Fri Feb 27 07:44:45 2009 +0000
+++ b/htdocs/misc/import.bml Fri Feb 27 10:29:16 2009 +0000
@@ -59,16 +59,27 @@ body<=
);
return "Database error." if $dbh->err;
+ # okay, this is kinda hacky but turn on the right things so we can do
+ # a proper entry import...
+ if ( $POST{lj_entries} ) {
+ $POST{lj_tags} = 1;
+ $POST{lj_friendgroups} = 1;
+ }
+
+ # default job status
my @jobs = (
- ['lj_userpics', 'ready'],
- ['lj_bio', 'ready'],
- ['lj_tags', 'ready'],
+ ['lj_userpics', 'ready'],
+ ['lj_bio', 'ready'],
+ ['lj_tags', 'ready'],
['lj_friendgroups', 'ready'],
- ['lj_friends', 'init'],
- ['lj_entries', 'init'],
+# ['lj_friends', 'init' ],
+ ['lj_entries', 'init' ],
);
+
# schedule userpic, bio, and tag imports
- foreach my $item (@jobs) {
+ foreach my $item ( @jobs ) {
+ next unless $POST{$item->[0]};
+
$dbh->do(
"INSERT INTO import_items (userid, item, status, created, import_data_id, priority) " .
"VALUES (?, ?, ?, UNIX_TIMESTAMP(), ?, UNIX_TIMESTAMP())",
@@ -129,17 +140,58 @@ body<=
# now let them do the rest...
my $authas = LJ::make_authas_select( $remote, { authas => $u->user } );
- $ret .= "<?h2 Start Import Job h2?><?p <form method='get'>$authas</form> p?><br />";
+ $authas = "<?p <form method='get'>$authas</form> p?><br />"
+ if $authas =~ /select/i;
+
+ # give selection table
+ $ret .= "<?h2 Start Import Job h2?>$authas";
$ret .= "<form method='post'>" . LJ::form_auth();;
+ $ret .= <<EOF;
- $ret .= "<input type='text' name='username' maxlength='15'> username<br />";
- $ret .= "<input type='password' name='password' maxlength='15'> password<br />";
- $ret .= "<select name='hostname'><option value='livejournal.com'>LiveJournal.com</option></select><br />";
- $ret .= "<br />";
- $ret .= "Clicking submit below will cause import jobs to be queued to import your userpics, your ";
- $ret .= "tags, and your bio fields. You can check this page for status.<br />";
- $ret .= "<strong>This option now imports your friend groups, friends, and entries.</strong><br />";
- $ret .= "<input type='submit' value='Do it!'></form>";
+<table>
+ <tr><td>Username:</td><td><input type='text' name='username' maxlength='15'></td></tr>
+ <tr><td>Password:</td><td><input type='password' name='password' maxlength='25'></td></tr>
+ <tr><td></td><td>
+ <select name='hostname'>
+ <option value='livejournal.com'>LiveJournal.com</option>
+ <option value='insanejournal.org'>Insane Journal</option>
+ </select>
+ </td></tr>
+ <tr><td colspan='2'> </td></tr>
+
+EOF
+
+ # checkbox easier this way
+ my %opts = (
+ lj_entries => [ 0, 'Import all journal entries. Implies: tags, friendgroups.' ],
+ lj_tags => [ 1, 'Import list of tags.' ],
+ lj_userpics => [ 1, 'Import icons (aka userpics).' ],
+ lj_bio => [ 1, 'Import bio field for profile.' ],
+# lj_friends => [ 0, 'Import friends as OpenID/feed accounts.' ],
+ lj_friendgroups => [ 1, 'Import friend groups as trust groups.' ],
+ );
+
+ foreach my $key ( sort keys %opts ) {
+ $ret .= "<tr><td></td><td>" .
+ LJ::html_check( { name => $key, id => $key, label => $opts{$key}->[1], selected => $opts{$key}->[0] } ) .
+ "</td></tr>\n";
+ }
+
+ $ret .= <<EOF;
+ <tr><td colspan='2'> </td></tr>
+</table>
+
+<?p
+ This will immediately kick off some jobs to import the selected items. Please make sure
+ you are okay with this data being imported. You will be able to watch status by checking
+ your site inbox to look for messages. <em>This action is not reversible.</em>
+p?>
+
+<?p <input type='submit' value='Import' /> p?>
+
+</form>
+EOF
+
return $ret;
}
_code?>
--------------------------------------------------------------------------------
