Skip to content

Commit

Permalink
Import old stories and journals into Firehose
Browse files Browse the repository at this point in the history
  • Loading branch information
pudge committed Oct 30, 2008
1 parent f7fec79 commit d255b25
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
10 changes: 5 additions & 5 deletions plugins/FireHose/FireHose.pm
Expand Up @@ -106,14 +106,14 @@ sub createUpdateItemFromJournal {
if ($journal) { if ($journal) {
my $globjid = $self->getGlobjidCreate("journals", $journal->{id}); my $globjid = $self->getGlobjidCreate("journals", $journal->{id});
my $globjid_q = $self->sqlQuote($globjid); my $globjid_q = $self->sqlQuote($globjid);
# XXX does this next line depend on the primary key being the my($itemid) = $self->sqlSelect("id", "firehose", "globjid=$globjid_q");
# first column returned by "SELECT *"? If I read that right,
# that's non-intuitive; we should select id by name instead. -Jamie
my($itemid) = $self->sqlSelect("*", "firehose", "globjid=$globjid_q");
if ($itemid) { if ($itemid) {
my $introtext = balanceTags(strip_mode($journal->{article}, $journal->{posttype}), { deep_nesting => 1 }); my $bodytext = balanceTags(strip_mode($journal->{article}, $journal->{posttype}), { deep_nesting => 1 });
my $introtext = $journal->{introtext} || $bodytext;

$self->setFireHose($itemid, { $self->setFireHose($itemid, {
introtext => $introtext, introtext => $introtext,
bodytext => $bodytext,
title => $journal->{description}, title => $journal->{description},
tid => $journal->{tid}, tid => $journal->{tid},
discussion => $journal->{discussion}, discussion => $journal->{discussion},
Expand Down
4 changes: 3 additions & 1 deletion plugins/Journal/Journal.pm
Expand Up @@ -42,6 +42,7 @@ sub set {
$self->sqlUpdate('journals', \%j1, "id=$id") if keys %j1; $self->sqlUpdate('journals', \%j1, "id=$id") if keys %j1;
$self->sqlUpdate('journals_text', \%j2, "id=$id") if $j2{article}; $self->sqlUpdate('journals_text', \%j2, "id=$id") if $j2{article};
if ($constants->{plugin}{FireHose}) { if ($constants->{plugin}{FireHose}) {
# XXX: this will not work with HumanConf!
my $reskey = getObject('Slash::ResKey'); my $reskey = getObject('Slash::ResKey');
my $rkey = $reskey->key('submit', { nostate => 1 }); my $rkey = $reskey->key('submit', { nostate => 1 });
if ($rkey && $rkey->createuse) { if ($rkey && $rkey->createuse) {
Expand Down Expand Up @@ -196,6 +197,7 @@ sub create {
my $slashdb = getCurrentDB(); my $slashdb = getCurrentDB();
$slashdb->setUser($user->{uid}, { journal_last_entry_date => $date }); $slashdb->setUser($user->{uid}, { journal_last_entry_date => $date });
if ($constants->{plugin}{FireHose}) { if ($constants->{plugin}{FireHose}) {
# XXX: this will not work with HumanConf!
my $reskey = getObject('Slash::ResKey'); my $reskey = getObject('Slash::ResKey');
my $rkey = $reskey->key('submit', { nostate => 1 }); my $rkey = $reskey->key('submit', { nostate => 1 });
if ($rkey && $rkey->createuse) { if ($rkey && $rkey->createuse) {
Expand Down Expand Up @@ -228,7 +230,7 @@ sub remove {
# if has been submitted as story or submission, don't # if has been submitted as story or submission, don't
# delete the discussion # delete the discussion
if ($journal->{promotetype} eq 'publicize' || $journal->{promotetype} eq "publish") { if ($journal->{promotetype} eq 'publicize' || $journal->{promotetype} eq "publish") {
my $kind = $self->getDiscussion($journal->{discussion}, 'kind'); my $kind = $self->getDiscussion($journal->{discussion}, 'dkid');
my $kinds = $self->getDescriptions('discussion_kinds'); my $kinds = $self->getDescriptions('discussion_kinds');
# set to disabled only if the journal has not been # set to disabled only if the journal has not been
# converted to a journal-story (it will get re-enabled # converted to a journal-story (it will get re-enabled
Expand Down
1 change: 1 addition & 0 deletions themes/slashcode/tasks/ircslash.pl
Expand Up @@ -356,6 +356,7 @@ sub getIRCData {
re => \&cmd_re, re => \&cmd_re,
d => \&cmd_roll, d => \&cmd_roll,


amihere => \&cmd_ha,
amiherenow => \&cmd_ha, amiherenow => \&cmd_ha,
amibacknow => \&cmd_ha, amibacknow => \&cmd_ha,
); );
Expand Down
25 changes: 15 additions & 10 deletions utils/import_journals_firehose
Expand Up @@ -3,24 +3,29 @@ use warnings;
use strict; use strict;


use Slash::Test shift || 'slash'; use Slash::Test shift || 'slash';
my $limit = shift || 100; my $limit = shift;

local $| = 1;
my $slashdb = getCurrentDB();
my $ids = $slashdb->sqlSelectColArrayref(
'journals.id', 'journals',
'journals.id NOT IN (SELECT firehose.srcid FROM firehose WHERE firehose.type = "journal") LIMIT ' . $limit
);


my $firehose = getObject("Slash::FireHose"); my $firehose = getObject("Slash::FireHose");
local $| = 1; my $journal = getObject("Slash::Journal");
printf STDERR "Importing %d journals\n", scalar(@$ids); printf STDERR "Fetching IDs ...\n";


my $slashdb = getCurrentDB();
my $ids = $slashdb->sqlSelectColArrayref('id', 'journals', '', ($limit ? "LIMIT $limit" : ()));
my $i = 0; my $i = 0;
my %ids; my %ids;

printf STDERR "\nImporting %d journals\n", scalar(@$ids);
for my $id (@$ids) { for my $id (@$ids) {
printf "\r%d", ++$i; printf "\r%d", ++$i;
my $introtext = $journal->getIntrotext($id);
$journal->sqlUpdate('journals_text',
{ introtext => $introtext },
"id = " . $journal->sqlQuote($id)
);
$ids{$id} = $firehose->createUpdateItemFromJournal($id); $ids{$id} = $firehose->createUpdateItemFromJournal($id);
} }
printf STDERR "\nImported %d journals\n", scalar(keys %ids);


my $string = join ';', map { "$_:$ids{$_}" } @$ids; my $string = join '; ', map { "$_:$ids{$_}" } @$ids;
print "\n$string\nDone\n"; print "\n$string\nDone\n";
29 changes: 29 additions & 0 deletions utils/import_stories_firehose
@@ -0,0 +1,29 @@
#!/usr/bin/perl
use warnings;
use strict;

use Slash::Test shift || 'slash';
my $limit = shift;
local $| = 1;

my $firehose = getObject("Slash::FireHose");
printf STDERR "Fetching IDs ...\n";

my $slashdb = getCurrentDB();
my $ids = $slashdb->sqlSelectColArrayref('stoid', 'stories', '', ($limit ? "LIMIT $limit" : ()));
my $i = 0;
my %ids;

printf STDERR "\nImporting %d stories\n", scalar(@$ids);
for my $id (@$ids) {
printf "\r%d", ++$i;
my $globjid = $slashdb->getGlobjidCreate("stories", $id);
my $fhid;
$fhid = $firehose->getFireHoseIdFromGlobjid($globjid) if $globjid;

$ids{$id} = $firehose->createItemFromStory($id) unless $fhid;
}
printf STDERR "\nImported %d stories\n", scalar(keys %ids);

my $string = join '; ', map { "$_:$ids{$_}" } sort { $a <=> $b } keys %ids;
print "\n$string\nDone\n";

0 comments on commit d255b25

Please sign in to comment.