[Fusionforge-commits] FusionForge branch 6.0 updated. e2cd57d Update CHANGES

Sylvain Beucler beuc-inria at libremir.placard.fr.eu.org
Thu Jun 11 16:06:41 CEST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, 6.0 has been updated
       via  e2cd57d9fa4fe02d807802c4bb0f9f7cbcafd977 (commit)
       via  761cfe79507a19ed8a1c966f939f0beae2cb83e2 (commit)
      from  33726e533223c35803230d95da85315931fcad9f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e2cd57d9fa4fe02d807802c4bb0f9f7cbcafd977
Author: Sylvain Beucler <sylvain.beucler at inria.fr>
Date:   Thu Jun 11 16:04:56 2015 +0200

    Update CHANGES

diff --git a/src/CHANGES b/src/CHANGES
index ab2add4..6782b31 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -1,11 +1,13 @@
 FusionForge 6.0.1:
 * Accounts: accept elliptic curve ssh keys (Unit 193)
-* Accounts: fix project join request form (Inria)
+* Accounts: fix project join request form [#778] (Inria)
 * SCM: fix commit privileges (*_scmro group membership) (Inria)
 * SCM: kill stalled Apache processes (Inria)
+* Forum: fix conflict between attachments and pending attachments [#662] (Inria)
 * FRS: display new releases first (Roland Mas, for Inria)
 * Tracker: fix description re-html-ization when editing item (Inria)
 * Tracker: fix HTML entities in mail notifications (Inria)
+* Tracker: provide a "Submit" button below the "add a comment" field [#776] (TrivialDev)
 * Widgets: MyProjects: only display active projects (Inria)
 * SCM SVN: fix double-compression in ViewVC (Inria)
 * SCM SVN: support files with spaces in ViewVC (Inria)

commit 761cfe79507a19ed8a1c966f939f0beae2cb83e2
Author: Sylvain Beucler <sylvain.beucler at inria.fr>
Date:   Thu Jun 11 16:04:49 2015 +0200

    forum: fix attachments upgrade script, fix message approval, fix pending attachments download, and properly delete attachments

diff --git a/src/common/docman/DocumentStorage.class.php b/src/common/docman/DocumentStorage.class.php
index 8cddf5c..3a979ef 100644
--- a/src/common/docman/DocumentStorage.class.php
+++ b/src/common/docman/DocumentStorage.class.php
@@ -46,6 +46,7 @@
 require_once $gfcommon.'include/Storage.class.php';
 
 class DocumentStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 			$c = __CLASS__;
diff --git a/src/common/forum/AttachManager.class.php b/src/common/forum/AttachManager.class.php
index cbb9bd0..9e08e0b 100644
--- a/src/common/forum/AttachManager.class.php
+++ b/src/common/forum/AttachManager.class.php
@@ -26,6 +26,7 @@
  */
 
 require_once $gfcommon.'forum/ForumStorage.class.php';
+require_once $gfcommon.'forum/ForumPendingStorage.class.php';
 
 class AttachManager extends Error {
 
@@ -306,14 +307,14 @@ class AttachManager extends Error {
 					if ($attachment_size) {
 						if (is_file($attachment)) {
 							$id = db_insertid($res,'forum_pending_attachment','attachmentid');
-							if (ForumStorage::instance()->store($this->$id, $attachment)) {
+							if (ForumPendingStorage::instance()->store($id, $attachment)) {
 								$this->messages[] = _('File uploaded');
 								db_commit();
 								return true;
 							} else {
-								ForumStorage::instance()->rollback();
+								ForumPendingStorage::instance()->rollback();
 								db_rollback();
-								$this->setError(ForumStorage::instance()->getErrorMessage());
+								$this->setError(ForumPendingStorage::instance()->getErrorMessage());
 								$this->messages[] = _('File not uploaded');
 								return false;
 							}
@@ -324,10 +325,9 @@ class AttachManager extends Error {
 							return false;
 						}
 					}
-					$this->messages[] = _('File not uploaded');
-				} else {
-					$this->messages[] = _('File not uploaded');
 				}
+				db_rollback();
+				$this->messages[] = _('File not uploaded');
 			}
 		} else {
 			if ($update) {
@@ -373,7 +373,7 @@ class AttachManager extends Error {
 				if ($msg_id != 0) {
 					$this->msg_id = $msg_id;
 				} else {
-					$result = db_query_params('SELECT max(msg_id) AS id FROM forum_pending_messages',
+					$result = db_query_params('SELECT max(msg_id) AS id FROM forum_messages',
 								array());
 					if (!$result || db_numrows($result) < 1) {
 						$this->messages[] = _('Could not get message id');
diff --git a/src/common/forum/Forum.class.php b/src/common/forum/Forum.class.php
index 452221f..bebd422 100644
--- a/src/common/forum/Forum.class.php
+++ b/src/common/forum/Forum.class.php
@@ -642,6 +642,7 @@ class Forum extends Error {
 			db_rollback();
 			return false;
 		}
+		# TODO: remove attachments from the filesystem
 
 		$result = db_query_params('DELETE FROM forum WHERE group_forum_id=$1',
 				array($this->getID()));
diff --git a/src/common/forum/ForumAdmin.class.php b/src/common/forum/ForumAdmin.class.php
index fd92684..b13f81f 100644
--- a/src/common/forum/ForumAdmin.class.php
+++ b/src/common/forum/ForumAdmin.class.php
@@ -369,19 +369,21 @@ class ForumAdmin extends Error {
 					case 2 : {
 						//delete
 						db_begin();
-						if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
-									array ($msgids[$i]))) {
-							$error_msg .= "DB Error: ". db_error();
-							db_rollback();
-							break;
+						$res_pa = db_query_params('SELECT attachmentid FROM forum_pending_attachment WHERE msg_id=$1',
+												  array($msgids[$i]));
+						while ($pa = db_fetch_array($res_pa)) {
+							ForumPendingStorage::instance()->delete($pa['attachmentid']);
+							db_query_params('DELETE FROM forum_pending_attachment WHERE attachmentid=$1', array($pa['attachmentid']));
 						}
 						if (!db_query_params('DELETE FROM forum_pending_messages WHERE msg_id=$1',
 									array ($msgids[$i]))) {
 							$error_msg .= "DB Error: ". db_error();
 							db_rollback();
+							ForumPendingStorage::instance()->rollback();
 							break;
 						}
 						db_commit();
+						ForumPendingStorage::instance()->commit();
 						$feedback .= _('Forum deleted');
 						break;
 					}
@@ -429,7 +431,7 @@ class ForumAdmin extends Error {
 								$userid = db_result($res2,0,"userid");
 								$dateline = db_result($res2,0,"dateline");
 								$filename = db_result($res2,0,"filename");
-								$filedata = db_result($res2,0,"filedata");
+								$filedata = ForumPendingStorage::instance()->get_storage(db_result($res2,0,"attachmentid"));
 								$filesize = db_result($res2,0,"filesize");
 								$visible = db_result($res2,0,"visible");
 								$msg_id = db_result($res2,0,"msg_id");
@@ -472,7 +474,8 @@ class ForumAdmin extends Error {
 						}
 
 						if ($deleteok) {
-							//delete the message and attach
+							// delete the message
+							// delete attachments (in the DB only, files already moved by FileStorage::store)
 							db_begin();
 							if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
 										array ($msgids[$i]))) {
diff --git a/src/common/forum/ForumMessage.class.php b/src/common/forum/ForumMessage.class.php
index 4b9a821..7b13b48 100644
--- a/src/common/forum/ForumMessage.class.php
+++ b/src/common/forum/ForumMessage.class.php
@@ -593,14 +593,18 @@ class ForumMessage extends Error {
 			$msg = new ForumMessage($this->Forum,db_result($result,$i,'msg_id'));
 			$count += $msg->delete();
 		}
-		$toss = db_query_params ('DELETE FROM forum
-			WHERE msg_id=$1
-			AND group_forum_id=$2',
-					 array ($msg_id,
-						$this->Forum->getID())) ;
 
-		$res = db_query_params ('DELETE FROM forum_attachment where msg_id=$1',
-					array ($msg_id));
+		$res_pa = db_query_params('SELECT attachmentid FROM forum_attachment WHERE msg_id=$1',
+								  array($msg_id));
+		while ($pa = db_fetch_array($res_pa)) {
+			ForumStorage::instance()->delete($pa['attachmentid']);
+			db_query_params('DELETE FROM forum_attachment WHERE attachmentid=$1',
+							array($pa['attachmentid']));
+		}
+		ForumStorage::instance()->commit();
+
+		$toss = db_query_params('DELETE FROM forum WHERE msg_id=$1 AND group_forum_id=$2',
+								array ($msg_id, $this->Forum->getID()));
 
 		return $count;
 	}
diff --git a/src/common/forum/ForumStorage.class.php b/src/common/forum/ForumPendingStorage.class.php
similarity index 94%
copy from src/common/forum/ForumStorage.class.php
copy to src/common/forum/ForumPendingStorage.class.php
index 67c67a7..8a3120a 100644
--- a/src/common/forum/ForumStorage.class.php
+++ b/src/common/forum/ForumPendingStorage.class.php
@@ -45,7 +45,8 @@
 
 require_once $gfcommon.'include/Storage.class.php';
 
-class ForumStorage extends Storage {
+class ForumPendingStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 			$c = __CLASS__;
@@ -55,6 +56,6 @@ class ForumStorage extends Storage {
 	}
 
 	function get_storage_path() {
-		return forge_get_config('data_path').'/forum';
+		return forge_get_config('data_path').'/forum/pending';
 	}
 }
diff --git a/src/common/forum/ForumStorage.class.php b/src/common/forum/ForumStorage.class.php
index 67c67a7..5426090 100644
--- a/src/common/forum/ForumStorage.class.php
+++ b/src/common/forum/ForumStorage.class.php
@@ -46,6 +46,7 @@
 require_once $gfcommon.'include/Storage.class.php';
 
 class ForumStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 			$c = __CLASS__;
diff --git a/src/common/include/Storage.class.php b/src/common/include/Storage.class.php
index 0852c30..564d6ee 100644
--- a/src/common/include/Storage.class.php
+++ b/src/common/include/Storage.class.php
@@ -79,7 +79,7 @@ class Storage extends Error {
 
 	function delete($key) {
 		$this->pending_delete[] = $this->get_storage($key);
-		return self::$_instance;
+		return $this->instance();
 	}
 
 	function deleteFromQuery($query, $params) {
diff --git a/src/common/tracker/ArtifactStorage.class.php b/src/common/tracker/ArtifactStorage.class.php
index ae4dce8..1c78631 100644
--- a/src/common/tracker/ArtifactStorage.class.php
+++ b/src/common/tracker/ArtifactStorage.class.php
@@ -45,6 +45,7 @@
 require_once $gfcommon.'include/Storage.class.php';
 
 class ArtifactStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 		$c = __CLASS__;
diff --git a/src/db/20140710-forum-migrate-attachments-to-fs.php b/src/db/20140710-forum-migrate-attachments-to-fs.php
index b90e478..bcb384d 100644
--- a/src/db/20140710-forum-migrate-attachments-to-fs.php
+++ b/src/db/20140710-forum-migrate-attachments-to-fs.php
@@ -25,6 +25,7 @@
 require_once dirname(__FILE__).'/../common/include/env.inc.php';
 require_once $gfcommon.'include/pre.php';
 require_once $gfcommon.'forum/ForumStorage.class.php';
+require_once $gfcommon.'forum/ForumPendingStorage.class.php';
 
 ini_set('memory_limit', -1);
 ini_set('max_execution_time', 0);
@@ -34,12 +35,18 @@ if (!is_dir($data_path)) {
 	system("mkdir -p $data_path");
 	system("chmod 0755 $data_path");
 }
-if (!is_dir("$data/forum")) {
+if (!is_dir("$data_path/forum")) {
 	system("mkdir $data_path/forum");
 	system("chmod 0700 $data_path/forum");
 }
+if (!is_dir("$data_path/forum/pending")) {
+	system("mkdir $data_path/forum/pending");
+	system("chmod 0700 $data_path/forum/pending");
+}
 
 $fs = new ForumStorage();
+$fps = new ForumPendingStorage();
+
 $tmp = tempnam('/tmp', 'forum');
 
 $res = db_query_params('SELECT attachmentid FROM forum_attachment where filedata != $1', array(0));
@@ -92,21 +99,21 @@ while($row = db_fetch_array($res)) {
 	$ret = file_put_contents($tmp, $data);
 	if ($ret === false) {
 		echo "UPGRADE ERROR: file_put_contents($tmp) error: returned false\n";
-		$fs->rollback();
+		$fps->rollback();
 		exit(1);
 	}
 	if ($ret != $size) {
 		echo "UPGRADE ERROR: file_put_contents($tmp) size error: ($ret != ".$size.")\n";
-		$fs->rollback();
+		$fps->rollback();
 		exit(1);
 	}
-	$ret = $fs->store($row['attachmentid'], $tmp);
+	$ret = $fps->store($row['attachmentid'], $tmp);
 	if (!$ret) {
-		echo "UPGRADE ERROR: $ret: ".$fs->getErrorMessage()."\n";
-		$fs->rollback();
+		echo "UPGRADE ERROR: $ret: ".$fps->getErrorMessage()."\n";
+		$fps->rollback();
 		exit(1);
 	}
-	$fs->commit();
+	$fps->commit();
 	db_query_params('UPDATE forum_pending_attachment set filedata = $1 where attachmentid = $2', array(0, $row['attachmentid']));
 }
 
diff --git a/src/www/forum/attachment.php b/src/www/forum/attachment.php
index 432ba5e..ceacc73 100644
--- a/src/www/forum/attachment.php
+++ b/src/www/forum/attachment.php
@@ -29,6 +29,7 @@ require_once '../env.inc.php';
 require_once $gfcommon.'include/pre.php';
 require_once $gfcommon.'forum/ForumHTML.class.php';
 require_once $gfcommon.'forum/ForumStorage.class.php';
+require_once $gfcommon.'forum/ForumPendingStorage.class.php';
 
 /**
  *  goodbye - Just prints a message and a close button.
@@ -131,7 +132,7 @@ if ($edit == "yes") {
 				}
 			} else {
 				//add new one
-				$attachok = $am->attach($attach,$group_id,$attachid, $msg_id);
+				$attachok = $am->attach($attach,$group_id,false,$msg_id);
 				if ($attachok!=false) {
 					$fm->fetchData($msg_id);
 					$fm->sendAttachNotice($attachok);
@@ -205,7 +206,11 @@ if ($mimetype) {
 	header('Content-type: application/octet-stream');
 }
 
-readfile_chunked(ForumStorage::instance()->get($attachid));
+if ($pending) {
+	readfile_chunked(ForumPendingStorage::instance()->get($attachid));
+} else {
+	readfile_chunked(ForumStorage::instance()->get($attachid));
+}
 flush();
 
 //increase the attach count

-----------------------------------------------------------------------

Summary of changes:
 src/CHANGES                                         |  4 +++-
 src/common/docman/DocumentStorage.class.php         |  1 +
 src/common/forum/AttachManager.class.php            | 14 +++++++-------
 src/common/forum/Forum.class.php                    |  1 +
 src/common/forum/ForumAdmin.class.php               | 17 ++++++++++-------
 src/common/forum/ForumMessage.class.php             | 18 +++++++++++-------
 ...rage.class.php => ForumPendingStorage.class.php} |  5 +++--
 src/common/forum/ForumStorage.class.php             |  1 +
 src/common/include/Storage.class.php                |  2 +-
 src/common/tracker/ArtifactStorage.class.php        |  1 +
 src/db/20140710-forum-migrate-attachments-to-fs.php | 21 ++++++++++++++-------
 src/www/forum/attachment.php                        |  9 +++++++--
 12 files changed, 60 insertions(+), 34 deletions(-)
 copy src/common/forum/{ForumStorage.class.php => ForumPendingStorage.class.php} (94%)

diff --git a/src/CHANGES b/src/CHANGES
index ab2add4..6782b31 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -1,11 +1,13 @@
 FusionForge 6.0.1:
 * Accounts: accept elliptic curve ssh keys (Unit 193)
-* Accounts: fix project join request form (Inria)
+* Accounts: fix project join request form [#778] (Inria)
 * SCM: fix commit privileges (*_scmro group membership) (Inria)
 * SCM: kill stalled Apache processes (Inria)
+* Forum: fix conflict between attachments and pending attachments [#662] (Inria)
 * FRS: display new releases first (Roland Mas, for Inria)
 * Tracker: fix description re-html-ization when editing item (Inria)
 * Tracker: fix HTML entities in mail notifications (Inria)
+* Tracker: provide a "Submit" button below the "add a comment" field [#776] (TrivialDev)
 * Widgets: MyProjects: only display active projects (Inria)
 * SCM SVN: fix double-compression in ViewVC (Inria)
 * SCM SVN: support files with spaces in ViewVC (Inria)
diff --git a/src/common/docman/DocumentStorage.class.php b/src/common/docman/DocumentStorage.class.php
index 8cddf5c..3a979ef 100644
--- a/src/common/docman/DocumentStorage.class.php
+++ b/src/common/docman/DocumentStorage.class.php
@@ -46,6 +46,7 @@
 require_once $gfcommon.'include/Storage.class.php';
 
 class DocumentStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 			$c = __CLASS__;
diff --git a/src/common/forum/AttachManager.class.php b/src/common/forum/AttachManager.class.php
index cbb9bd0..9e08e0b 100644
--- a/src/common/forum/AttachManager.class.php
+++ b/src/common/forum/AttachManager.class.php
@@ -26,6 +26,7 @@
  */
 
 require_once $gfcommon.'forum/ForumStorage.class.php';
+require_once $gfcommon.'forum/ForumPendingStorage.class.php';
 
 class AttachManager extends Error {
 
@@ -306,14 +307,14 @@ class AttachManager extends Error {
 					if ($attachment_size) {
 						if (is_file($attachment)) {
 							$id = db_insertid($res,'forum_pending_attachment','attachmentid');
-							if (ForumStorage::instance()->store($this->$id, $attachment)) {
+							if (ForumPendingStorage::instance()->store($id, $attachment)) {
 								$this->messages[] = _('File uploaded');
 								db_commit();
 								return true;
 							} else {
-								ForumStorage::instance()->rollback();
+								ForumPendingStorage::instance()->rollback();
 								db_rollback();
-								$this->setError(ForumStorage::instance()->getErrorMessage());
+								$this->setError(ForumPendingStorage::instance()->getErrorMessage());
 								$this->messages[] = _('File not uploaded');
 								return false;
 							}
@@ -324,10 +325,9 @@ class AttachManager extends Error {
 							return false;
 						}
 					}
-					$this->messages[] = _('File not uploaded');
-				} else {
-					$this->messages[] = _('File not uploaded');
 				}
+				db_rollback();
+				$this->messages[] = _('File not uploaded');
 			}
 		} else {
 			if ($update) {
@@ -373,7 +373,7 @@ class AttachManager extends Error {
 				if ($msg_id != 0) {
 					$this->msg_id = $msg_id;
 				} else {
-					$result = db_query_params('SELECT max(msg_id) AS id FROM forum_pending_messages',
+					$result = db_query_params('SELECT max(msg_id) AS id FROM forum_messages',
 								array());
 					if (!$result || db_numrows($result) < 1) {
 						$this->messages[] = _('Could not get message id');
diff --git a/src/common/forum/Forum.class.php b/src/common/forum/Forum.class.php
index 452221f..bebd422 100644
--- a/src/common/forum/Forum.class.php
+++ b/src/common/forum/Forum.class.php
@@ -642,6 +642,7 @@ class Forum extends Error {
 			db_rollback();
 			return false;
 		}
+		# TODO: remove attachments from the filesystem
 
 		$result = db_query_params('DELETE FROM forum WHERE group_forum_id=$1',
 				array($this->getID()));
diff --git a/src/common/forum/ForumAdmin.class.php b/src/common/forum/ForumAdmin.class.php
index fd92684..b13f81f 100644
--- a/src/common/forum/ForumAdmin.class.php
+++ b/src/common/forum/ForumAdmin.class.php
@@ -369,19 +369,21 @@ class ForumAdmin extends Error {
 					case 2 : {
 						//delete
 						db_begin();
-						if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
-									array ($msgids[$i]))) {
-							$error_msg .= "DB Error: ". db_error();
-							db_rollback();
-							break;
+						$res_pa = db_query_params('SELECT attachmentid FROM forum_pending_attachment WHERE msg_id=$1',
+												  array($msgids[$i]));
+						while ($pa = db_fetch_array($res_pa)) {
+							ForumPendingStorage::instance()->delete($pa['attachmentid']);
+							db_query_params('DELETE FROM forum_pending_attachment WHERE attachmentid=$1', array($pa['attachmentid']));
 						}
 						if (!db_query_params('DELETE FROM forum_pending_messages WHERE msg_id=$1',
 									array ($msgids[$i]))) {
 							$error_msg .= "DB Error: ". db_error();
 							db_rollback();
+							ForumPendingStorage::instance()->rollback();
 							break;
 						}
 						db_commit();
+						ForumPendingStorage::instance()->commit();
 						$feedback .= _('Forum deleted');
 						break;
 					}
@@ -429,7 +431,7 @@ class ForumAdmin extends Error {
 								$userid = db_result($res2,0,"userid");
 								$dateline = db_result($res2,0,"dateline");
 								$filename = db_result($res2,0,"filename");
-								$filedata = db_result($res2,0,"filedata");
+								$filedata = ForumPendingStorage::instance()->get_storage(db_result($res2,0,"attachmentid"));
 								$filesize = db_result($res2,0,"filesize");
 								$visible = db_result($res2,0,"visible");
 								$msg_id = db_result($res2,0,"msg_id");
@@ -472,7 +474,8 @@ class ForumAdmin extends Error {
 						}
 
 						if ($deleteok) {
-							//delete the message and attach
+							// delete the message
+							// delete attachments (in the DB only, files already moved by FileStorage::store)
 							db_begin();
 							if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
 										array ($msgids[$i]))) {
diff --git a/src/common/forum/ForumMessage.class.php b/src/common/forum/ForumMessage.class.php
index 4b9a821..7b13b48 100644
--- a/src/common/forum/ForumMessage.class.php
+++ b/src/common/forum/ForumMessage.class.php
@@ -593,14 +593,18 @@ class ForumMessage extends Error {
 			$msg = new ForumMessage($this->Forum,db_result($result,$i,'msg_id'));
 			$count += $msg->delete();
 		}
-		$toss = db_query_params ('DELETE FROM forum
-			WHERE msg_id=$1
-			AND group_forum_id=$2',
-					 array ($msg_id,
-						$this->Forum->getID())) ;
 
-		$res = db_query_params ('DELETE FROM forum_attachment where msg_id=$1',
-					array ($msg_id));
+		$res_pa = db_query_params('SELECT attachmentid FROM forum_attachment WHERE msg_id=$1',
+								  array($msg_id));
+		while ($pa = db_fetch_array($res_pa)) {
+			ForumStorage::instance()->delete($pa['attachmentid']);
+			db_query_params('DELETE FROM forum_attachment WHERE attachmentid=$1',
+							array($pa['attachmentid']));
+		}
+		ForumStorage::instance()->commit();
+
+		$toss = db_query_params('DELETE FROM forum WHERE msg_id=$1 AND group_forum_id=$2',
+								array ($msg_id, $this->Forum->getID()));
 
 		return $count;
 	}
diff --git a/src/common/forum/ForumStorage.class.php b/src/common/forum/ForumPendingStorage.class.php
similarity index 94%
copy from src/common/forum/ForumStorage.class.php
copy to src/common/forum/ForumPendingStorage.class.php
index 67c67a7..8a3120a 100644
--- a/src/common/forum/ForumStorage.class.php
+++ b/src/common/forum/ForumPendingStorage.class.php
@@ -45,7 +45,8 @@
 
 require_once $gfcommon.'include/Storage.class.php';
 
-class ForumStorage extends Storage {
+class ForumPendingStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 			$c = __CLASS__;
@@ -55,6 +56,6 @@ class ForumStorage extends Storage {
 	}
 
 	function get_storage_path() {
-		return forge_get_config('data_path').'/forum';
+		return forge_get_config('data_path').'/forum/pending';
 	}
 }
diff --git a/src/common/forum/ForumStorage.class.php b/src/common/forum/ForumStorage.class.php
index 67c67a7..5426090 100644
--- a/src/common/forum/ForumStorage.class.php
+++ b/src/common/forum/ForumStorage.class.php
@@ -46,6 +46,7 @@
 require_once $gfcommon.'include/Storage.class.php';
 
 class ForumStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 			$c = __CLASS__;
diff --git a/src/common/include/Storage.class.php b/src/common/include/Storage.class.php
index 0852c30..564d6ee 100644
--- a/src/common/include/Storage.class.php
+++ b/src/common/include/Storage.class.php
@@ -79,7 +79,7 @@ class Storage extends Error {
 
 	function delete($key) {
 		$this->pending_delete[] = $this->get_storage($key);
-		return self::$_instance;
+		return $this->instance();
 	}
 
 	function deleteFromQuery($query, $params) {
diff --git a/src/common/tracker/ArtifactStorage.class.php b/src/common/tracker/ArtifactStorage.class.php
index ae4dce8..1c78631 100644
--- a/src/common/tracker/ArtifactStorage.class.php
+++ b/src/common/tracker/ArtifactStorage.class.php
@@ -45,6 +45,7 @@
 require_once $gfcommon.'include/Storage.class.php';
 
 class ArtifactStorage extends Storage {
+	protected static $_instance;
 	public static function instance() {
 		if (!isset(self::$_instance)) {
 		$c = __CLASS__;
diff --git a/src/db/20140710-forum-migrate-attachments-to-fs.php b/src/db/20140710-forum-migrate-attachments-to-fs.php
index b90e478..bcb384d 100644
--- a/src/db/20140710-forum-migrate-attachments-to-fs.php
+++ b/src/db/20140710-forum-migrate-attachments-to-fs.php
@@ -25,6 +25,7 @@
 require_once dirname(__FILE__).'/../common/include/env.inc.php';
 require_once $gfcommon.'include/pre.php';
 require_once $gfcommon.'forum/ForumStorage.class.php';
+require_once $gfcommon.'forum/ForumPendingStorage.class.php';
 
 ini_set('memory_limit', -1);
 ini_set('max_execution_time', 0);
@@ -34,12 +35,18 @@ if (!is_dir($data_path)) {
 	system("mkdir -p $data_path");
 	system("chmod 0755 $data_path");
 }
-if (!is_dir("$data/forum")) {
+if (!is_dir("$data_path/forum")) {
 	system("mkdir $data_path/forum");
 	system("chmod 0700 $data_path/forum");
 }
+if (!is_dir("$data_path/forum/pending")) {
+	system("mkdir $data_path/forum/pending");
+	system("chmod 0700 $data_path/forum/pending");
+}
 
 $fs = new ForumStorage();
+$fps = new ForumPendingStorage();
+
 $tmp = tempnam('/tmp', 'forum');
 
 $res = db_query_params('SELECT attachmentid FROM forum_attachment where filedata != $1', array(0));
@@ -92,21 +99,21 @@ while($row = db_fetch_array($res)) {
 	$ret = file_put_contents($tmp, $data);
 	if ($ret === false) {
 		echo "UPGRADE ERROR: file_put_contents($tmp) error: returned false\n";
-		$fs->rollback();
+		$fps->rollback();
 		exit(1);
 	}
 	if ($ret != $size) {
 		echo "UPGRADE ERROR: file_put_contents($tmp) size error: ($ret != ".$size.")\n";
-		$fs->rollback();
+		$fps->rollback();
 		exit(1);
 	}
-	$ret = $fs->store($row['attachmentid'], $tmp);
+	$ret = $fps->store($row['attachmentid'], $tmp);
 	if (!$ret) {
-		echo "UPGRADE ERROR: $ret: ".$fs->getErrorMessage()."\n";
-		$fs->rollback();
+		echo "UPGRADE ERROR: $ret: ".$fps->getErrorMessage()."\n";
+		$fps->rollback();
 		exit(1);
 	}
-	$fs->commit();
+	$fps->commit();
 	db_query_params('UPDATE forum_pending_attachment set filedata = $1 where attachmentid = $2', array(0, $row['attachmentid']));
 }
 
diff --git a/src/www/forum/attachment.php b/src/www/forum/attachment.php
index 432ba5e..ceacc73 100644
--- a/src/www/forum/attachment.php
+++ b/src/www/forum/attachment.php
@@ -29,6 +29,7 @@ require_once '../env.inc.php';
 require_once $gfcommon.'include/pre.php';
 require_once $gfcommon.'forum/ForumHTML.class.php';
 require_once $gfcommon.'forum/ForumStorage.class.php';
+require_once $gfcommon.'forum/ForumPendingStorage.class.php';
 
 /**
  *  goodbye - Just prints a message and a close button.
@@ -131,7 +132,7 @@ if ($edit == "yes") {
 				}
 			} else {
 				//add new one
-				$attachok = $am->attach($attach,$group_id,$attachid, $msg_id);
+				$attachok = $am->attach($attach,$group_id,false,$msg_id);
 				if ($attachok!=false) {
 					$fm->fetchData($msg_id);
 					$fm->sendAttachNotice($attachok);
@@ -205,7 +206,11 @@ if ($mimetype) {
 	header('Content-type: application/octet-stream');
 }
 
-readfile_chunked(ForumStorage::instance()->get($attachid));
+if ($pending) {
+	readfile_chunked(ForumPendingStorage::instance()->get($attachid));
+} else {
+	readfile_chunked(ForumStorage::instance()->get($attachid));
+}
 flush();
 
 //increase the attach count


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list