From 5d138757b6111ac8f8b64ec24af6a7f3ff2e87b6 Mon Sep 17 00:00:00 2001 From: hylom Date: Tue, 25 Oct 2016 21:36:16 +0900 Subject: [PATCH] Model::SlashDB: fix to run as single module --- src/newslash_web/lib/Newslash/Model/SlashDB.pm | 113 +++++++++++++++---------- 1 file changed, 66 insertions(+), 47 deletions(-) diff --git a/src/newslash_web/lib/Newslash/Model/SlashDB.pm b/src/newslash_web/lib/Newslash/Model/SlashDB.pm index 38b55f18..f82feb5c 100644 --- a/src/newslash_web/lib/Newslash/Model/SlashDB.pm +++ b/src/newslash_web/lib/Newslash/Model/SlashDB.pm @@ -21,6 +21,7 @@ use Storable qw(thaw nfreeze); use URI (); #use Slash::Utility; +use Newslash::Model::SlashUtility; #use Slash::Custom::ParUserAgent; #use Slash::Constants ':messages'; @@ -407,7 +408,7 @@ sub getSponsorForDiscussion { ######################################################## sub createComment { my($self, $comment) = @_; - return -1 unless dbAvailable("write_comments"); + return -1 unless $self->dbAvailable("write_comments"); my $constants = $self->getCurrentStatic(); my $comment_text = $comment->{comment}; delete $comment->{comment}; @@ -491,7 +492,7 @@ sub createComment { $self->sqlDo("COMMIT"); $self->sqlDo("SET AUTOCOMMIT=1"); - my $firehose = getObject('Slash::FireHose'); + my $firehose = $self->getObject('Slash::FireHose'); if ($firehose) { $firehose->createUpdateItemFromComment($cid); } @@ -1279,7 +1280,7 @@ sub createSubmission { $self->setSubmission($subid, $submission) if $subid && keys %$submission; if ($constants->{plugin}{FireHose} && $subid) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); my $firehose_id = $firehose->createItemFromSubmission($subid); if ($firehose_id) { @@ -1365,7 +1366,7 @@ sub setContentFilter { # This creates an entry in the accesslog sub createAccessLog { my($self, $op, $dat, $status) = @_; - return if !dbAvailable('write_accesslog'); + return if !$self->dbAvailable('write_accesslog'); my $constants = $self->getCurrentStatic(); my $form = getCurrentForm(); my $user = getCurrentUser(); @@ -1377,7 +1378,7 @@ sub createAccessLog { return if $op eq 'css' && $constants->{accesslog_css_skip}; - my $reader = getObject('Slash::DB', { db_type => 'reader' }); + my $reader = $self->getObject('Slash::DB', { db_type => 'reader' }); if ($op =~ /^(?:image|css|js)$/ && $constants->{accesslog_imageregex}) { return if $constants->{accesslog_imageregex} eq 'NONE'; @@ -1490,7 +1491,7 @@ sub createAccessLog { sub _writeAccessLogCache { my($self) = @_; - return if !dbAvailable('write_accesslog'); + return if !$self->dbAvailable('write_accesslog'); return unless ref($self->{_accesslog_insert_cache}) && @{$self->{_accesslog_insert_cache}}; # $self->{_dbh}{AutoCommit} = 0; @@ -1508,7 +1509,7 @@ sub _writeAccessLogCache { # This creates an entry in the accesslog for admins -Brian sub createAccessLogAdmin { my($self, $op, $dat, $status) = @_; - return if !dbAvailable('write_accesslog'); + return if !$self->dbAvailable('write_accesslog'); return if $op =~ /^images?$/; my $constants = $self->getCurrentStatic(); my $form = getCurrentForm(); @@ -1549,9 +1550,9 @@ sub createAccessLogAdmin { } sub ajaxPageProfile { - return '' if !dbAvailable('write_accesslog'); + return '' if !$self->dbAvailable('write_accesslog'); my $constants = $self->getCurrentStatic(); - my $logdb = getObject('Slash::DB', { virtual_user => $constants->{log_db_user} }); + my $logdb = $self->getObject('Slash::DB', { virtual_user => $constants->{log_db_user} }); return '' if !$logdb; my $form = getCurrentForm(); my $pagemark = $form->{pagemark} || 0; @@ -1648,7 +1649,7 @@ sub deleteUser { # delete Journal if ($constants->{plugin}{Journal}) { - my $journal = getObject('Slash::Journal'); + my $journal = $self->getObject('Slash::Journal'); my $entries = $journal->getsByUid($uid); foreach my $entry (@$entries) { $journal->remove($entry->[3]); @@ -1658,7 +1659,7 @@ sub deleteUser { # delete Zoo if ($constants->{plugin}{Zoo}) { my $people = $self->sqlSelectAllHashrefArray('uid, person', 'people', "uid=$uid"); - my $zoo = getObject('Slash::Zoo'); + my $zoo = $self->getObject('Slash::Zoo'); foreach my $entry (@$people) { $zoo->delete($entry->{uid}, $entry->{person}); } @@ -1865,7 +1866,7 @@ sub createBadPasswordLog { # generate a message for every bad attempt over a threshold if ($bp_count && $bp_count == $warn_limit) { - my $messages = getObject("Slash::Messages"); + my $messages = $self->getObject("Slash::Messages"); return unless $messages; my $users = $messages->checkMessageCodes( MSG_CODE_BADPASSWORD, [$uid] @@ -2675,6 +2676,10 @@ sub getDBVirtualUsers { return $self->sqlSelectColArrayref('virtual_user', 'dbs') } +=pod + +This method moved to LegacyDB.pm. + ################################################################# # get list of DBs, never cache # (do caching in getSlashConf) @@ -2688,6 +2693,8 @@ my $ref_func = sub{ }; return $self->cache_local_and_memcached('db_classes', $ref_func); } +=cut + ################################################################# # Just create an empty content_filter sub createContentFilter { @@ -2950,7 +2957,7 @@ sub deleteComment { } my $constants = $self->getCurrentStatic(); if ($constants->{m1}) { - my $moddb = getObject("Slash::$constants->{m1_pluginname}"); + my $moddb = $self->getObject("Slash::$constants->{m1_pluginname}"); if ($moddb) { $moddb->deleteModeratorlog({ cid => $cid }); } @@ -3208,7 +3215,7 @@ sub deleteSubmission { } if ($constants->{plugin}{FireHose} && @subid > 0) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); $firehose->rejectItemBySubid(\@subid); } return @subid; @@ -3238,7 +3245,7 @@ sub deleteDiscussion { ) if @$comment_ids; my $constants = $self->getCurrentStatic(); if ($constants->{m1}) { - my $moddb = getObject("Slash::$constants->{m1_pluginname}"); + my $moddb = $self->getObject("Slash::$constants->{m1_pluginname}"); if ($moddb) { $moddb->deleteModeratorlog({ sid => $did }); } @@ -3775,7 +3782,7 @@ sub deleteStory { my $constants = $self->getCurrentStatic(); if ($constants->{plugin}{FireHose}) { my $stoid = $self->getStoidFromSidOrStoid($id); - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); my $globjid = $self->getGlobjidCreate("stories", $stoid); my $fhid = $firehose->getFireHoseIdFromGlobjid($globjid); $firehose->setFireHose($fhid, { public => "no", rejected => "yes"}); @@ -4049,7 +4056,7 @@ print STDERR scalar(gmtime) . " stoid '$stoid' lu '$lu' options_lu '$options->{l $self->setStory_delete_memcached_by_stoid([ $stoid ]); if ($constants->{plugin}{FireHose} && @fh_update_fields > 0) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); $firehose->updateItemFromStory($stoid); } @@ -4271,7 +4278,7 @@ sub validFormkey { # If we're using the HumanConf plugin, check for its validity # as well. return 'ok' if $options->{no_hc}; - my $hc = getObject("Slash::HumanConf"); + my $hc = $self->getObject("Slash::HumanConf"); return 'ok' if !$hc; return $hc->validFormkeyHC($formname); } @@ -4400,7 +4407,7 @@ sub checkPostInterval { # If this user has access modifiers applied, check for possible # different speed limits based on those. First match, if any, # wins. - my $reader = getObject('Slash::DB', { db_type => 'reader' }); + my $reader = $self->getObject('Slash::DB', { db_type => 'reader' }); my $srcids = $user->{srcids}; my $al2_hr = $srcids ? $reader->getAL2($srcids) : { }; my $al2_name_used = "_none_"; @@ -6166,7 +6173,7 @@ sub _displaystatus { my $displaystatus = $mainpage ? 0 : 1; if ($options->{allow_abbrev}) { - my $tags = getObject("Slash::Tags"); + my $tags = $self->getObject("Slash::Tags"); my $globjid = $self->getGlobjidFromTargetIfExists('stories', $stoid); if ($tags->isAdminTagged($globjid, 'abbreviated')) { $displaystatus = 0.5; @@ -6317,7 +6324,7 @@ sub getStoryByTime { sub getAndSetPreviousStory { my($self, $story) = @_; - my $reader = getObject('Slash::DB', { db_type => 'reader' }); + my $reader = $self->getObject('Slash::DB', { db_type => 'reader' }); my $time = $self->getTime(); if (!$story->{prev_stoid}) { @@ -6334,7 +6341,7 @@ sub getAndSetPreviousStory { sub getAndSetNextStory { my($self, $story) = @_; - my $reader = getObject('Slash::DB', { db_type => 'reader' }); + my $reader = $self->getObject('Slash::DB', { db_type => 'reader' }); my $time = $self->getTime(); if (!$story->{next_stoid}) { @@ -6393,7 +6400,7 @@ sub getStoryByTimeAdmin { foreach my $story (@$returnable) { $story->{displaystatus} = $self->_displaystatus($story->{stoid}, { no_time_restrict => 1, allow_abbrev => 1 }); if ($constants->{plugin}{FireHose}) { - my $fh = getObject("Slash::FireHose"); + my $fh = $self->getObject("Slash::FireHose"); my $item = $fh->getFireHoseByTypeSrcid("story", $story->{stoid}); $story->{fhid} = $item->{id}; } @@ -7179,7 +7186,7 @@ sub countStoriesPostedOut { sub _stories_time_clauses { my($self, $options) = @_; my $constants = $self->getCurrentStatic(); - my $user = getCurrentUser(); + #my $user = getCurrentUser(); my $try_future = $options->{try_future} || 0; my $future_secs = defined($options->{future_secs}) ? $options->{future_secs} @@ -7200,12 +7207,12 @@ sub _stories_time_clauses { # and this page must be plummy (able to have plums), OR the user must # have a daypass. my $future = 0; - $future = 1 if $try_future - && $future_secs - && ( !$must_be_subscriber - || ( $user->{is_subscriber} && $user->{state}{page_plummy} ) -|| !$user->{is_anon} - || $user->{has_daypass} ); + #$future = 1 if $try_future + #&& $future_secs + # && ( !$must_be_subscriber + # || ( $user->{is_subscriber} && $user->{state}{page_plummy} ) + # || !$user->{is_anon} + # || $user->{has_daypass} ); # If we have NOW() in the WHERE clause, the query cache can't hold # onto this. Since story times are rounded to the minute, we can @@ -8198,7 +8205,7 @@ sub createStory { if (!$error) { if ($story->{fhid} && $constants->{plugin}{FireHose}) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); my $item = $firehose->getFireHose($story->{fhid}); $firehose->setFireHose($story->{fhid}, { stoid => $stoid }); if ($item && $item->{type} eq "journal") { @@ -8320,7 +8327,7 @@ sub createStory { $self->sqlDo("SET AUTOCOMMIT=1"); if ($constants->{plugin}{FireHose}) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); $firehose->createItemFromStory($stoid); } @@ -8349,7 +8356,7 @@ sub grantStorySubmissionKarma { my $constants = $self->getCurrentStatic(); if ($constants->{plugin}{FireHose}) { my $fhid; - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); if ($story->{fhid}) { $fhid = $story->{fhid}; } elsif ($story->{subid}) { @@ -8486,7 +8493,7 @@ sub updateStory { $self->sqlDo("COMMIT"); $self->sqlDo("SET AUTOCOMMIT=1"); - if (my $pollbooth_db = getObject('Slash::PollBooth')) { + if (my $pollbooth_db = $self->getObject('Slash::PollBooth')) { $pollbooth_db->updatePollFromStory($sid, { date => 1, topic => 1, @@ -8521,7 +8528,7 @@ sub createSignoff { $self->setStory($stoid, { thumb_signoff_needed => 0 }); if ($constants->{plugin}{FireHose}) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); my $stoid_q = $self->sqlQuote($stoid); my ($id) = $self->sqlSelect("id", "firehose", "type='story' and srcid=$stoid_q"); if($id) { @@ -8539,7 +8546,7 @@ sub createSignoff { my $s_user = $self->getUser($uid); my $story = $self->getStory($stoid); my $message = "$s_user->{nickname} $signoff_type $story->{title}"; - my $remarks = getObject('Slash::Remarks'); + my $remarks = $self->getObject('Slash::Remarks'); $remarks->createRemark($message, { uid => $uid, stoid => $stoid, @@ -8595,7 +8602,7 @@ sub deleteSignoffsForStory { my $stoid_q = $self->sqlQuote($stoid); $self->sqlDelete("signoff", "stoid=$stoid_q"); if ($constants->{plugin}{FireHose}) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); my ($id) = $self->sqlSelect("id", "firehose", "type='story' and srcid=$stoid_q"); $firehose->setFireHose($id, { signoffs => '' }); @@ -8939,7 +8946,7 @@ sub getSlashConf { } # We only need to do this on startup. This var isn't really used; - # see the code comment in getObject(). + # see the code comment in $self->getObject(). $conf{classes} = $self->getClasses(); if ($conf{utf8}) { @@ -8954,6 +8961,10 @@ sub getSlashConf { =cut +=pod + +these method moved to LegacyDB.pm. + ################################################################## # It would be best to write a Slash::MemCached class, preferably as # a plugin, but let's just do this for now. @@ -9047,6 +9058,8 @@ sub _getMCDStats_percentify { $hr->{$dest} = $perc; } +=cut + ################################################################## # What an ugly ass method that should go away -Brian # It's ugly, but performs many necessary functions, and anything @@ -9292,7 +9305,7 @@ sub getStoryList { } # Now set displaystatus. my $ds = $self->displaystatusForStories($stoids); - my $tags = getObject("Slash::Tags"); + my $tags = $self->getObject("Slash::Tags"); for my $story (@$list) { $story->{displaystatus} = $ds->{$story->{stoid}}; my $globjid = $self->getGlobjidFromTargetIfExists('stories', $story->{stoid}); @@ -10587,7 +10600,7 @@ sub setStoryRenderedFromChosen { $self->setStory_delete_memcached_by_tid($rendered_tids); if ($constants->{plugin}{FireHose}) { - my $firehose = getObject("Slash::FireHose"); + my $firehose = $self->getObject("Slash::FireHose"); $firehose->setTopicsRenderedForStory($stoid, $rendered_tids); } @@ -11173,7 +11186,7 @@ sub setUser { my %new_values = ( ); if ($constants->{plugin}{Tags}) { my @update_keys = sort map { s/^-//; $_ } keys %$hashref; - my $tagboxdb = getObject('Slash::Tagbox'); + my $tagboxdb = $self->getObject('Slash::Tagbox'); my @log_keys = $tagboxdb->userKeysNeedTagLog(\@update_keys); %old_values = ( map { ($_, undef) } @log_keys ); } @@ -11310,7 +11323,7 @@ sub setUser { } if ($rows && keys(%old_values)) { - my $tagboxdb = getObject('Slash::Tagbox'); + my $tagboxdb = $self->getObject('Slash::Tagbox'); for my $name (keys %old_values) { $tagboxdb->logUserChange($uid, $name, $old_values{$name}, $new_values{$name}) if $old_values{$name} ne $new_values{$name}; @@ -11610,7 +11623,7 @@ sub _getUser_do_selects { $this_clout = $clout_hr->{$clid}; } else { my $this_info = $clout_info->{$clid}; - my $clout_obj = getObject($this_info->{class}, { db_type => 'reader' }); warn "no obj for '$this_info->{class}'" unless $clout_obj; + my $clout_obj = $self->getObject($this_info->{class}, { db_type => 'reader' }); warn "no obj for '$this_info->{class}'" unless $clout_obj; $this_clout = $clout_obj->getUserClout($answer) if $clout_obj; } $answer->{clout}{ $clout_types->{$clid} } = $this_clout @@ -12674,7 +12687,7 @@ sub getGlobjidCreate { my($self, $name, $target_id, $options) = @_; my $db; if ($options && $options->{reader_ok}) { - $db = getObject('Slash::DB', { db_type => 'reader' }); + $db = $self->getObject('Slash::DB', { db_type => 'reader' }); } else { $db = getCurrentDB(); } @@ -12753,7 +12766,7 @@ sub getGlobjTypes { my $ref_func = sub{ my($self) = @_; # Cache needs to be built, so build it. - my $reader = getObject('Slash::DB', { db_type => 'reader' }); + my $reader = $self->getObject('Slash::DB', { db_type => 'reader' }); my $hr = $reader->sqlSelectAllKeyValue('gtid, maintable', 'globj_types'); my @gtids = keys %$hr; for my $gtid (@gtids) { $hr->{$hr->{$gtid}} = $gtid } @@ -12938,7 +12951,7 @@ sub _addGlobjEssentials_stories { my($url, $title) = @$data_ar; #print STDERR "for stoid $stoid url='$url' title='$title' time='$story->{time}'\n"; if ($constants->{firehose_link_article2}) { - my $fh = getObject("Slash::FireHose", { db_type => 'reader'}); + my $fh = $self->getObject("Slash::FireHose", { db_type => 'reader'}); my $item = $fh->getFireHoseByTypeSrcid('story',$stoid); $data_hr->{$globjid}{url} = $fh->linkFireHose($item); $data_hr->{$globjid}{title} = $item->{title}; @@ -12964,7 +12977,7 @@ sub _addGlobjEssentials_urls { "url_id IN ($id_str)") : { }; my $hoseid_hr = { }; - my $firehose = getObject('Slash::FireHose'); + my $firehose = $self->getObject('Slash::FireHose'); if ($firehose) { $hoseid_hr = $id_str ? $self->sqlSelectAllKeyValue( @@ -13839,6 +13852,10 @@ sub getStuckStory { return $returnable->[0]; } +=pod + +these method moved to LegacyDB.pm + ######################################################## my $cache_master; sub cache_local_and_memcached { @@ -13879,6 +13896,8 @@ sub delete_local_and_memcached { $mcd->delete("$self->{_mcd_keyprefix}:$name") if ($mcd); } +=cut + ######################################################## sub DESTROY { my($self) = @_; -- 2.11.0