[Customisation Database Commits] [customisation-db] Add "dotted" topics. Ticket #62149.

Cesar G prototech91 at gmail.com
Sun Apr 15 19:16:27 BST 2012



commit fd6304c7deb068c2bf633bf0fc5c5581ab424188
Author: Cesar G <prototech91 at gmail.com>
Date:   Sat Apr 14 19:47:14 2012 -0700

    Add "dotted" topics. Ticket #62149.

diff --git a/titania/common.php b/titania/common.php
index 3e93a66..fb9044e 100644
--- a/titania/common.php
+++ b/titania/common.php
@@ -22,7 +22,7 @@ if (!defined('NOT_IN_COMMUNITY'))
 }
 
 // Version number (only used for the installer)
-define('TITANIA_VERSION', '0.3.15');
+define('TITANIA_VERSION', '0.3.16');
 
 define('PHPBB_USE_BOARD_URL_PATH', true);
 if (!defined('IN_TITANIA_INSTALL'))
diff --git a/titania/includes/dynamic_constants.php b/titania/includes/dynamic_constants.php
index caada13..d58d94f 100644
--- a/titania/includes/dynamic_constants.php
+++ b/titania/includes/dynamic_constants.php
@@ -46,5 +46,6 @@ define('TITANIA_TAG_APPLIED_TABLE',				$table_prefix . 'tag_applied');
 define('TITANIA_TAG_FIELDS_TABLE',				$table_prefix . 'tag_fields');
 define('TITANIA_TAG_TYPES_TABLE',				$table_prefix . 'tag_types');
 define('TITANIA_TOPICS_TABLE',					$table_prefix . 'topics');
+define('TITANIA_TOPICS_POSTED_TABLE',			$table_prefix . 'topics_posted');
 define('TITANIA_TRACK_TABLE',					$table_prefix . 'track');
 define('TITANIA_WATCH_TABLE',					$table_prefix . 'watch');
\ No newline at end of file
diff --git a/titania/includes/functions_install.php b/titania/includes/functions_install.php
index f4dcf32..c8f5531 100644
--- a/titania/includes/functions_install.php
+++ b/titania/includes/functions_install.php
@@ -175,6 +175,41 @@ function titania_custom($action, $version)
 						phpbb::$db->sql_query($sql);
 					}
 				break;
+
+				case '0.3.16' :
+					$sql = 'SELECT DISTINCT topic_id, post_user_id
+						FROM ' . TITANIA_POSTS_TABLE . ' 
+						WHERE post_approved = 1 AND post_deleted = 0';
+					$result = phpbb::$db->sql_query($sql);
+					
+					$data = array();
+					$i = 0;
+
+					while ($row = phpbb::$db->sql_fetchrow($result))
+					{
+						$batch = floor($i / 500);
+						
+						$data[$batch][] = array(
+							'topic_id'		=> (int) $row['topic_id'],
+							'user_id'		=> (int) $row['post_user_id'],
+							'topic_posted'	=> 1
+						);
+						++$i;
+					}
+					phpbb::$db->sql_freeresult($result);
+
+					if (sizeof($data))
+					{
+						phpbb::$db->sql_query('TRUNCATE ' . TITANIA_TOPICS_POSTED_TABLE);
+
+						foreach ($data as $batch => $rows)
+						{
+							phpbb::$db->sql_multi_insert(TITANIA_TOPICS_POSTED_TABLE, $rows);
+						}
+						
+						unset($data);
+					}				
+				break;
 			}
 		break;
 
