From 2e2334a38d00893ad6f1d612c608a7ff0ba81083 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 1 Sep 2010 15:58:11 +0000 Subject: [PATCH] Repeated punishment withdraws old punishments --- Builder/IISMainHandler/build.txt | 2 +- Common/dataobjects/Post.cs | 92 +++++++++++++++++++------------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 7ccfcb1..7cebf7d 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -997 \ No newline at end of file +1001 \ No newline at end of file diff --git a/Common/dataobjects/Post.cs b/Common/dataobjects/Post.cs index 2de867b..0789586 100644 --- a/Common/dataobjects/Post.cs +++ b/Common/dataobjects/Post.cs @@ -335,51 +335,71 @@ namespace FLocal.Common.dataobjects { } } + private readonly object Punish_Locker = new object(); public void Punish(Account account, PunishmentType type, string comment) { if(!Moderator.isModerator(account, this.thread.board)) throw new FLocalException(account.id + " is not a moderator in board " + this.thread.board.id); if(account.user.id == this.poster.id) throw new FLocalException("You cannot punish your own posts"); - ChangeSetUtil.ApplyChanges( - new UpdateChange( - TableSpec.instance, - new Dictionary { - { TableSpec.FIELD_TOTALPUNISHMENTS, new IncrementFieldValue() }, - }, - this.id - ), - new InsertChange( - Punishment.TableSpec.instance, - new Dictionary { - { Punishment.TableSpec.FIELD_POSTID, new ScalarFieldValue(this.id.ToString()) }, - { Punishment.TableSpec.FIELD_OWNERID, new ScalarFieldValue(this.poster.id.ToString()) }, - { Punishment.TableSpec.FIELD_ORIGINALBOARDID, new ScalarFieldValue(this.thread.board.id.ToString()) }, - { Punishment.TableSpec.FIELD_MODERATORID, new ScalarFieldValue(account.id.ToString()) }, - { Punishment.TableSpec.FIELD_PUNISHMENTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, - { Punishment.TableSpec.FIELD_PUNISHMENTTYPE, new ScalarFieldValue(type.id.ToString()) }, - { Punishment.TableSpec.FIELD_ISWITHDRAWED, new ScalarFieldValue("0") }, - { Punishment.TableSpec.FIELD_COMMENT, new ScalarFieldValue(comment) }, - } - ) - ); + lock(this.Punish_Locker) { - this.punishments_Reset(); + List changes = ( + from punishment in this.punishments + select (AbstractChange)new UpdateChange( + Punishment.TableSpec.instance, + new Dictionary { + { Punishment.TableSpec.FIELD_ISWITHDRAWED, new ScalarFieldValue("1") }, + }, + punishment.id + ) + ).ToList(); - Account posterAccount = null; - try { - posterAccount = Account.LoadByUser(this.poster); - } catch(NotFoundInDBException) { - } - - if(posterAccount != null) { - PMMessage newMessage = PMConversation.SendPMMessage( - account, - posterAccount, - this.title, - String.Format("{0}\r\n[post]{2}[/post]\r\n{1}", type.description, comment, this.id) + changes.Add( + new UpdateChange( + TableSpec.instance, + new Dictionary { + { TableSpec.FIELD_TOTALPUNISHMENTS, new IncrementFieldValue() }, + }, + this.id + ) ); - newMessage.conversation.markAsRead(account, newMessage, newMessage); + + changes.Add( + new InsertChange( + Punishment.TableSpec.instance, + new Dictionary { + { Punishment.TableSpec.FIELD_POSTID, new ScalarFieldValue(this.id.ToString()) }, + { Punishment.TableSpec.FIELD_OWNERID, new ScalarFieldValue(this.poster.id.ToString()) }, + { Punishment.TableSpec.FIELD_ORIGINALBOARDID, new ScalarFieldValue(this.thread.board.id.ToString()) }, + { Punishment.TableSpec.FIELD_MODERATORID, new ScalarFieldValue(account.id.ToString()) }, + { Punishment.TableSpec.FIELD_PUNISHMENTDATE, new ScalarFieldValue(DateTime.Now.ToUTCString()) }, + { Punishment.TableSpec.FIELD_PUNISHMENTTYPE, new ScalarFieldValue(type.id.ToString()) }, + { Punishment.TableSpec.FIELD_ISWITHDRAWED, new ScalarFieldValue("0") }, + { Punishment.TableSpec.FIELD_COMMENT, new ScalarFieldValue(comment) }, + } + ) + ); + + ChangeSetUtil.ApplyChanges(changes.ToArray()); + + this.punishments_Reset(); + + Account posterAccount = null; + try { + posterAccount = Account.LoadByUser(this.poster); + } catch(NotFoundInDBException) { + } + + if(posterAccount != null) { + PMMessage newMessage = PMConversation.SendPMMessage( + account, + posterAccount, + this.title, + String.Format("{0}\r\n[post]{2}[/post]\r\n{1}", type.description, comment, this.id) + ); + newMessage.conversation.markAsRead(account, newMessage, newMessage); + } } }