[Customisation Database Commits] r455 - in /trunk/titania: common.php includes/tools/sync.php
Nathan Guse
exreaction at phpbb.com
Wed Dec 30 02:18:51 GMT 2009
Author: exreaction
Date: Wed Dec 30 02:18:51 2009
New Revision: 455
Log:
Sync tool
Added:
trunk/titania/includes/tools/sync.php (with props)
Modified:
trunk/titania/common.php
Modified: trunk/titania/common.php
==============================================================================
*** trunk/titania/common.php (original)
--- trunk/titania/common.php Wed Dec 30 02:18:51 2009
***************
*** 63,66 ****
--- 63,80 ----
titania::$cache->purge();
titania::error_box('SUCCESS', phpbb::$user->lang['CACHE_PURGED']);
+ }
+
+ // admin requested a sync
+ if (isset($_GET['sync']) && phpbb::$auth->acl_get('a_'))
+ {
+ $sync = new titania_sync();
+ $method = explode('_', request_var('sync', ''), 2);
+
+ if (method_exists($sync, $method[0]))
+ {
+ $sync->$method[0]($method[1]);
+ }
+
+ titania::error_box('SUCCESS', 'Sync Success');
}
\ No newline at end of file
Added: trunk/titania/includes/tools/sync.php
==============================================================================
*** trunk/titania/includes/tools/sync.php (added)
--- trunk/titania/includes/tools/sync.php Wed Dec 30 02:18:51 2009
***************
*** 0 ****
--- 1,86 ----
+ <?php
+ /**
+ *
+ * @package Titania
+ * @version $Id$
+ * @copyright (c) 2009 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * @ignore
+ */
+ if (!defined('IN_TITANIA'))
+ {
+ exit;
+ }
+
+ // Hopefully this helps
+ @set_time_limit(0);
+
+ /**
+ * Sync handler for Titania
+ *
+ * Hopefully we never need to use this, but we probably will at some point, so put all sync stuff in here for easy access (and not to take up extra space in other files when they will rarely, if ever, be needed)
+ */
+ class titania_sync
+ {
+ /**
+ * Sync topics
+ *
+ * @param <type> $mode The mode (post_count - topics_posts field)
+ * @param <type> $topic_id The topic id to limit to
+ */
+ public function topics($mode, $topic_id = false)
+ {
+ switch ($mode)
+ {
+ // Sync the topics_posts field
+ case 'post_count' :
+ $sql = 'SELECT topic_id, topic_posts FROM ' . TITANIA_TOPICS_TABLE .
+ (($topic_id) ? ' WHERE topic_id = ' . (int) $topic_id : '') . '
+ ORDER BY topic_id ASC';
+ $result = phpbb::$db->sql_query($sql);
+ while ($row = phpbb::$db->sql_fetchrow($result))
+ {
+ $post_count = $this->_get_post_count($row['topic_id']);
+ if ($row['topic_posts'] != $post_count)
+ {
+ $sql = 'UPDATE ' . TITANIA_TOPICS_TABLE . ' SET topic_posts = \'' . $post_count . '\' WHERE topic_id = ' . $row['topic_id'];
+ phpbb::$db->sql_query($sql);
+ }
+ }
+ phpbb::$db->sql_freeresult($result);
+ break;
+ }
+ }
+
+ public function _get_post_count($topic_id)
+ {
+ $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
+ WHERE topic_id = ' . (int) $topic_id . '
+ AND (post_access = ' . TITANIA_ACCESS_TEAMS . ' OR post_deleted <> 0)'; // Account for our hacking
+ $result = phpbb::$db->sql_query($sql);
+ $teams = phpbb::$db->sql_fetchfield('cnt', $result);
+ phpbb::$db->sql_freeresult($result);
+
+ $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
+ WHERE topic_id = ' . (int) $topic_id . '
+ AND post_access = ' . TITANIA_ACCESS_AUTHORS . '
+ AND post_deleted = 0'; // Account for our hacking
+ $result = phpbb::$db->sql_query($sql);
+ $authors = phpbb::$db->sql_fetchfield('cnt', $result);
+ phpbb::$db->sql_freeresult($result);
+
+ $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
+ WHERE topic_id = ' . (int) $topic_id . '
+ AND post_access = ' . TITANIA_ACCESS_PUBLIC . '
+ AND post_deleted = 0'; // Account for our hacking
+ $result = phpbb::$db->sql_query($sql);
+ $public = phpbb::$db->sql_fetchfield('cnt', $result);
+ phpbb::$db->sql_freeresult($result);
+
+ return ($teams + $authors + $public) . ':' . ($authors + $public) . ':' . $public;
+ }
+ }
\ No newline at end of file
Propchange: trunk/titania/includes/tools/sync.php
------------------------------------------------------------------------------
svn:keywords = Revision Author Date Id
More information about the customisationdb-commits
mailing list