diff --git a/titania/includes/manage_tools/resync_dotted_topics.php b/titania/includes/manage_tools/resync_dotted_topics.php
new file mode 100644
index 0000000..ab3939b
--- /dev/null
+++ b/titania/includes/manage_tools/resync_dotted_topics.php
@@ -0,0 +1,69 @@
+<?php
+/**
+*
+* @package Titania
+* @copyright (c) 2012 phpBB Customisation Database Team
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2
+*
+*/
+
+/**
+ * @ignore
+ */
+if (!defined('IN_PHPBB'))
+{
+	exit;
+}
+
+class resync_dotted_topics
+{
+	/**
+	* Tool overview page
+	*/
+	function display_options()
+	{
+		return 'RESYNC_DOTTED_TOPICS';
+	}
+
+	/**
+	* Run the tool
+	*/
+	function run_tool()
+	{
+		$sql = 'SELECT DISTINCT topic_id, post_user_id
+			FROM ' . TITANIA_POSTS_TABLE . ' 
+			WHERE post_approved = 1 AND post_deleted = 0';
+		$result = phpbb::$db->sql_query($sql);
+
+		$data = array();
+		$i = 0;
+
+		while ($row = phpbb::$db->sql_fetchrow($result))
+		{
+			$batch = floor($i / 500);
+
+			$data[$batch][] = array(
+				'topic_id'		=> (int) $row['topic_id'],
+				'user_id'		=> (int) $row['post_user_id'],
+				'topic_posted'	=> 1
+			);
+			++$i;
+		}
+		phpbb::$db->sql_freeresult($result);
+
+		if (sizeof($data))
+		{
+			phpbb::$db->sql_query('TRUNCATE ' . TITANIA_TOPICS_POSTED_TABLE);
+
+			foreach ($data as $batch => $rows)
+			{
+				phpbb::$db->sql_multi_insert(TITANIA_TOPICS_POSTED_TABLE, $rows);
+			}
+			
+			unset($data);
+		}
+
+
+		trigger_back('RESYNC_DOTTED_TOPICS_COMPLETE');
+	}
+}
diff --git a/titania/includes/objects/post.php b/titania/includes/objects/post.php
index d552890..da17f0f 100644
--- a/titania/includes/objects/post.php
+++ b/titania/includes/objects/post.php
@@ -400,6 +400,11 @@ class titania_post extends titania_message_object
 			));
 			$attention->submit();
 		}
+		else
+		{
+			// Update posted topics table
+			$this->topic->update_posted_status('add', $this->post_user_id);
+		}
 
 		// If no topic_id it means we are creating a new topic, so we need to set the first_post_ data.
 		// Respect the post_time!  If for some reason we want to insert a post before the first one...
@@ -578,6 +583,9 @@ class titania_post extends titania_message_object
 
 		parent::submit();
 
