From 3362baca51bd82e6cc0d15625863e46506bece72 Mon Sep 17 00:00:00 2001
From: Joas Schilling <nickvergessen@gmx.de>
Date: Wed, 27 Feb 2013 19:27:30 +0100
Subject: [ticket/10411] Add migrations file for teampage table

PHPBB3-10411
---
 phpBB/includes/db/migration/data/310/teampage.php | 104 ++++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 phpBB/includes/db/migration/data/310/teampage.php

(limited to 'phpBB/includes/db')

diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/includes/db/migration/data/310/teampage.php
new file mode 100644
index 0000000000..510ecf9481
--- /dev/null
+++ b/phpBB/includes/db/migration/data/310/teampage.php
@@ -0,0 +1,104 @@
+<?php
+/**
+*
+* @package migration
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
+*
+*/
+
+class phpbb_db_migration_data_310_teampage extends phpbb_db_migration
+{
+	public function effectively_installed()
+	{
+		return $this->db_tools->sql_table_exists($this->table_prefix . 'teampage');
+	}
+
+	static public function depends_on()
+	{
+		return array('phpbb_db_migration_data_310_dev');
+	}
+
+	public function update_schema()
+	{
+		return array(
+			'add_tables'		=> array(
+				$this->table_prefix . 'teampage'	=> array(
+					'COLUMNS'		=> array(
+						'teampage_id'		=> array('UINT', NULL, 'auto_increment'),
+						'group_id'			=> array('UINT', 0),
+						'teampage_name'		=> array('VCHAR_UNI:255', ''),
+						'teampage_position'	=> array('UINT', 0),
+						'teampage_parent'	=> array('UINT', 0),
+					),
+					'PRIMARY_KEY'		=> 'teampage_id',
+				),
+			),
+			'drop_columns'		=> array(
+				$this->table_prefix . 'groups'		=> array(
+					'group_teampage',
+				),
+			),
+		);
+	}
+
+	public function revert_schema()
+	{
+		return array(
+			'drop_tables'		=> array(
+				$this->table_prefix . 'teampage',
+			),
+			'add_columns'		=> array(
+				$this->table_prefix . 'groups'		=> array(
+					'group_teampage'	=> array('UINT', 0, 'after' => 'group_legend'),
+				),
+			),
+		);
+	}
+
+	public function update_data()
+	{
+		return array(
+			array('custom', array(array($this, 'add_groups_teampage'))),
+		);
+	}
+
+	public function add_groups_teampage()
+	{
+		$sql = 'SELECT teampage_id
+			FROM ' . TEAMPAGE_TABLE;
+		$result = $this->db->sql_query_limit($sql, 1);
+		$added_groups_teampage = (bool) $this->db->sql_fetchfield('teampage_id');
+		$this->db->sql_freeresult($result);
+
+		if (!$added_groups_teampage)
+		{
+			$sql = 'SELECT *
+				FROM ' . GROUPS_TABLE . '
+				WHERE group_type = ' . GROUP_SPECIAL . "
+					AND (group_name = 'ADMINISTRATORS'
+						OR group_name = 'GLOBAL_MODERATORS')
+				ORDER BY group_name ASC";
+			$result = $this->db->sql_query($sql);
+
+			$teampage_entries = array();
+			while ($row = $db->sql_fetchrow($result))
+			{
+				$teampage_entries[] = array(
+					'group_id'			=> (int) $row['group_id'],
+					'teampage_name'		=> '',
+					'teampage_position'	=> sizeof($teampage_entries) + 1,
+					'teampage_parent'	=> 0,
+				);
+			}
+			$db->sql_freeresult($result);
+
+			if (sizeof($teampage_entries))
+			{
+				$this->db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries);
+			}
+			unset($teampage_entries);
+		}
+
+	}
+}
-- 
cgit v1.2.1


From 19c3917de985d04f994bc22bcec1e814aa2e207c Mon Sep 17 00:00:00 2001
From: Joas Schilling <nickvergessen@gmx.de>
Date: Fri, 1 Mar 2013 12:46:55 +0100
Subject: [ticket/10411] Fix call to function on non-object $db->...()

