1 package Newslash::Model::Stories;
2 use Newslash::Model::Base -base;
4 use Newslash::Model::SlashDB;
6 use Newslash::Model::Stories::Text;
7 use Newslash::Model::Stories::RelatedStories;
10 use DateTime::Format::MySQL;
11 use DateTime::Format::ISO8601;
12 use List::Util q(any);
23 datetime => [qw(time last_update day_published
24 stuckendtime archive_last_update
26 other => [qw(uid dept hits discussion primaryskid
27 tid submitter commentcount hitparade
29 qid body_length word_count sponsor
30 stuck stuckpos fakeemail homepage
32 aliases => { user_id => "uid",
39 use constant FACULTIES => { 1000 => [qw(hits hitparade)] };
44 SELECT uid, COUNT(stoid) AS count
46 WHERE stories.time <= NOW()
50 my $dbh = $self->connect_db;
51 my $sth = $dbh->prepare($sql);
53 my $rs = $sth->fetchall_hashref("uid");
55 $self->set_error("select failed", $dbh->errstr, $dbh->err);
65 my $join = 'LEFT JOIN firehose ON (stories.stoid = firehose.srcid AND firehose.type = "story")';
66 my $where = 'firehose.public != "no"';
67 return $self->generic_count(table => "stories",
76 sub text { return shift->_get_model('::Stories::Text'); }
77 sub related_stories { return shift->_get_model('::Stories::RelatedStories'); }
80 my ($self, $class) = @_;
81 $self->{sub_models} ||= {};
82 if (!$self->{sub_models}->{$class}) {
83 $self->{sub_models}->{$class} = $self->new_instance_of($class);
86 if ($self->transaction_mode && !$self->{sub_models}->{$class}->transaction_mode) {
87 $self->{sub_models}->{$class}->use_transaction($self->{_tr_dbh});
90 return $self->{sub_models}->{$class};
93 #========================================================================
95 =head2 select($query_type, $value)
107 query key, "sid" or "stoid"
117 HASH of story contents
128 my $unique_keys = { id => "stories.stoid",
129 story_id => "stories.stoid",
130 stoid => "stories.stoid",
131 sid => "stories.sid",
133 my $keys = { user_id => "stories.uid",
134 uid => "stories.uid",
135 topic_id => "stories.tid",
136 tid => "stories.tid",
137 discussion_id => "stories.discussion",
138 commentcount => "stories.commentcount",
139 hits => "stories.hits",
140 submitter => "stories.submitter",
141 create_time => "stories.time",
142 update_time => "stories.last_update",
143 public => "firehose.public",
145 my $datetime_keys = { create_time => "stories.time",
146 update_time => "stories.last_update",
148 my $timestamp = "stories.time";
150 my ($where_clause, $where_values, $unique) = $self->build_where_clause(unique_keys => $unique_keys,
152 datetime_keys => $datetime_keys,
153 timestamp => $timestamp,
155 my ($limit_clause, $limit_values) = $self->build_limit_clause(params => $params);
156 my ($orderby_clause, $orderby_values) = $self->build_order_by_clause(keys => $keys,
159 # TODO: give reasonable LIMIT Value...
160 $limit_clause = "LIMIT 50" if !$limit_clause;
164 if ($params->{hide_future}) {
165 push @where_clauses, "stories.time <= NOW()";
168 # hide non-public story?
169 if ($params->{public_only}) {
170 push @where_clauses, "firehose.public != 'no'";
173 # exclude "preview" item
174 push @where_clauses, "globj_types.maintable != 'preview'";
176 if (@where_clauses) {
178 $where_clause = $where_clause . " AND ";
181 $where_clause = "WHERE ";
183 $where_clause = $where_clause . join(" AND ", @where_clauses);
187 push @attrs, @$where_values, @$limit_values, @$orderby_values;
189 my $dbh = $self->connect_db;
193 users.nickname as author,
201 discussions.type AS discussion_type,
202 discussions.commentcount AS comment_count
205 ON stories.stoid = story_text.stoid
207 ON stories.uid = users.uid
209 ON (stories.stoid = firehose.srcid AND firehose.type = "story")
210 LEFT JOIN discussions
211 ON firehose.discussion = discussions.id
213 ON firehose.globjid = globjs.globjid
214 LEFT JOIN globj_types
215 ON globjs.gtid = globj_types.gtid
221 $self->_last_query($sql, \@attrs);
223 my $sth = $dbh->prepare($sql);
224 $sth->execute(@attrs);
225 my $stories = $sth->fetchall_arrayref({});
228 $self->disconnect_db();
231 if (@$stories == 0) {
232 $self->disconnect_db();
233 return $unique ? undef : [];
238 SELECT tags.*, tagnames.tagname, target.stoid
239 FROM (SELECT stories.stoid FROM stories
241 ON (stories.stoid = firehose.srcid AND firehose.type = "story")
243 ON firehose.globjid = globjs.globjid
244 LEFT JOIN globj_types
245 ON globjs.gtid = globj_types.gtid
246 $where_clause $orderby_clause $limit_clause) AS target
248 ON target.stoid = globjs.target_id
249 LEFT JOIN globj_types
250 ON globjs.gtid = globj_types.gtid
252 ON globjs.globjid = tags.globjid
254 ON tags.tagnameid = tagnames.tagnameid
255 WHERE globjs.gtid = 1
258 $sth = $dbh->prepare($sql);
259 $sth->execute(@attrs);
260 my $tags_table = $sth->fetchall_arrayref({});
264 SELECT story_topics_rendered.*, story_topics_chosen.weight, topics.*
265 FROM (SELECT stories.stoid FROM stories
267 ON (stories.stoid = firehose.srcid AND firehose.type = "story")
269 ON firehose.globjid = globjs.globjid
270 LEFT JOIN globj_types
271 ON globjs.gtid = globj_types.gtid
272 $where_clause $orderby_clause $limit_clause) AS target
273 LEFT JOIN story_topics_rendered
274 ON target.stoid = story_topics_rendered.stoid
275 LEFT JOIN story_topics_chosen
276 ON story_topics_rendered.stoid = story_topics_chosen.stoid
277 AND story_topics_rendered.tid = story_topics_chosen.tid
279 ON story_topics_rendered.tid = topics.tid
282 $sth = $dbh->prepare($sql);
283 $sth->execute(@attrs);
284 my $topics_table = $sth->fetchall_arrayref({});
289 FROM (SELECT stories.stoid FROM stories
291 ON (stories.stoid = firehose.srcid AND firehose.type = "story")
293 ON firehose.globjid = globjs.globjid
294 LEFT JOIN globj_types
295 ON globjs.gtid = globj_types.gtid
296 $where_clause $orderby_clause $limit_clause) AS target
297 LEFT JOIN story_param
298 ON target.stoid = story_param.stoid
301 $sth = $dbh->prepare($sql);
302 $sth->execute(@attrs);
303 my $params_table = $sth->fetchall_arrayref({});
306 $self->disconnect_db();
310 for my $tag (@$tags_table) {
311 my $stoid = $tag->{stoid};
312 if (!$tags->{$stoid}) {
313 $tags->{$stoid} = [];
315 push @{$tags->{$stoid}}, $tag;
319 for my $topic (@$topics_table) {
320 my $stoid = $topic->{stoid};
321 if (!$topics->{$stoid}) {
322 $topics->{$stoid} = [];
324 push @{$topics->{$stoid}}, $topic;
328 for my $param (@$params_table) {
329 my $stoid = $param->{stoid};
330 if (!$params->{$stoid}) {
331 $params->{$stoid} = [];
333 push @{$params->{$stoid}}, $param;
336 for my $story (@$stories) {
337 my $stoid = $story->{stoid};
338 $story->{tags} = $tags->{$stoid} || [];
339 $story->{topics} = $topics->{$stoid} || [];
340 if ($params->{$stoid}) {
341 for my $param (@{$params->{$stoid}}) {
342 $story->{$param->{name}} = $param->{value};
345 $self->_generalize($story, $params);
348 return $stories->[0] if $unique;
352 sub _check_and_regularize_params {
353 my ($self, $params) = @_;
356 if (defined $params->{title}) {
357 if (length($params->{title}) > $self->{options}->{Story}->{title_max_byte}) {
358 $msg = "title too long. max: $self->{options}->{Story}->{title_max_byte} bytes";
359 $self->set_error($msg, -1);
364 $params->{commentstatus} = $params->{commentstatus} || $params->{comment_status} || "enabled";
365 if (defined $params->{commentstatus}) {
366 if (!grep /\A$params->{commentstatus}\z/, qw(disabled
373 $msg = "invalid comment_status";
374 $self->set_error($msg, -1);
379 # check timestamp. use ISO8601 style timestamp like: 2006-08-14T02:34:56-0600
380 if ($params->{time}) {
381 my $rex_timestamp = qr/
382 ^(\d+)-(\d+)-(\d+)\D+(\d+):(\d+):(\d+(?:\.\d+)?) # datetime
383 (?:Z|([+-])(\d+):(\d+))?$ # tz
385 if ($params->{time} =~ $rex_timestamp) {
386 $params->{time} = "$1-$2-$3 $4:$5:$6";
393 sub _set_tags_from_topics {
394 my ($self, $user, $stoid, $topics) = @_;
399 my $globjs = $self->new_instance_of("Newslash::Model::Globjs");
400 my $globj_id = $globjs->getGlobjidFromTargetIfExists("stories", $stoid);
403 my $tags = $self->new_instance_of("Tags");
404 for my $tid (keys %$topics) {
405 my $ret = $tags->set_tag(uid => $user->{uid} || $user->{user_id},
407 globj_id => $globj_id,
410 #warn "set_tag fault..." if !$ret
418 this implementation uses old slash's updateStory($sid, $data),
419 $sid is takable sid or stoid.
424 #my ($self, $params, $user, $extra_params, $opts) = @_;
427 my $user = $params->{user};
431 my $stoid = $params->{stoid} || $params->{story_id} || $params->{id};
432 my $sid = $params->{sid};
435 $story = $self->select(stoid => $stoid);
438 $story = $self->select(sid => $sid);
442 $sid = $story->{sid};
443 $stoid = $story->{stoid};
447 $self->last_error("no story given");
452 return if !$self->_check_and_regularize_params($params);
454 my $slash_db = Newslash::Model::SlashDB->new($self->{options});
456 my $add_related = $params->{add_related};
457 delete $params->{add_related} if $add_related;
458 my $add_tags = $params->{add_tags};
459 delete $params->{add_tags} if $add_tags;
461 $stoid = $slash_db->updateStory($stoid, $params);
464 $self->_set_tags_from_topics($params->{user}, $stoid, $params->{topics_chosen});
468 my $tags = $self->new_instance_of("Tags");
469 my $globjs = $self->new_instance_of("Newslash::Model::Globjs");
470 my $globj_id = $globjs->getGlobjidFromTargetIfExists("stories", $params->{stoid});
471 for my $tag (@$add_tags) {
472 my $rs = $tags->add(uid => $user->{uid} || $user->{user_id},
473 globj_id => $globj_id,
476 $self->logger->warn("Stories::update: tag $tag set failed: " . $tags->last_error);
481 # insert related story
483 for my $related_sid (@$add_related) {
484 my $rs = $self->add_related_story(sid => $sid,
485 related_sid => $related_sid);
487 $self->logger->warn("Stories::update: insert related story $related_sid to $sid failed: " . $self->last_error);
490 $rs = $self->add_related_story(sid => $related_sid,
491 related_sid => $sid);
493 $self->logger->warn("Stories::update: insert related story $sid to $related_sid failed: " . $self->last_error);
498 return wantarray ? ($sid, $stoid) : $stoid;
504 return $self->generic_update(params => $params);
508 =head2 create(\%params, $uid)
540 #my ($self, $params, $user, $extra_params, $opts) = @_;
542 return if $self->check_readonly;
545 my $user = $params->{user};
549 $msg = "no_title" if !$params->{title};
550 $msg = "no_introtext" if !$params->{introtext} && !$params->{intro_text};
551 $msg = "no_topics" if !defined $params->{topics_chosen};
552 $msg = "invalid_user" if !defined $user->{uid};
554 if (length($params->{title}) > $self->{options}->{Story}->{title_max_byte}) {
555 $msg = "title too long. max: $self->{options}->{Story}->{title_max_byte} bytes";
558 $params->{commentstatus} = $params->{commentstatus} || $params->{comment_status} || "enabled";
559 if (!grep /\A$params->{commentstatus}\z/, qw(disabled enabled friends_only friends_fof_only no_foe no_foe_eof logged_in)) {
560 $msg = "invalid comment_status";
563 # check timestamp. use ISO8601 style timestamp like: 2006-08-14T02:34:56-0600
564 if ($params->{time}) {
565 my $rex_timestamp = qr/
566 ^(\d+)-(\d+)-(\d+)[^ 0-9]+(\d+):(\d+):(\d+(?:\.\d+)?) # datetime
567 (?:Z|([+-])(\d+):(\d+))?$ # tz
569 if ($params->{time} =~ $rex_timestamp) {
570 my $dt = DateTime::Format::ISO8601->parse_datetime($params->{time});
571 $params->{time} = DateTime::Format::MySQL->format_datetime($dt);
575 # check parameters finish
576 if (length($msg) > 0) {
577 $self->set_error($msg, -1);
580 $params->{neverdisplay} ||= 0;
581 $params->{uid} = $user->{uid};
584 if ($params->{submission_id}) {
585 my $submission = $self->new_instance_of("Submissions")->select(id => $params->{submission_id});
587 $params->{submitter} = $submission->{uid};
588 $params->{fhid} = $submission->{fhid};
591 $self->logger->error("Stories::create - invalid submission_id: $params->{submission_id}");
594 if ($params->{journal_id}) {
595 my $journal = $self->new_instance_if("Journals")->select(id => $params->{journal_id});
597 $params->{submitter} = $journal->{uid};
598 $params->{fhid} = $journal->{fhid};
601 $self->logger->error("Stories::create - invalid journal_id: $params->{journal_id}");
604 $params->{submitter} ||= $user->{uid};
606 # createStory() deletes topics_chosen, so need to save here.
607 my $topics_chosen = $params->{topics_chosen};
609 my $add_related = $params->{add_related};
610 delete $params->{add_related} if $add_related;
611 my $add_tags = $params->{add_tags};
612 delete $params->{add_tags} if $add_tags;
614 my $slash_db = Newslash::Model::SlashDB->new($self->{options});
616 if ($params->{update}) {
617 $stoid = $params->{stoid} || $params->{story_id} || $params->{id};
618 $sid = $slash_db->updateStory($stoid, $params);
619 $self->set_error("updateStory failed");
623 ($sid, $stoid) = $slash_db->createStory($params);
626 my $globjs = $self->new_instance_of("Newslash::Model::Globjs");
627 my $globj_id = $globjs->getGlobjidFromTargetIfExists("stories", $params->{stoid});
630 my $tags = $self->new_instance_of("Tags");
632 for my $tid (keys %$topics_chosen) {
633 my $rs = $tags->add(uid => $user->{uid} || $user->{user_id},
635 globj_id => $globj_id,
639 $self->logger->warn("Stories::create: tag $tid set failed: " . $tags->last_error);
646 for my $tag (@$add_tags) {
647 my $rs = $tags->add(uid => $user->{uid} || $user->{user_id},
648 globj_id => $globj_id,
651 $self->logger->warn("Stories::create: tag $tag set failed: " . $tags->last_error);
656 # insert related story
658 for my $related_sid (@$add_related) {
659 my $rs = $self->add_related_story(sid => $sid,
660 related_sid => $related_sid);
662 $self->logger->warn("insert related story failed: " . $self->last_error);
665 $rs = $self->add_related_story(sid => $related_sid,
666 related_sid => $sid);
668 $self->logger->warn("Stories::create: insert related story failed: " . $self->last_error);
673 # add firehose item to related_story
674 if ($params->{submission_id}) {
675 my $submissions = $self->new_instance_of("Submissions");
676 my $submission = $submissions->select(id => $params->{submission_id});
678 my $rs = $self->add_related_firehose(sid => $sid,
679 fhid => $submission->{fhid});
681 $self->logger->error("Stories::create - insert related firehose failed: " . $self->last_error);
684 # change submission status
685 if (!$submissions->update(id => $submission->{subid}, del => 2)) {
686 $self->logger->error("Stories::create - cannot change submission status");
690 $self->logger->error("Stories::create - invalid submission_id: $params->{submission_id}");
696 return wantarray ? ($sid, $stoid) : $stoid;
702 return $self->generic_insert(params => $params);
706 my ($self, @params) = @_;
707 my $params = {@params};
708 my $dt = $params->{base_datetime} || DateTime->now;
710 # create sid from timestamp
711 # my $sid_format = '%02d/%02d/%02d/%02d%0d2%02d';
712 my $sid_format = '%y/%m/%d/%H%M%S';
713 my $sid = $dt->strftime($sid_format);
715 # insert blank story with given sid
716 my $dbh = $self->connect_db;
717 my $sql = "INSERT INTO stories (sid) VALUES (?)";
719 my $n = 100; # retry 100 times
721 my $rs = $dbh->do($sql, undef, $sid);
723 $self->set_error("sid_insert_error", -1);
727 my $stoid = $dbh->last_insert_id(undef, undef, undef, undef);
728 $self->disconnect_db;
729 return ($sid, $stoid);
732 # allocate failed, so recreate sid
733 $dt->subtract( seconds => 1 );
734 $sid = $dt->strftime($sid_format);
736 $self->set_error("sid_allocate_failed", -1);
737 $self->disconnect_db;
744 my ($self, $bogus_sid) = @_;
745 # yes, this format is correct, don't change it :-)
746 my $sidformat = '%02d/%02d/%02d/%02d%0d2%02d';
747 # Create a sid based on the current time.
749 my $start_time = time;
751 # If we were called being told that there's at
752 # least one sid that is invalid (already taken),
753 # then look backwards in time until we find it,
754 # then go one second further.
758 @lt = localtime($start_time);
759 $lt[5] %= 100; $lt[4]++; # year and month
760 last if $bogus_sid eq sprintf($sidformat, @lt[reverse 0..5]);
763 # Found the bogus sid by looking
764 # backwards. Go one second further.
767 # Something's wrong. Skip ahead in
768 # time instead of back (not sure what
770 $start_time = time + 1;
773 @lt = localtime($start_time);
774 $lt[5] %= 100; $lt[4]++; # year and month
775 return sprintf($sidformat, @lt[reverse 0..5]);
786 =head2 get_related_items($stoid)
804 ARRAY of related links
810 sub get_related_items {
813 my $stoid = $params->{stoid} || $params->{story_id} || $params->{id};
816 my $dbh = $self->connect_db;
820 story_text.title as title2,
825 SELECT * FROM related_stories
827 ORDER BY ordernum ASC
829 LEFT JOIN story_text ON story_text.stoid = related.rel_stoid
830 LEFT JOIN firehose ON firehose.id = related.fhid
831 LEFT JOIN stories ON stories.sid = related.rel_sid
832 LEFT JOIN topics ON topics.tid = stories.tid
835 my $sth = $dbh->prepare($sql);
836 $sth->execute($stoid);
837 my $related = $sth->fetchall_arrayref({});
838 $self->disconnect_db();
840 for my $r (@$related) {
841 $r->{create_time} = $r->{time};
842 $r->{title} = $r->{title2} unless $r->{title};
844 $r->{type} = "story";
845 $r->{key_id} = $r->{rel_sid};
847 $r->{type} = "submission";
848 $r->{key_id} = $r->{srcid};
850 $r->{primary_topic} = {};
851 $r->{primary_topic}->{tid} = $r->{tid};
852 for my $k (qw{keyword textname series image width height
853 submittable searchable storypickable usesprite}) {
855 $r->{primary_topic}->{$k} = $r->{$k};
863 sub add_related_story {
867 my $story = $args->{story};
869 if ($args->{stoid}) {
870 $story = $self->select(stoid => $args->{stoid});
871 } elsif ($args->{sid}) {
872 $story = $self->select(sid => $args->{sid});
876 if (!$story || !$story->{stoid} || !$story->{sid}) {
877 $self->last_error("cannot get target story");
881 my $related = $args->{related};
883 if ($args->{related_stoid}) {
884 $related = $self->select(stoid => $args->{related_stoid});
885 } elsif ($args->{related_sid}) {
886 $related = $self->select(sid => $args->{related_sid});
890 if (!$related || !$related->{stoid} || !$related->{sid} ) {
891 $self->last_error("cannot get related story");
895 # get related item count
896 my $dbh = $self->start_transaction;
897 my $sql = "SELECT rel_stoid FROM related_stories WHERE stoid = ?";
898 my $stoids = $dbh->do($sql, undef, $story->{stoid});
899 $stoids = [] if ref($stoids) ne "ARRAY";
901 # check if related story is already set
902 if (any { $_ eq $related->{stoid} } @$stoids) {
908 my $count = @$stoids;
909 my $rs = $self->related_stories->insert(stoid => $story->{stoid},
910 rel_stoid => $related->{stoid},
911 rel_sid => $related->{sid},
912 ordernum => $count + 1);
915 $self->last_error("insert failed: " . $self->related_stories->last_error);
923 sub add_related_firehose {
927 my $story = $args->{story};
929 if ($args->{stoid}) {
930 $story = $self->select(stoid => $args->{stoid});
931 } elsif ($args->{sid}) {
932 $story = $self->select(sid => $args->{sid});
936 if (!$story || !$story->{stoid} || !$story->{sid}) {
937 $self->last_error("cannot get target story");
941 my $fh_item = $args->{firehose_item};
944 $fh_item = $self->new_instance_of("Firehose")->select(id => $args->{fhid});
949 $self->last_error("cannot get related firehose item");
953 # get related item count
954 my $dbh = $self->start_transaction;
955 my $sql = "SELECT rel_stoid FROM related_stories WHERE stoid = ?";
956 my $stoids = $dbh->do($sql, undef, $story->{stoid});
957 $stoids = [] if ref($stoids) ne "ARRAY";
960 my $count = @$stoids;
961 my $rs = $self->related_stories->insert(stoid => $story->{stoid},
964 title => "Firehose: $fh_item->{title}",
965 fhid => $fh_item->{id},
966 ordernum => $count + 1);
969 $self->last_error("insert failed: " . $self->related_stories->last_error);
978 =head2 parameters($stoid)
980 get story parameters.
1003 my ($self, $stoid) = @_;
1005 my $dbh = $self->connect_db;
1007 my $sql = <<"EOSQL";
1008 SELECT * FROM story_param WHERE stoid = ?
1011 my $sth = $dbh->prepare($sql);
1012 $sth->execute($stoid);
1013 my $params = $sth->fetchall_hashref('name');
1016 # get next/prev story info
1017 if ($params->{next_stoid} || $params->{prev_stoid}) {
1019 SELECT stories.*, story_text.* FROM stories JOIN story_text ON stories.stoid = story_text.stoid WHERE stories.stoid = ? OR stories.stoid = ?
1021 $sth = $dbh->prepare($sql);
1022 my $next = $params->{next_stoid}->{value} || 0;
1023 my $prev = $params->{prev_stoid}->{value} || 0;
1024 $sth->execute($next, $prev);
1025 my $sids = $sth->fetchall_hashref('stoid');
1026 $params->{next_stoid}->{story} = $sids->{$next} if $sids->{$next};
1027 $params->{prev_stoid}->{story} = $sids->{$prev} if $sids->{$prev};
1031 $self->disconnect_db();
1035 #========================================================================
1037 =head2 set_dirty($key, $id)
1039 set writestatus dirty for the story.
1066 my ($self, $key, $id) = @_;
1067 return if $self->check_readonly;
1070 if ($key eq 'stoid') {
1077 my $dbh = $self->connect_db;
1078 my $sql = <<"EOSQL";
1079 INSERT INTO story_dirty (stoid) VALUES (?)
1082 my $rs = $dbh->do($sql, undef, $stoid);
1090 my ($self, $story, $params) = @_;
1094 $story->{id} = $story->{stoid};
1095 $story->{story_id} = $story->{stoid};
1096 $story->{create_time} = $story->{time};
1097 $story->{update_time} = $story->{last_update};
1099 for my $t (@{$story->{topics}}) {
1100 if ($t->{tid} && $t->{tid} == $story->{tid}) {
1101 $story->{primary_topic} = $t;
1105 $story->{content_type} = "story";
1106 $story->{intro_text} = $story->{introtext};
1107 $story->{bodytext} ||= "";
1108 $story->{body_text} = $story->{bodytext};
1109 if ($story->{body_text}) {
1110 $story->{full_text} = join("\n", $story->{intro_text}, $story->{body_text});
1113 $story->{full_text} = $story->{intro_text};
1115 $story->{fulltext} = $story->{full_text};
1117 $story->{discussion_id} = $story->{discussion};
1119 # no public flag given, public is 'yes'
1120 $story->{public} = 'yes' if !$story->{public};
1124 # delete story from database
1125 # this method is for test purpose only.
1128 return if $self->check_readonly;
1131 my $stoid = $params->{story_id};
1137 #my $dbh = $self->connect_db({AutoCommit => 0,});
1138 my $dbh = $self->start_transaction;
1139 for my $table (qw(stories story_param story_text story_topics_chosen story_topics_rendered)) {
1140 my $sql = "DELETE FROM $table WHERE stoid = ?";
1141 my $rs = $dbh->do($sql, undef, $stoid);
1142 if (!defined $rs || $rs == 0) {
1143 Mojo::Log->new->warn("DELETE FROM $table failed. stoid is $stoid.");
1148 # delete from firehose
1149 my $firehose = $self->new_instance_of("Firehose");
1150 $firehose->hard_delete("story", $stoid);