sub _generalize {
my ($self, $submission) = @_;
+ return if !$submission;
+ return {} if (keys %$submission == 0);
+
$submission->{title} = $submission->{subj};
$submission->{introtext} = $submission->{story};
- my @tags = split /\s+/, $submission->{toptags};
- $submission->{toptags} = \@tags;
- my $primary_topic = {};
- for my $item (qw(tid keyword textname series image width height submittable searchable storypickable usesprite)) {
- $primary_topic->{$item} = $submission->{$item};
+ if ($submission->{toptags}) {
+ my @tags = split /\s+/, $submission->{toptags};
+ $submission->{toptags} = \@tags;
+ my $primary_topic = {};
+ for my $item (qw(tid keyword textname series image width height submittable searchable storypickable usesprite)) {
+ $primary_topic->{$item} = $submission->{$item};
+ }
+ $submission->{primary_topic} = $primary_topic;
+ $submission->{topics} = [$primary_topic,];
}
- $submission->{primary_topic} = $primary_topic;
- $submission->{topics} = [$primary_topic,];
$submission->{content_type} = 'submission';
return $submission;
# temporary function from slash (Slash::Utility::Data)
- my $dbh = $self->connect_db({AutoCommit => 0,});
+ my $dbh = $self->start_transaction;
my $sql = <<"EOSQL";
INSERT INTO submissions
(email, emaildomain, name, time, subj, story, tid, primaryskid, uid, ipid, subnetid, signature)
$params->{url_id} = 0;
}
+ # check signature
+ my $sig = $self->generate_signature($params->{introtext}, $params->{title});
+ my $rs = $self->select(signature => $sig);
+ if ($rs) {
+ $self->set_error("duplicated signature");
+ $self->rollback;
+ return 0;
+ }
$dbh->do($sql, undef,
$params->{email}, #email
# error occured
$self->set_errorno($dbh->{mysql_errno});
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
$sql = "INSERT INTO submission_param (subid, name, value) VALUES (?, ?, ?)";
# error occured
$self->set_errorno($dbh->{mysql_errno});
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
push @param_ids, $param_id;
}
# get creationtime
my $sth = $dbh->prepare("SELECT time FROM submissions WHERE subid = ?");
$sth->execute($sub_id);
- my $rs = $sth->fetchrow_hashref;
+ $rs = $sth->fetchrow_hashref;
if (!$rs) {
# error occured
$self->set_errorno($dbh->{mysql_errno});
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
$sth->finish;
my $create_time = $rs->{time};
# error occured
warn "invalid globjid";
$self->set_error("invalid globjid");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
# TODO: sprite_info column don't have default value...
# error occured
$self->set_errorno($dbh->{mysql_errno});
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
my $firehose_id = $dbh->last_insert_id(undef, undef, undef, undef);
# error occured
$self->set_errorno($dbh->{mysql_errno});
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
my $firehose_text_id = $dbh->last_insert_id(undef, undef, undef, undef);
# error occured
$self->set_errorno($discuss->last_error);
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
$sql = "UPDATE firehose SET discussion = ? WHERE id = ?";
$rs = $dbh->do($sql, undef, $discussion_id, $firehose_id);
# error occured
$self->set_errorno($dbh->{mysql_errno});
$self->set_error("mysql_error");
- $dbh->rollback;
- $self->disconnect_db;
- return undef;
+ $self->rollback;
+ return;
}
- $dbh->commit;
- $self->disconnect_db;
+ $self->commit;
return $sub_id;
}