[vanillin commit] r304 - trunk/library/Vanilla

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 20, 2007, 10:30:04 PM10/20/07
to vanilli...@googlegroups.com
Author: helgith
Date: Sat Oct 20 19:29:34 2007
New Revision: 304

Modified:
trunk/library/Vanilla/DiscussionManager.php

Log:
SaveDiscussion was like broken broken broken because of a wrong if else

Modified: trunk/library/Vanilla/DiscussionManager.php
==============================================================================
--- trunk/library/Vanilla/DiscussionManager.php (original)
+++ trunk/library/Vanilla/DiscussionManager.php Sat Oct 20 19:29:34 2007
@@ -492,87 +492,87 @@
// Make sure we got it
if ($Discussion->DiscussionID == 0) {

$this->Context->ErrorManager->AddError($this->Context,
$this->Name, 'SaveDiscussion', 'Your last discussion could not be found.');
+ }
+ } else {
+ $NewDiscussion = 0;
+ $OldDiscussion = false;
+ if ($Discussion->DiscussionID == 0) {
+ $NewDiscussion = 1;
} else {
- $NewDiscussion = 0;
- $OldDiscussion = false;
- if ($Discussion->DiscussionID == 0) {
- $NewDiscussion = 1;
- } else {
- $OldDiscussion = $this->GetDiscussionById($Discussion->DiscussionID);
- }
-
- // Validate the Discussion topic
- $Name = FormatStringForDatabaseInput($Discussion->Name);
-
Validate($this->Context->GetDefinition('DiscussionTopicLower'), 1,
$Name, 100, '', $this->Context);
- if ($Discussion->CategoryID <= 0) {
- $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrSelectCategory'));
- }
+ $OldDiscussion = $this->GetDiscussionById($Discussion->DiscussionID);
+ }

- // Validate first comment
- $Discussion->Comment->DiscussionID = $Discussion->DiscussionID;
- if ($OldDiscussion) {
- $Discussion->Comment->CommentID = $OldDiscussion->FirstCommentID;
- } else {
- $Discussion->Comment->CommentID = 0;
+ // Validate the Discussion topic
+ $Name = FormatStringForDatabaseInput($Discussion->Name);
+
Validate($this->Context->GetDefinition('DiscussionTopicLower'), 1,
$Name, 100, '', $this->Context);
+ if ($Discussion->CategoryID <= 0) {
+ $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrSelectCategory'));
+ }
+
+ // Validate first comment
+ $Discussion->Comment->DiscussionID = $Discussion->DiscussionID;
+ if ($OldDiscussion) {
+ $Discussion->Comment->CommentID = $OldDiscussion->FirstCommentID;
+ } else {
+ $Discussion->Comment->CommentID = 0;
+ }
+ $CommentManager = ObjectFactory::getInstance()->NewObject('CommentManager');
+ $CommentManager->ValidateComment($Discussion->Comment, 0);
+
+ // Validate the whisperusername
+ $CommentManager->ValidateWhisperUsername($Discussion);
+
+ // If updating, validate that this is admin or the author
+ if (!$NewDiscussion) {
+ if ($OldDiscussion->AuthUserID != $session->UserID
&& !$session->User->Permission('PERMISSION_EDIT_DISCUSSIONS')) {
+ $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrPermissionEditComments'));
}
- $CommentManager = ObjectFactory::getInstance()->NewObject('CommentManager');
-
$CommentManager->ValidateComment($Discussion->Comment, 0);
-
- // Validate the whisperusername
- $CommentManager->ValidateWhisperUsername($Discussion);
+ }

- // If updating, validate that this is admin or the author
- if (!$NewDiscussion) {
- if ($OldDiscussion->AuthUserID !=
$session->UserID
&& !$session->User->Permission('PERMISSION_EDIT_DISCUSSIONS')) {
- $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrPermissionEditComments'));
- }
+ // If validation was successful, then reset the
properties to db safe values for saving
+ if ($this->Context->WarningCollector->Count() == 0) {
+ $Discussion->Name = $Name;
+ }
+
+ if ($this->Context->WarningCollector->Iif()) {
+ $s = ObjectFactory::getInstance()->NewObject('SqlBuilder');
+
+ // Update the user info & check for spam
+ if ($NewDiscussion) {
+ $UserManager = ObjectFactory::getInstance()->NewObject('UserManager');
+ $UserManager->UpdateUserDiscussionCount($session->UserID);
}

- // If validation was successful, then reset the
properties to db safe values for saving
+ // Proceed with the save if there are no warnings
if ($this->Context->WarningCollector->Count() ==
0) {
- $Discussion->Name = $Name;
- }
-
- if ($this->Context->WarningCollector->Iif()) {
- $s = ObjectFactory::getInstance()->NewObject('SqlBuilder');
-
- // Update the user info & check for spam
+ $s->SetMainTable('Discussion', 'd');
+ $s->AddFieldNameValue('Name', $Discussion->Name);
+ $s->AddFieldNameValue('CategoryID', $Discussion->CategoryID);
if ($NewDiscussion) {
- $UserManager = ObjectFactory::getInstance()->NewObject('UserManager');
- $UserManager->UpdateUserDiscussionCount($session->UserID);
+ $s->AddFieldNameValue('AuthUserID', $session->UserID);
+ $s->AddFieldNameValue('DateCreated', MysqlDateTime());
+ $s->AddFieldNameValue('DateLastActive', MysqlDateTime());
+ $s->AddFieldNameValue('CountComments', 0);
+ $s->AddFieldNameValue('WhisperUserID', $Discussion->WhisperUserID);
+ $Discussion->DiscussionID =
$db->Insert($s, $this->Name, 'NewDiscussion', 'An error occurred while
creating a new discussion.');
+ $Discussion->Comment->DiscussionID = $Discussion->DiscussionID;
+ } else {
+ $s->AddWhere('d', 'DiscussionID', '', $Discussion->DiscussionID, '=');
+ $db->Update($s,
$this->Name, 'NewDiscussion', 'An error occurred while updating the discussion.');
}
+ }

- // Proceed with the save if there are no warnings
- if ($this->Context->WarningCollector->Count()
== 0) {
+ // Now save the associated Comment
+ if ($Discussion->Comment->DiscussionID > 0) {
+
$CommentManager->SaveComment($Discussion->Comment, 1);
+
+ // Now update the topic table so that we know
what the first comment in the discussion was
+ if ($Discussion->Comment->CommentID > 0 &&
$NewDiscussion) {
+ $s->Clear();
$s->SetMainTable('Discussion', 'd');
- $s->AddFieldNameValue('Name', $Discussion->Name);
- $s->AddFieldNameValue('CategoryID', $Discussion->CategoryID);
- if ($NewDiscussion) {
- $s->AddFieldNameValue('AuthUserID', $session->UserID);
- $s->AddFieldNameValue('DateCreated', MysqlDateTime());
-
$s->AddFieldNameValue('DateLastActive', MysqlDateTime());
- $s->AddFieldNameValue('CountComments', 0);
- $s->AddFieldNameValue('WhisperUserID', $Discussion->WhisperUserID);
- $Discussion->DiscussionID =
$db->Insert($s, $this->Name, 'NewDiscussion', 'An error occurred while
creating a new discussion.');
- $Discussion->Comment->DiscussionID = $Discussion->DiscussionID;
- } else {
- $s->AddWhere('d', 'DiscussionID', '', $Discussion->DiscussionID, '=');
- $db->Update($s,
$this->Name, 'NewDiscussion', 'An error occurred while updating the discussion.');
- }
- }
-
- // Now save the associated Comment
- if ($Discussion->Comment->DiscussionID > 0) {
-
$CommentManager->SaveComment($Discussion->Comment, 1);
-
- // Now update the topic table so that we
know what the first comment in the discussion was
- if ($Discussion->Comment->CommentID > 0 &&
$NewDiscussion) {
- $s->Clear();
- $s->SetMainTable('Discussion', 'd');
-
$s->AddFieldNameValue('FirstCommentID', $Discussion->Comment->CommentID);
- $s->AddWhere('d', 'DiscussionID', '', $Discussion->Comment->DiscussionID, '=');
- $db->Update($s,
$this->Name, 'NewDiscussion', 'An error occurred while updating
discussion properties.');
- }
+ $s->AddFieldNameValue('FirstCommentID', $Discussion->Comment->CommentID);
+ $s->AddWhere('d', 'DiscussionID', '', $Discussion->Comment->DiscussionID, '=');
+ $db->Update($s,
$this->Name, 'NewDiscussion', 'An error occurred while updating
discussion properties.');
}
}
}

Reply all
Reply to author
Forward
0 new messages