PHPBB3-10411
---
 phpBB/includes/db/migration/data/310/teampage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'phpBB/includes/db')

diff --git a/phpBB/includes/db/migration/data/310/teampage.php b/phpBB/includes/db/migration/data/310/teampage.php
index 510ecf9481..4e77da17b7 100644
--- a/phpBB/includes/db/migration/data/310/teampage.php
+++ b/phpBB/includes/db/migration/data/310/teampage.php
@@ -82,7 +82,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration
 			$result = $this->db->sql_query($sql);
 
 			$teampage_entries = array();
-			while ($row = $db->sql_fetchrow($result))
+			while ($row = $this->db->sql_fetchrow($result))
 			{
 				$teampage_entries[] = array(
 					'group_id'			=> (int) $row['group_id'],
@@ -91,7 +91,7 @@ class phpbb_db_migration_data_310_teampage extends phpbb_db_migration
 					'teampage_parent'	=> 0,
 				);
 			}
-			$db->sql_freeresult($result);
+			$this->db->sql_freeresult($result);
 
 			if (sizeof($teampage_entries))
 			{
-- 
cgit v1.2.1


From c7ca4e445c7dc6c775e27597cd7b0968fa5fd904 Mon Sep 17 00:00:00 2001
From: Marc Alexander <admin@m-a-styles.de>
Date: Mon, 4 Mar 2013 01:04:36 +0100
Subject: [feature/avatars] Add migrations data file for avatars

The module_auth of the ucp avatar settings are used for checking if the
migration has already been installed.

PHPBB3-10018
---
 phpBB/includes/db/migration/data/310/avatars.php | 64 ++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 phpBB/includes/db/migration/data/310/avatars.php

(limited to 'phpBB/includes/db')

diff --git a/phpBB/includes/db/migration/data/310/avatars.php b/phpBB/includes/db/migration/data/310/avatars.php
new file mode 100644
index 0000000000..de11a64556
--- /dev/null
+++ b/phpBB/includes/db/migration/data/310/avatars.php
@@ -0,0 +1,64 @@
+<?php
+/**
+*
+* @package migration
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
+*
+*/
+
+class phpbb_db_migration_data_310_avatars extends phpbb_db_migration
+{
+	public function effectively_installed()
+	{
+		$sql = 'SELECT module_auth
+				FROM ' . MODULES_TABLE . "
+				WHERE module_class = 'ucp'
+					AND module_basename = 'ucp_profile'
+					AND module_mode = 'avatar'";
+		$result = $this->db->sql_query($sql);
+		$module_auth = $this->db->sql_fetchfield('module_auth');
+		$this->db->sql_freeresult($result);
+		return ($module_auth == 'cfg_allow_avatar');
+	}
+
+	static public function depends_on()
+	{
+		return array('phpbb_db_migration_data_30x_3_0_11');
+	}
+
+	public function update_schema()
+	{
+		return array(
+			'change_columns'	=> array(
+				$this->table_prefix . 'users'			=> array(
+					'user_avatar_type'		=> array('VCHAR:255', ''),
+				),
+				$this->table_prefix . 'groups'			=> array(
+					'group_avatar_type'		=> array('VCHAR:255', ''),
+				),
+			),
+		);
+	}
+
+	public function revert_schema()
+	{
+		return array(
+			'change_columns'	=> array(
+				$this->table_prefix . 'users'			=> array(
+					'user_avatar_type'		=> array('TINT:2', ''),
+				),
+				$this->table_prefix . 'groups'			=> array(
+					'group_avatar_type'		=> array('TINT:2', ''),
+				),
+			),
+		);
+	}
+
+	public function update_data()
+	{
+		return array(
+			array('config.add', array('allow_avatar_gravatar', 0)),
+		);
+	}
+}
-- 
cgit v1.2.1


From ae15fabb323c8f76ad2c8c994c2d205aabeafcbe Mon Sep 17 00:00:00 2001
From: Nathaniel Guse <nathaniel.guse@gmail.com>
Date: Sun, 3 Mar 2013 20:59:21 -0600
Subject: [ticket/11396] Rename insert_migration to set_migration_state

PHPBB3-11396
---
 phpBB/includes/db/migrator.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'phpBB/includes/db')

diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php
index de9c06948c..7b5e8cb2de 100644
--- a/phpBB/includes/db/migrator.php
+++ b/phpBB/includes/db/migrator.php
@@ -174,7 +174,7 @@ class phpbb_db_migrator
 					'migration_start_time'	=> time(),
 					'migration_end_time'	=> time(),
 				);
-				$this->insert_migration($name, $state);
+				$this->set_migration_state($name, $state);
 			}
 		}
 
@@ -350,7 +350,7 @@ class phpbb_db_migrator
 			}
 		}
 
-		$this->insert_migration($name, $state);
+		$this->set_migration_state($name, $state);
 
 		return true;
 	}
@@ -422,7 +422,7 @@ class phpbb_db_migrator
 				$state['migration_data_done'] = ($result === true) ? false : true;
 			}
 
-			$this->insert_migration($name, $state);
+			$this->set_migration_state($name, $state);
 		}
 		else
 		{
@@ -641,7 +641,7 @@ class phpbb_db_migrator
 	* @param array $state
 	* @return null
 	*/
-	protected function insert_migration($name, $state)
+	protected function set_migration_state($name, $state)
 	{
 		$migration_row = $state;
 		$migration_row['migration_depends_on'] = serialize($state['migration_depends_on']);
-- 
cgit v1.2.1


From 2e2ddd7e85034f747d5dd312803aadfc47ac80e2 Mon Sep 17 00:00:00 2001
From: Marc Alexander <admin@m-a-styles.de>
Date: Mon, 4 Mar 2013 10:30:49 +0100
Subject: [feature/avatars] Update module_auth of ucp module and fix small
 issues

Reduced the check effectively_installed() to just checking for the config
entry "allow_avatar_gravatar". Also added the missing update of the
module_auth of the ucp_profile avatar mode.

PHPBB3-10018
---
 phpBB/includes/db/migration/data/310/avatars.php | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

(limited to 'phpBB/includes/db')

diff --git a/phpBB/includes/db/migration/data/310/avatars.php b/phpBB/includes/db/migration/data/310/avatars.php
index de11a64556..79547337f7 100644
--- a/phpBB/includes/db/migration/data/310/avatars.php
+++ b/phpBB/includes/db/migration/data/310/avatars.php
@@ -11,15 +11,7 @@ class phpbb_db_migration_data_310_avatars extends phpbb_db_migration
 {
 	public function effectively_installed()
 	{
-		$sql = 'SELECT module_auth
-				FROM ' . MODULES_TABLE . "
-				WHERE module_class = 'ucp'
-					AND module_basename = 'ucp_profile'
-					AND module_mode = 'avatar'";
-		$result = $this->db->sql_query($sql);
-		$module_auth = $this->db->sql_fetchfield('module_auth');
-		$this->db->sql_freeresult($result);
-		return ($module_auth == 'cfg_allow_avatar');
+		return isset($this->config['allow_avatar_gravatar']);
 	}
 
 	static public function depends_on()
@@ -59,6 +51,17 @@ class phpbb_db_migration_data_310_avatars extends phpbb_db_migration
 	{
 		return array(
 			array('config.add', array('allow_avatar_gravatar', 0)),
+			array('custom', array(array($this, 'update_module_auth'))),
 		);
 	}
+
+	public function update_module_auth()
+	{
+		$sql = 'UPDATE ' . $this->table_prefix . "modules
+			SET module_auth = 'cfg_allow_avatar'
+			WHERE module_class = 'ucp'
+				AND module_basename = 'ucp_profile'
+				AND module_mode = 'avatar'";
+		$this->db->sql_query($sql);
+	}
 }
-- 
cgit v1.2.1