Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Committing fixes

  • Loading branch information...
commit d77f54cfd47befc5d14c22c1cb20ccc405b31981 1 parent 0cedd74
Brian Aker BrianAker authored
37 Slash/DB/MySQL/MySQL.pm
@@ -156,12 +156,34 @@ sub init {
156 156 }
157 157
158 158 ########################################################
  159 +# Yes, this is ugly, and we can ditch it in about 6 months
  160 +# Turn off autocommit here
  161 +sub sqlTransactionStart {
  162 + my($self, $arg) = @_;
  163 + $self->sqlDo($arg);
  164 +}
  165 +
  166 +########################################################
  167 +# Put commit here
  168 +sub sqlTransactionFinish {
  169 + my($self) = @_;
  170 + $self->sqlDo("UNLOCK TABLES");
  171 +}
  172 +
  173 +########################################################
  174 +# In another DB put rollback here
  175 +sub sqlTransactionCancel {
  176 + my($self) = @_;
  177 + $self->sqlDo("UNLOCK TABLES");
  178 +}
  179 +
  180 +########################################################
159 181 # Bad need of rewriting....
160 182 sub createComment {
161 183 my($self, $form, $user, $pts, $default_user) = @_;
162 184 my $sid_db = $self->{_dbh}->quote($form->{sid});
163 185
164   - $self->sqlDo("LOCK TABLES comments WRITE");
  186 + $self->sqlTransactionStart("LOCK TABLES comments WRITE");
165 187 my($maxCid) = $self->sqlSelect(
166 188 "max(cid)", "comments", "sid=$sid_db"
167 189 );
@@ -173,7 +195,7 @@ sub createComment {
173 195 $self->{_dbh}->quote($form->{postercomment}) . "," .
174 196 ($form->{postanon} ? $default_user : $user->{uid}) . ", $pts,-1,0)";
175 197
176   - $self->sqlDo("UNLOCK TABLES");
  198 + $self->sqlTransactionFinish();
177 199 # don't allow pid to be passed in the form.
178 200 # This will keep a pid from being replace by
179 201 # with other comment's pid
@@ -1599,7 +1621,7 @@ sub setMetaMod {
1599 1621 my $returns = [];
1600 1622
1601 1623 # Update $muid's Karma
1602   - $self->sqlDo("LOCK TABLES users_info WRITE, metamodlog WRITE");
  1624 + $self->sqlTransactionStart("LOCK TABLES users_info WRITE, metamodlog WRITE");
1603 1625 for (keys %{$m2victims}) {
1604 1626 my $muid = $m2victims->{$_}[0];
1605 1627 my $val = $m2victims->{$_}[1];
@@ -1631,7 +1653,7 @@ sub setMetaMod {
1631 1653 -flag => $flag
1632 1654 });
1633 1655 }
1634   - $self->sqlDo("UNLOCK TABLES");
  1656 + $self->sqlTransactionFinish();
1635 1657
1636 1658 return $returns;
1637 1659 }
@@ -2260,11 +2282,8 @@ sub getStoryList {
2260 2282 my $form = getCurrentForm();
2261 2283
2262 2284 # CHANGE DATE_ FUNCTIONS
2263   - my $sql = q[SELECT storiestuff.hits, commentcount, stories.sid, title, uid,
2264   - date_format(time,"%k:%i") as t,tid,section,
2265   - displaystatus,writestatus,
2266   - date_format(time,"%W %M %d"),
2267   - date_format(time,"%m/%d")
  2285 + my $sql = q[SELECT storiestuff.hits, commentcount, stories.sid, title, uid, time, tid, section,
  2286 + displaystatus,writestatus
2268 2287 FROM stories,storiestuff
2269 2288 WHERE storiestuff.sid=stories.sid];
2270 2289 $sql .= " AND section='$user->{section}'" if $user->{section};
26 Slash/DB/Static/MySQL/MySQL.pm
@@ -78,13 +78,13 @@ sub setStoryIndex {
78 78 for my $sid (@sids) {
79 79 $stories{$sid} = $self->sqlSelectHashref("*","stories","sid='$sid'");
80 80 }
81   - $self->{_dbh}->do("LOCK TABLES newstories WRITE");
  81 + $self->{_dbh}->sqlTransactionStart("LOCK TABLES newstories WRITE");
82 82
83 83 foreach my $sid (keys %stories) {
84 84 $self->sqlReplace("newstories", $stories{$sid}, "sid='$sid'");
85 85 }
86 86
87   - $self->{_dbh}->do("UNLOCK TABLES");
  87 + $self->{_dbh}->sqlTransactionFinish();
88 88 }
89 89
90 90 ########################################################
@@ -213,13 +213,13 @@ sub updateStamps {
213 213
214 214 my $E = $self->sqlSelectAll($columns, $tables, $where, $other);
215 215
216   - $self->sqlDo("LOCK TABLES users_info WRITE");
  216 + $self->sqlTransactionStart("LOCK TABLES users_info WRITE");
217 217
218 218 for (@{$E}) {
219 219 my $uid=$_->[0];
220 220 $self->setUser($uid, {-lastaccess=>'now()'});
221 221 }
222   - $self->sqlDo("UNLOCK TABLES");
  222 + $self->sqlTransactionFinish();
223 223 }
224 224
225 225 ########################################################
@@ -371,9 +371,7 @@ sub tokens2points {
371 371 my $constants = getCurrentStatic();
372 372 my @log;
373 373 my $c = $self->sqlSelectMany("uid,tokens", "users_info", "tokens >= $constants->{maxtokens}");
374   - $self->sqlDo("LOCK TABLES users READ,
375   - users_info WRITE,
376   - users_comments WRITE");
  374 + $self->sqlTransactionStart("LOCK TABLES users READ, users_info WRITE, users_comments WRITE");
377 375
378 376 while (my($uid, $tokens) = $c->fetchrow) {
379 377 push @log, ("Giving $constants->{maxtokens}/$constants->{tokensperpoint} " .
@@ -393,13 +391,13 @@ sub tokens2points {
393 391 seclev < 100 AND
394 392 users.uid=users_comments.uid AND
395 393 users.uid=users_info.uid");
396   - $self->sqlDo("UNLOCK TABLES");
  394 + $self->sqlTransactionFinish();
397 395
398   - $self->sqlDo("LOCK TABLES users_comments WRITE");
  396 + $self->sqlTransactionStart("LOCK TABLES users_comments WRITE");
399 397 while (my($uid) = $c->fetchrow) {
400 398 $self->sqlUpdate("users_comments", { points => 5 } ,"uid=$uid");
401 399 }
402   - $self->sqlDo("UNLOCK TABLES");
  400 + $self->sqlTransactionFinish();
403 401
404 402 return \@log;
405 403 }
@@ -419,14 +417,14 @@ sub stirPool {
419 417
420 418 my $revoked = 0;
421 419
422   - $self->sqlDo("LOCK TABLES users_comments WRITE");
  420 + $self->sqlTransactionStart("LOCK TABLES users_comments WRITE");
423 421
424 422 while (my($p, $u) = $c->fetchrow) {
425 423 $revoked += $p;
426 424 $self->sqlUpdate("users_comments", { points => '0' }, "uid=$u");
427 425 }
428 426
429   - $self->sqlDo("UNLOCK TABLES");
  427 + $self->sqlTransactionFinish();
430 428 $c->finish;
431 429 return 0;
432 430 }
@@ -512,14 +510,14 @@ sub giveKarma {
512 510 }
513 511
514 512
515   - $self->sqlDo("LOCK TABLES users_info WRITE");
  513 + $self->sqlTransactionStart("LOCK TABLES users_info WRITE");
516 514 for (@eligibles) {
517 515 next unless $scores[$uid];
518 516 $self->setUser($uid, {
519 517 -tokens => "tokens+" . $scores[$uid]
520 518 });
521 519 }
522   - $self->sqlDo("UNLOCK TABLES");
  520 + $self->sqlTransactionFinish();
523 521
524 522 return("Start at $st end at $fi. $eligible left. First score is $cnt");
525 523 }
5 plugins/Admin/admin.pl
@@ -1117,7 +1117,10 @@ sub listStories {
1117 1117
1118 1118 for (@$storylist) {
1119 1119 ($hits, $comments, $sid, $title, $aid, $time, $tid, $section,
1120   - $displaystatus, $writestatus, $td, $td2) = @$_;
  1120 + $displaystatus, $writestatus) = @$_;
  1121 + $time = timeCalc($time, '%H:%M');
  1122 + my $td = timeCalc($time, '%A %B %d');
  1123 + my $td2 = timeCalc($time, '%m/%d');
1121 1124
1122 1125 $substrtid = substr($tid, 0, 5);
1123 1126

0 comments on commit d77f54c

Please sign in to comment.
Something went wrong with that request. Please try again.