+		// Update topics posted table
+		$this->topic->update_posted_status('remove', $this->post_user_id);
+
 		// Decrement the user's postcount if we must
 		if ($this->post_approved && in_array($this->post_type, titania::$config->increment_postcount))
 		{
@@ -651,6 +659,9 @@ class titania_post extends titania_message_object
 
 		parent::submit();
 
+		// Update topics posted table
+		$this->topic->update_posted_status('add', $this->post_user_id);
+
 		// Increment the user's postcount if we must
 		if ($this->post_approved && in_array($this->post_type, titania::$config->increment_postcount))
 		{
@@ -730,6 +741,9 @@ class titania_post extends titania_message_object
 		// Initiate self-destruct mode
 		parent::delete();
 
+		// Update topics posted table
+		$this->topic->update_posted_status('remove', $this->post_user_id);
+
 		// Check if the topic is empty
 		$flags = titania_count::get_flags(TITANIA_ACCESS_TEAMS, true, true);
 		if (titania_count::from_db($this->topic->topic_posts, $flags) <= 0)
diff --git a/titania/includes/objects/topic.php b/titania/includes/objects/topic.php
index 3dc13c8..ba9eb09 100644
--- a/titania/includes/objects/topic.php
+++ b/titania/includes/objects/topic.php
@@ -241,6 +241,47 @@ class titania_topic extends titania_database_object
 	}
 
 	/**
+	* Update topic posted mark
+	*
+	* Based on code from phpBB's functions.php and functions_posting.php
+	*/
+	public function update_posted_status($mode = 'add', $user_id = false)
+	{
+		$user_id = (int) ($user_id) ? $user_id : phpbb::$user->data['user_id'];
+		$this->topic_id = (int) $this->topic_id;
+
+		if ($mode == 'add')
+		{
+			phpbb::$db->sql_return_on_error(true);
+
+			$sql_ary = array(
+				'user_id'		=> $user_id,
+				'topic_id'		=> $this->topic_id,
+				'topic_posted'	=> 1
+			);
+
+			phpbb::$db->sql_query('INSERT INTO ' . TITANIA_TOPICS_POSTED_TABLE . ' ' . phpbb::$db->sql_build_array('INSERT', $sql_ary));
+
+			phpbb::$db->sql_return_on_error(false);			
+		}
+		else if ($mode == 'remove')
+		{
+			$sql = 'SELECT post_id
+				FROM ' . TITANIA_POSTS_TABLE . '
+				WHERE post_user_id = ' . $user_id . ' AND topic_id = ' . $this->topic_id . '
+					AND post_approved = 1 AND post_deleted = 0';
+			phpbb::$db->sql_query_limit($sql, 1);
+			$post_id = phpbb::$db->sql_fetchfield('post_id');
+
+			if (!$post_id)
+			{
+				$sql = 'DELETE FROM ' . TITANIA_TOPICS_POSTED_TABLE . ' WHERE user_id = ' . $user_id . ' AND topic_id = ' . $this->topic_id;
+				phpbb::$db->sql_query($sql);
+			}
+		}
+	}
+
+	/**
 	* Assign details
 	*
 	* A little different from those in other classes, this one only returns the info ready for output
diff --git a/titania/includes/overlords/queue.php b/titania/includes/overlords/queue.php
index 0bb69de..9d8ec7e 100644
--- a/titania/includes/overlords/queue.php
+++ b/titania/includes/overlords/queue.php
@@ -107,7 +107,7 @@ class queue_overlord
 		$queue_ids = array();
 
 		$sql_ary = array(
-			'SELECT' => '*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour',
+			'SELECT' => '*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour, tp.topic_posted',
 
 			'FROM'		=> array(
 				TITANIA_QUEUE_TABLE		=> 'q',
@@ -116,6 +116,13 @@ class queue_overlord
 				TITANIA_TOPICS_TABLE	=> 't',
 			),
 
+			'LEFT_JOIN'	=> array(
+				array(
+					'FROM'	=> array(TITANIA_TOPICS_POSTED_TABLE => 'tp'),
+					'ON'	=> 'tp.topic_id = t.topic_id AND tp.user_id = ' . (int) phpbb::$user->data['user_id'],
+				),
+			),
+
 			'WHERE' => 'q.queue_type = ' . (int) $type .
 				(($queue_status) ? ' AND q.queue_status = ' . (int) $queue_status : ' AND q.queue_status > 0 ') . '
 				AND c.contrib_id = q.contrib_id
@@ -177,6 +184,7 @@ class queue_overlord
 			$row = self::$queue[$queue_id];
 
 			$topic->__set_array($row);
+			$topic->topic_posted = $row['topic_posted'];
 
 			phpbb::$template->assign_block_vars('topics', array_merge($topic->assign_details(), array(
 				'TOPIC_SUBJECT'				=> $row['contrib_name'] . ' - ' . $row['revision_version'],
diff --git a/titania/includes/overlords/topics.php b/titania/includes/overlords/topics.php
index 558f279..96f3725 100644
--- a/titania/includes/overlords/topics.php
+++ b/titania/includes/overlords/topics.php
@@ -206,12 +206,19 @@ $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DA
 		$switch_on_sticky = true; // Display the extra block after stickies end?  Not used when not sorting with stickies first
 
 		$sql_ary = array(
-			'SELECT' => 't.*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour',
+			'SELECT' => 't.*, u.username as topic_first_post_username, u.user_colour as topic_first_post_user_colour, ul.username as topic_last_post_username, ul.user_colour as topic_last_post_user_colour, tp.topic_posted',
 
 			'FROM'		=> array(
 				TITANIA_TOPICS_TABLE	=> 't',
 			),
 
+			'LEFT_JOIN'	=> array(
+				array(
+					'FROM'	=> array(TITANIA_TOPICS_POSTED_TABLE => 'tp'),
+					'ON'	=> 'tp.topic_id = t.topic_id AND tp.user_id = ' . (int) phpbb::$user->data['user_id'],
+				),
+			),
+
 			'WHERE' => self::sql_permissions('t.', false, true),
 
 			'ORDER_BY'	=> 't.topic_sticky DESC, ' . $sort->get_order_by(),
@@ -424,6 +431,7 @@ $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DA
 
 			$topic->__set_array($row);
 			$contrib->__set_array($row);
+			$topic->topic_posted = $row['topic_posted'];
 
 			phpbb::$template->assign_block_vars('topics', array_merge($topic->assign_details(), array(
 				'S_TOPIC_TYPE_SWITCH'		=> ($switch_on_sticky && $last_was_sticky && !$topic->topic_sticky) ? true : false,
diff --git a/titania/includes/versions.php b/titania/includes/versions.php
index b863537..abd4e12 100644
--- a/titania/includes/versions.php
+++ b/titania/includes/versions.php
@@ -667,6 +667,20 @@ $versions = array(
 		'table_column_add' => array(
 			array(TITANIA_CONTRIBS_TABLE, 'contrib_limited_support', array('TINT:1', 0)),
 		),
+	'0.3.16' => array(
+		'table_add' => array(
+			array(TITANIA_TOPICS_POSTED_TABLE, array(
+				'COLUMNS'		=> array(
+					'user_id'			=> array('UINT', 0),
+					'topic_id'			=> array('UINT', 0),
+					'topic_posted'		=> array('TINT:1', 0)),
+				'KEYS'			=> array(
+					'user_id'			=> array('INDEX', 'user_id'),
+					'topic_id'			=> array('INDEX', 'topic_id'),
+				),
+			)),
+		),
+		'custom'	=> 'titania_custom',
 	),
 	// IF YOU ADD A NEW VERSION DO NOT FORGET TO INCREMENT THE VERSION NUMBER IN common.php!
 );
diff --git a/titania/language/en/manage_tools/resync_dotted_topics.php b/titania/language/en/manage_tools/resync_dotted_topics.php
new file mode 100644
index 0000000..c216279
--- /dev/null
+++ b/titania/language/en/manage_tools/resync_dotted_topics.php
@@ -0,0 +1,43 @@
+<?php
+/**
+*
+* @package Titania
+* @copyright (c) 2012 phpBB Customisation Database Team
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2
+*
+*/
+
+/**
+* DO NOT CHANGE
+*/
+if (!defined('IN_PHPBB'))
+{
+	exit;
+}
+
+if (empty($lang) || !is_array($lang))
+{
+	$lang = array();
+}
+
+// DEVELOPERS PLEASE NOTE
+//
+// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
+//
+// Placeholders can now contain order information, e.g. instead of
+// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
+// translators to re-order the output of data while ensuring it remains correct
+//
+// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
+// equally where a string contains only two placeholders which are used to wrap text
+// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
+//
+// Some characters you may want to copy&paste:
+// ’ » “ ” …
+//
+
+$lang = array_merge($lang, array(
+	'RESYNC_DOTTED_TOPICS'		=> 'Resynchronise dotted topics',
+	'RESYNC_DOTTED_TOPICS_COMPLETE'		=> 'All dotted topics have been resynchronised.',
+	'RESYNC_DOTTED_TOPICS_CONFIRM'		=> 'Are you sure that you want to resynchronise all dotted topics?',
+));
\ No newline at end of file
diff --git a/titania/manage/attention.php b/titania/manage/attention.php
index 3fdcfe3..931cfb4 100644
--- a/titania/manage/attention.php
+++ b/titania/manage/attention.php
@@ -185,6 +185,9 @@ if ($attention_id || ($object_type && $object_id))
 				$post->topic->topic_id = $post->topic_id;
 				$post->topic->load();
 
+				// Update topics posted table
+				$post->topic->update_posted_status('add', $post->post_user_id);
+
 				// Update first/last post?
 				if ($post->topic->topic_first_post_time > $post->post_time)
 				{




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://code.phpbb.com/pipermail/customisationdb-commits/attachments/20120415/d32709ff/attachment-0001.html>


More information about the customisationdb-commits mailing list