From a9cf558af7fc08539e15ceca1e889e087c815c8d Mon Sep 17 00:00:00 2001 From: Sajaki Date: Sat, 28 Apr 2012 10:43:43 +0200 Subject: [ticket/10854] sql server drop default constraint when dropping column drops default columns with T-SQL before attempting drop column to avoids sql exception. This is a huge annoyance in UMIL scripts running under sql server. --- phpBB/includes/db/db_tools.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index c6dd23e6bd..f63ff18cbe 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -1819,6 +1819,22 @@ class phpbb_db_tools case 'mssql': case 'mssqlnative': + // remove default cosntraints first + // http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx + $statements[] = "DECLARE @drop_default_name VARCHAR(100), @cmd VARCHAR(1000) + SET @drop_default_name = + (SELECT so.name FROM sysobjects so + JOIN sysconstraints sc ON so.id = sc.constid + WHERE object_name(so.parent_obj) = '{$table_name}' + AND so.xtype = 'D' + AND sc.colid = (SELECT colid FROM syscolumns + WHERE id = object_id('{$table_name}') + AND name = '{$column_name}')) + IF @drop_default_name <> '' + BEGIN + SET @cmd = 'ALTER TABLE [{$table_name}] DROP CONSTRAINT [' + @drop_default_name + ']' + EXEC(@cmd) + END"; $statements[] = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']'; break; -- cgit v1.2.1 From 83a71a2e777dcc9d1c717b6bf438b9aaf41dffba Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sun, 2 Dec 2012 23:01:29 +0000 Subject: [ticket/11171] Use the options stored to decide how to show it Added what's needed so that the post in the report is parsed the same way as it was being parsed when the post was reported PHPBB3-11171 --- phpBB/includes/mcp/mcp_reports.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 3426d62cdb..ca730f7728 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -71,7 +71,7 @@ class mcp_reports // closed reports are accessed by report id $report_id = request_var('r', 0); - $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour + $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, r.reported_post_enable_magic_url, r.reported_post_enable_smilies, r.reported_post_enable_bbcode, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . ' AND rr.reason_id = r.reason_id @@ -94,6 +94,10 @@ class mcp_reports $post_id = $report['post_id']; $report_id = $report['report_id']; + + $parse_post_flags = $report['reported_post_enable_bbcode'] ? OPTION_FLAG_BBCODE : 0; + $parse_post_flags += $report['reported_post_enable_smilies'] ? OPTION_FLAG_SMILIES : 0; + $parse_post_flags += $report['reported_post_enable_magic_url'] ? OPTION_FLAG_LINKS : 0; $post_info = get_post_data(array($post_id), 'm_report', true); @@ -227,7 +231,7 @@ class mcp_reports 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']), 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']), - 'POST_PREVIEW' => generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES, false), + 'POST_PREVIEW' => generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], $parse_post_flags, false), 'POST_SUBJECT' => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], -- cgit v1.2.1 From 73971ef0fa2a53b056847a524bb84f8b2d3e5a4b Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sun, 2 Dec 2012 23:19:59 +0000 Subject: [ticket/11171] Cleanup of leftovers I didn't notice that there were actually leftovers from the other PR. Anyway, this will remove all the leftovers I noticed from the other PR. PHPBB3-11171 --- phpBB/includes/mcp/mcp_reports.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index ca730f7728..8da303f6e3 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -140,18 +140,7 @@ class mcp_reports $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false; - // Process message, leave it uncensored - $message = $post_info['post_text']; - if ($post_info['bbcode_bitfield']) - { - include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); - $bbcode = new bbcode($post_info['bbcode_bitfield']); - $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']); - } - - $message = bbcode_nl2br($message); - $message = smiley_text($message); $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text'])); if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) @@ -172,7 +161,7 @@ class mcp_reports if (sizeof($attachments)) { $update_count = array(); - parse_attachments($post_info['forum_id'], $message, $attachments, $update_count); + parse_attachments($post_info['forum_id'], $report['reported_post_text'], $attachments, $update_count); } // Display not already displayed Attachments for this post, we already parsed them. ;) -- cgit v1.2.1 From f817e20f287a21e2dddfba9721f5e02dce162d29 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Jul 2011 11:57:53 -0400 Subject: [feature/migrations] Basic migrations with schema and data changes The migrator takes care of applying migrations as necessary. RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337 PHPBB3-9737 --- phpBB/includes/constants.php | 1 + phpBB/includes/db/migration.php | 79 ++++++++++++++ phpBB/includes/db/migrator.php | 227 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 phpBB/includes/db/migration.php create mode 100644 phpBB/includes/db/migrator.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..68c96a2759 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -237,6 +237,7 @@ define('ICONS_TABLE', $table_prefix . 'icons'); define('LANG_TABLE', $table_prefix . 'lang'); define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); +define('MIGRATIONS_TABLE', $table_prefix . 'migrations'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php new file mode 100644 index 0000000000..f96fcb9568 --- /dev/null +++ b/phpBB/includes/db/migration.php @@ -0,0 +1,79 @@ +db = &$db; + $this->db_tools = &$db_tools; + } + + /** + * Defines other migrationsto be applied first (abstract method) + * + * @return array An array of migration class names + */ + function depends_on() + { + return array(); + } + + /** + * Updates the database schema + * + * @return null + */ + function update_schema() + { + } + + /** + * Updates data + * + * @return null + */ + function update_data() + { + } + + /** + * Adds a column to a database table + */ + function db_column_add($table_name, $column_name, $column_data) + { + $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + } +} diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php new file mode 100644 index 0000000000..d5d938ca28 --- /dev/null +++ b/phpBB/includes/db/migrator.php @@ -0,0 +1,227 @@ +db = &$db; + $this->db_tools = &$db_tools; + $this->migrations_table = $migrations_table; + $this->migrations = array(); + + $this->load_migration_state(); + } + + /** + * Loads all migrations and their application state from the database. + * + * @return null + */ + function load_migration_state() + { + $sql = "SELECT * + FROM " . $this->migrations_table; + $result = $this->db->sql_query($sql); + + $this->migration_state = array(); + while ($migration = $this->db->sql_fetchrow($result)) + { + $this->migration_state[$migration['migration_name']] = $migration; + } + + $this->db->sql_freeresult($result); + } + + /** + * Sets the list of available migration class names to the given array. + * + * @param array $class_names An array of migration class names + * @return null + */ + function set_migrations($class_names) + { + $this->migrations = $class_names; + } + + /** + * Runs a single update step from the next migration to be applied. + * + * The update step can either be a schema or a (partial) data update. To + * check if update() needs to be called again use the finished() method. + * + * @return null + */ + function update() + { + foreach ($this->migrations as $name) + { + if (!isset($this->migration_state[$name]) || + !$this->migration_state[$name]['migration_schema_done'] || + !$this->migration_state[$name]['migration_data_done']) + { + if (!$this->try_apply($name)) + { + continue; + } + else + { + return; + } + } + } + } + + /** + * Attempts to apply a step of the given migration or one of its dependencies + * + * @param string The class name of the migration + * @return bool Whether any update step was successfully run + */ + function try_apply($name) + { + if (!class_exists($name)) + { + return false; + } + + $migration =& new $name($this->db, $this->db_tools); + $state = (isset($this->migration_state[$name])) ? + $this->migration_state[$name] : + array( + 'migration_schema_done' => false, + 'migration_data_done' => false, + 'migration_data_state' => '', + ); + + $depends = $migration->depends_on(); + + foreach ($depends as $depend) + { + if (!isset($this->migration_state[$depend]) || + !$this->migration_state[$depend]['migration_schema_done'] || + !$this->migration_state[$depend]['migration_data_done']) + { + return $this->try_apply($depend); + } + } + + if (!$state['migration_schema_done']) + { + $migration->update_schema(); + $state['migration_schema_done'] = true; + } + else + { + $migration->update_data(); + $state['migration_data_done'] = true; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + + return true; + } + + /** + * Checks if a migration's dependencies can even theoretically be satisfied. + * + * @param string $name The class name of the migration + * @return bool Whether the migration cannot be fulfilled + */ + function unfulfillable($name) + { + if (isset($this->migration_state[$name])) + { + return false; + } + + if (!class_exists($name)) + { + return true; + } + + $migration =& new $name($this->db, $this->db_tools); + $depends = $migration->depends_on(); + + foreach ($depends as $depend) + { + if ($this->unfulfillable($depend)) + { + return true; + } + } + + return false; + } + + /** + * Checks whether all available, fulfillable migrations have been applied. + * + * @return bool Whether the migrations have been applied + */ + function finished() + { + foreach ($this->migrations as $name) + { + if (!isset($this->migration_state[$name])) + { + // skip unfulfillable migrations, but fulfillables mean we + // are not finished yet + if ($this->unfulfillable($name)) + { + continue; + } + return false; + } + + $migration = $this->migration_state[$name]; + + if (!$migration['migration_schema_done'] || !$migration['migration_data_done']) + { + return false; + } + } + + return true; + } +} -- cgit v1.2.1 From d304b6449db6e7c6f3c9058062aca0c641f023a4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 7 Aug 2011 19:10:38 -0400 Subject: [feature/migrations] Store start and end time of migrations PHPBB3-9737 --- phpBB/includes/db/migrator.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index d5d938ca28..f4613e3aec 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -127,6 +127,8 @@ class phpbb_db_migrator 'migration_schema_done' => false, 'migration_data_done' => false, 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, ); $depends = $migration->depends_on(); @@ -141,6 +143,12 @@ class phpbb_db_migrator } } + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } + if (!$state['migration_schema_done']) { $migration->update_schema(); @@ -150,6 +158,7 @@ class phpbb_db_migrator { $migration->update_data(); $state['migration_data_done'] = true; + $state['migration_end_time'] = time(); } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -162,6 +171,18 @@ class phpbb_db_migrator return true; } + function insert_migration($name, $state) + { + $migration_row = $state; + $migration_row['migration_name'] = $name; + + $sql = 'INSERT INTO ' . $this->migrations_table . ' + ' . $this->db->sql_build_array('INSERT', $migration_row); + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + } + /** * Checks if a migration's dependencies can even theoretically be satisfied. * -- cgit v1.2.1 From 8645321f40d0b13de6201688c69f9f05bc649dcf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 12:26:44 -0700 Subject: [feature/migrations] Return schema changes in database update style array Returning the set of schema changes allows potentially aggregating to generate the overall install schema automatically from a set of migrations PHPBB3-9737 --- phpBB/includes/db/migration.php | 5 +++-- phpBB/includes/db/migrator.php | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index f96fcb9568..ee916aedc0 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -52,12 +52,13 @@ class phpbb_db_migration } /** - * Updates the database schema + * Updates the database schema by providing a set of change instructions * - * @return null + * @return array */ function update_schema() { + return array(); } /** diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index f4613e3aec..4a178af468 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -151,7 +151,7 @@ class phpbb_db_migrator if (!$state['migration_schema_done']) { - $migration->update_schema(); + $this->apply_schema_changes($migration->update_schema()); $state['migration_schema_done'] = true; } else @@ -245,4 +245,9 @@ class phpbb_db_migrator return true; } + + function apply_schema_changes($schema_changes) + { + $this->db_tools->perform_schema_changes($schema_changes); + } } -- cgit v1.2.1 From c802f2a66c577781036b7bfd6d6689159028c3a6 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 13:02:56 -0700 Subject: [feature/migrations] Standard vars for migrations and run sql with feedback PHPBB3-9737 --- phpBB/includes/db/migration.php | 52 +++++++++++++++++++++++++++++++++++++---- phpBB/includes/db/migrator.php | 17 +++++++++++--- 2 files changed, 62 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index ee916aedc0..09d4e31344 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -28,17 +28,32 @@ class phpbb_db_migration { var $db; var $db_tools; + var $table_prefix; + + var $phpbb_root_path; + var $php_ext; + + var $errors; /** * Migration constructor * * @param dbal $db Connected database abstraction instance * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools + * @param string $table_prefix The prefix for all table names + * @param string $phpbb_root_path + * @param string $php_ext */ - function phpbb_db_migration(&$db, &$db_tools) + function phpbb_db_migration(&$db, &$db_tools, $table_prefix, $phpbb_root_path, $php_ext) { $this->db = &$db; $this->db_tools = &$db_tools; + $this->table_prefix = $table_prefix; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->errors = array(); } /** @@ -71,10 +86,39 @@ class phpbb_db_migration } /** - * Adds a column to a database table + * Wrapper for running queries to generate user feedback on updates */ - function db_column_add($table_name, $column_name, $column_data) + function sql_query($sql) { - $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + if (defined('DEBUG_EXTRA')) + { + echo "
\n{$sql}\n
"; + } + + $db->sql_return_on_error(true); + + if ($sql === 'begin') + { + $result = $db->sql_transaction('begin'); + } + else if ($sql === 'commit') + { + $result = $db->sql_transaction('commit'); + } + else + { + $result = $db->sql_query($sql); + if ($db->sql_error_triggered) + { + $this->errors[] = array( + 'sql' => $db->sql_error_sql, + 'code' => $db->sql_error_returned, + ); + } + } + + $db->sql_return_on_error(false); + + return $result; } } diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4a178af468..4ce54a4b92 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -24,6 +24,10 @@ class phpbb_db_migrator { var $db; var $db_tools; + var $table_prefix; + + var $phpbb_root_path; + var $php_ext; var $migrations_table; var $migration_state; @@ -35,16 +39,23 @@ class phpbb_db_migrator * * @param dbal $db Connected database abstraction instance * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools + * @param string $table_prefix The prefix for all table names * @param string $migrations_table The name of the db table storing * information on applied migrations + * @param string $phpbb_root_path + * @param string $php_ext */ - function phpbb_db_migrator(&$db, &$db_tools, $migrations_table) + function phpbb_db_migrator(&$db, &$db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { $this->db = &$db; $this->db_tools = &$db_tools; + $this->table_prefix = $table_prefix; $this->migrations_table = $migrations_table; $this->migrations = array(); + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->load_migration_state(); } @@ -120,7 +131,7 @@ class phpbb_db_migrator return false; } - $migration =& new $name($this->db, $this->db_tools); + $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -201,7 +212,7 @@ class phpbb_db_migrator return true; } - $migration =& new $name($this->db, $this->db_tools); + $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $depends = $migration->depends_on(); foreach ($depends as $depend) -- cgit v1.2.1 From b1f9ca2f6541924c75a30c68dd8a4bc8db62205d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 9 Nov 2012 17:10:48 +0100 Subject: [feature/migrations] Moved database_update info to individual migration classes --- phpBB/includes/db/migration.php | 2 +- phpBB/includes/db/migration/v301.php | 25 +++ phpBB/includes/db/migration/v3010.php | 25 +++ phpBB/includes/db/migration/v3010rc1.php | 29 +++ phpBB/includes/db/migration/v3010rc2.php | 25 +++ phpBB/includes/db/migration/v3010rc3.php | 25 +++ phpBB/includes/db/migration/v3011.php | 25 +++ phpBB/includes/db/migration/v3011rc1.php | 83 ++++++++ phpBB/includes/db/migration/v3011rc2.php | 31 +++ phpBB/includes/db/migration/v3012rc1.php | 26 +++ phpBB/includes/db/migration/v301rc1.php | 77 +++++++ phpBB/includes/db/migration/v302.php | 25 +++ phpBB/includes/db/migration/v302rc1.php | 30 +++ phpBB/includes/db/migration/v302rc2.php | 52 +++++ phpBB/includes/db/migration/v303.php | 25 +++ phpBB/includes/db/migration/v303rc1.php | 135 ++++++++++++ phpBB/includes/db/migration/v304.php | 40 ++++ phpBB/includes/db/migration/v304rc1.php | 96 +++++++++ phpBB/includes/db/migration/v305.php | 25 +++ phpBB/includes/db/migration/v305rc1.php | 146 +++++++++++++ phpBB/includes/db/migration/v306.php | 25 +++ phpBB/includes/db/migration/v306rc1.php | 350 +++++++++++++++++++++++++++++++ phpBB/includes/db/migration/v306rc2.php | 25 +++ phpBB/includes/db/migration/v306rc3.php | 31 +++ phpBB/includes/db/migration/v306rc4.php | 25 +++ phpBB/includes/db/migration/v307.php | 25 +++ phpBB/includes/db/migration/v307pl1.php | 25 +++ phpBB/includes/db/migration/v307rc1.php | 46 ++++ phpBB/includes/db/migration/v307rc2.php | 53 +++++ phpBB/includes/db/migration/v308.php | 25 +++ phpBB/includes/db/migration/v308rc1.php | 222 ++++++++++++++++++++ phpBB/includes/db/migration/v309.php | 25 +++ phpBB/includes/db/migration/v309rc1.php | 100 +++++++++ phpBB/includes/db/migration/v309rc2.php | 25 +++ phpBB/includes/db/migration/v309rc3.php | 25 +++ phpBB/includes/db/migration/v309rc4.php | 25 +++ 36 files changed, 1998 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/db/migration/v301.php create mode 100644 phpBB/includes/db/migration/v3010.php create mode 100644 phpBB/includes/db/migration/v3010rc1.php create mode 100644 phpBB/includes/db/migration/v3010rc2.php create mode 100644 phpBB/includes/db/migration/v3010rc3.php create mode 100644 phpBB/includes/db/migration/v3011.php create mode 100644 phpBB/includes/db/migration/v3011rc1.php create mode 100644 phpBB/includes/db/migration/v3011rc2.php create mode 100644 phpBB/includes/db/migration/v3012rc1.php create mode 100644 phpBB/includes/db/migration/v301rc1.php create mode 100644 phpBB/includes/db/migration/v302.php create mode 100644 phpBB/includes/db/migration/v302rc1.php create mode 100644 phpBB/includes/db/migration/v302rc2.php create mode 100644 phpBB/includes/db/migration/v303.php create mode 100644 phpBB/includes/db/migration/v303rc1.php create mode 100644 phpBB/includes/db/migration/v304.php create mode 100644 phpBB/includes/db/migration/v304rc1.php create mode 100644 phpBB/includes/db/migration/v305.php create mode 100644 phpBB/includes/db/migration/v305rc1.php create mode 100644 phpBB/includes/db/migration/v306.php create mode 100644 phpBB/includes/db/migration/v306rc1.php create mode 100644 phpBB/includes/db/migration/v306rc2.php create mode 100644 phpBB/includes/db/migration/v306rc3.php create mode 100644 phpBB/includes/db/migration/v306rc4.php create mode 100644 phpBB/includes/db/migration/v307.php create mode 100644 phpBB/includes/db/migration/v307pl1.php create mode 100644 phpBB/includes/db/migration/v307rc1.php create mode 100644 phpBB/includes/db/migration/v307rc2.php create mode 100644 phpBB/includes/db/migration/v308.php create mode 100644 phpBB/includes/db/migration/v308rc1.php create mode 100644 phpBB/includes/db/migration/v309.php create mode 100644 phpBB/includes/db/migration/v309rc1.php create mode 100644 phpBB/includes/db/migration/v309rc2.php create mode 100644 phpBB/includes/db/migration/v309rc3.php create mode 100644 phpBB/includes/db/migration/v309rc4.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index 09d4e31344..aca9d264bb 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -3,7 +3,7 @@ * * @package db * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 * */ diff --git a/phpBB/includes/db/migration/v301.php b/phpBB/includes/db/migration/v301.php new file mode 100644 index 0000000000..8a2a265a3c --- /dev/null +++ b/phpBB/includes/db/migration/v301.php @@ -0,0 +1,25 @@ +sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $config['default_style'] .' + WHERE ' . $db->sql_in_set('user_style', $deactivated_style_ids); + _sql($sql, $errored, $error_ary); + } + + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $db->sql_build_query('SELECT', $sql_array); + + do + { + $result = $db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $db->sql_in_set('msg_id', $delete_pms); + _sql($sql, $errored, $error_ary); + } + } + while (sizeof($delete_pms) == $batch_size); + } +} diff --git a/phpBB/includes/db/migration/v3011rc2.php b/phpBB/includes/db/migration/v3011rc2.php new file mode 100644 index 0000000000..0f66eff156 --- /dev/null +++ b/phpBB/includes/db/migration/v3011rc2.php @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/v3012rc1.php b/phpBB/includes/db/migration/v3012rc1.php new file mode 100644 index 0000000000..67f7a29b02 --- /dev/null +++ b/phpBB/includes/db/migration/v3012rc1.php @@ -0,0 +1,26 @@ + array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array('group_legend'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + ); + } + + function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/v302.php b/phpBB/includes/db/migration/v302.php new file mode 100644 index 0000000000..942a0ac58c --- /dev/null +++ b/phpBB/includes/db/migration/v302.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/v303.php b/phpBB/includes/db/migration/v303.php new file mode 100644 index 0000000000..409c396baf --- /dev/null +++ b/phpBB/includes/db/migration/v303.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array('set_group_default_max_recipients')) + + // Not prefilling yet + set_config('dbms_version', ''); + + // Add new permission u_masspm_group and duplicate settings from u_masspm + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + $auth_admin = new auth_admin(); + + // Only add the new permission if it does not already exist + if (empty($auth_admin->acl_options['id']['u_masspm_group'])) + { + $auth_admin->acl_add_option(array('global' => array('u_masspm_group'))); + + // Now the tricky part, filling the permission + $old_id = $auth_admin->acl_options['id']['u_masspm']; + $new_id = $auth_admin->acl_options['id']['u_masspm_group']; + + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); + + foreach ($tables as $table) + { + $sql = 'SELECT * + FROM ' . $table . ' + WHERE auth_option_id = ' . $old_id; + $result = _sql($sql, $errored, $error_ary); + + $sql_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $row['auth_option_id'] = $new_id; + $sql_ary[] = $row; + } + $db->sql_freeresult($result); + + if (sizeof($sql_ary)) + { + $db->sql_multi_insert($table, $sql_ary); + } + } + + // Remove any old permission entries + $auth_admin->acl_clear_prefetch(); + } + + /** + * Do not resync post counts here. An admin may do this later from the ACP + $start = 0; + $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000; + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0'; + _sql($sql, $errored, $error_ary); + + do + { + $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id + FROM ' . POSTS_TABLE . ' + WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' + AND post_postcount = 1 AND post_approved = 1 + GROUP BY poster_id'; + $result = _sql($sql, $errored, $error_ary); + + if ($row = $db->sql_fetchrow($result)) + { + do + { + $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}"; + _sql($sql, $errored, $error_ary); + } + while ($row = $db->sql_fetchrow($result)); + + $start += $step; + } + else + { + $start = 0; + } + $db->sql_freeresult($result); + } + while ($start); + */ + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + _sql($sql, $errored, $error_ary); + } + + function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } + +} diff --git a/phpBB/includes/db/migration/v304.php b/phpBB/includes/db/migration/v304.php new file mode 100644 index 0000000000..2895caaa6d --- /dev/null +++ b/phpBB/includes/db/migration/v304.php @@ -0,0 +1,40 @@ +sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . LOG_TABLE . " + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + _sql($sql, $errored, $error_ary); + } + else + { + $sql = 'UPDATE ' . LOG_TABLE . " + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + _sql($sql, $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/v304rc1.php b/phpBB/includes/db/migration/v304rc1.php new file mode 100644 index 0000000000..a7098ce62f --- /dev/null +++ b/phpBB/includes/db/migration/v304rc1.php @@ -0,0 +1,96 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = _sql($sql, $errored, $error_ary); + + while ($row = $db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/v305.php b/phpBB/includes/db/migration/v305.php new file mode 100644 index 0000000000..b4d676d72a --- /dev/null +++ b/phpBB/includes/db/migration/v305.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + // Captcha config variables + set_config('captcha_gd_wave', 0); + set_config('captcha_gd_3d_noise', 1); + set_config('captcha_gd_fonts', 1); + set_config('confirm_refresh', 1); + + // Maximum number of keywords + set_config('max_num_search_keywords', 10); + + // Remove static config var and put it back as dynamic variable + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET is_dynamic = 1 + WHERE config_name = 'search_indexing_state'"; + _sql($sql, $errored, $error_ary); + + // Hash old MD5 passwords + $sql = 'SELECT user_id, user_password + FROM ' . USERS_TABLE . ' + WHERE user_pass_convert = 1'; + $result = _sql($sql, $errored, $error_ary); + + while ($row = $db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary); + } + } + $db->sql_freeresult($result); + + // Adjust bot entry + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + _sql($sql, $errored, $error_ary); + + + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + + // We get duplicate entries first + $sql = 'SELECT auth_option + FROM ' . ACL_OPTIONS_TABLE . ' + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $db->sql_query($sql); + + $auth_options = array(); + while ($row = $db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $db->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $db->sql_fetchrow($result); + + while ($row = $db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + } + $db->sql_freeresult($result); + } + } + + // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one. + $changes = array( + 'drop_keys' => array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + ); + + global $db_tools; + + $statements = $db_tools->perform_schema_changes($changes); + + foreach ($statements as $sql) + { + _sql($sql, $errored, $error_ary); + } + + $changes = array( + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + + $statements = $db_tools->perform_schema_changes($changes); + + foreach ($statements as $sql) + { + _sql($sql, $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/v306.php b/phpBB/includes/db/migration/v306.php new file mode 100644 index 0000000000..eec2f7c752 --- /dev/null +++ b/phpBB/includes/db/migration/v306.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + function update_data() + { + // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled... + if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin'])) + { + set_config('captcha_plugin', 'phpbb_captcha_gd'); + } + else if (!isset($config['captcha_plugin'])) + { + set_config('captcha_plugin', 'phpbb_captcha_nogd'); + } + + // Entries for the Feed Feature + set_config('feed_enable', '0'); + set_config('feed_limit', '10'); + + set_config('feed_overall_forums', '1'); + set_config('feed_overall_forums_limit', '15'); + + set_config('feed_overall_topics', '0'); + set_config('feed_overall_topics_limit', '15'); + + set_config('feed_forum', '1'); + set_config('feed_topic', '1'); + set_config('feed_item_statistics', '1'); + + // Entries for smiley pagination + set_config('smilies_per_page', '50'); + + // Entry for reporting PMs + set_config('allow_pm_report', '1'); + + // Install modules + $modules_to_install = array( + 'feed' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_FEED_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_BOARD_CONFIGURATION', + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') + ), + 'warnings' => array( + 'base' => 'users', + 'class' => 'acp', + 'title' => 'ACP_USER_WARNINGS', + 'auth' => 'acl_a_user', + 'display' => 0, + 'cat' => 'ACP_CAT_USERS', + 'after' => array('feedback', 'ACP_USER_FEEDBACK') + ), + 'send_statistics' => array( + 'base' => 'send_statistics', + 'class' => 'acp', + 'title' => 'ACP_SEND_STATISTICS', + 'auth' => 'acl_a_server', + 'cat' => 'ACP_SERVER_CONFIGURATION' + ), + 'setting_forum_copy' => array( + 'base' => 'permissions', + 'class' => 'acp', + 'title' => 'ACP_FORUM_PERMISSIONS_COPY', + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') + ), + 'pm_reports' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_OPEN', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + 'pm_reports_closed' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_CLOSED', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + 'pm_report_details' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORT_DETAILS', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + ); + + _add_modules($modules_to_install); + + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $db->sql_query($sql); + $group_id = (int) $db->sql_fetchfield('group_id'); + $db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + _sql($sql, $errored, $error_ary); + + $group_id = $db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $db->sql_query($sql); + $u_role = (int) $db->sql_fetchfield('role_id'); + $db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $db->sql_query($sql); + $next_order_id = (int) $db->sql_fetchfield('max_order_id'); + $db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + _sql($sql, $errored, $error_ary); + $u_role = $db->sql_nextid(); + + if (!$errored) + { + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + _sql($sql, $errored, $error_ary); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + _sql($sql, $errored, $error_ary); + } + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $db->sql_query($sql); + $f_role = (int) $db->sql_fetchfield('role_id'); + $db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $db->sql_query($sql); + $next_order_id = (int) $db->sql_fetchfield('max_order_id'); + $db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + _sql($sql, $errored, $error_ary); + $f_role = $db->sql_nextid(); + + if (!$errored) + { + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + _sql($sql, $errored, $error_ary); + } + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + _sql($sql, $errored, $error_ary); + } + + // Newly registered users limit + if (!isset($config['new_member_post_limit'])) + { + set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0); + } + + if (!isset($config['new_member_group_default'])) + { + set_config('new_member_group_default', 0); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $db->sql_query($sql); + $is_options = (int) $db->sql_fetchfield('forum_id'); + $db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + _sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary); + } + $db->sql_freeresult($result); + } + + // Clear permissions... + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + + if (!isset($config['allow_avatar'])) + { + if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote']) + { + set_config('allow_avatar', '1'); + } + else + { + set_config('allow_avatar', '0'); + } + } + + if (!isset($config['allow_avatar_remote_upload'])) + { + if ($config['allow_avatar_remote'] && $config['allow_avatar_upload']) + { + set_config('allow_avatar_remote_upload', '1'); + } + else + { + set_config('allow_avatar_remote_upload', '0'); + } + } + + // Minimum number of characters + if (!isset($config['min_post_chars'])) + { + set_config('min_post_chars', '1'); + } + + if (!isset($config['allow_quick_reply'])) + { + set_config('allow_quick_reply', '1'); + } + + // Set every members user_options column to enable + // bbcode, smilies and URLs for signatures by default + $sql = 'SELECT user_options + FROM ' . USERS_TABLE . ' + WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')'; + $result = $db->sql_query_limit($sql, 1); + $user_option = (int) $db->sql_fetchfield('user_options'); + $db->sql_freeresult($result); + + // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option + if (!($user_option & 1 << 15)) + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + _sql($sql, $errored, $error_ary); + } + + if (!isset($config['delete_time'])) + { + set_config('delete_time', $config['edit_time']); + } + } +} diff --git a/phpBB/includes/db/migration/v306rc2.php b/phpBB/includes/db/migration/v306rc2.php new file mode 100644 index 0000000000..0a6c388da6 --- /dev/null +++ b/phpBB/includes/db/migration/v306rc2.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'log' => array('log_time'), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + function update_data() + { + // ATOM Feeds + set_config('feed_overall', '1'); + set_config('feed_http_auth', '0'); + set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15)); + set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10)); + set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0')); + set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0')); + + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt'); + _sql($sql, $errored, $error_ary); + } +} diff --git a/phpBB/includes/db/migration/v307rc2.php b/phpBB/includes/db/migration/v307rc2.php new file mode 100644 index 0000000000..f9492f3d1c --- /dev/null +++ b/phpBB/includes/db/migration/v307rc2.php @@ -0,0 +1,53 @@ + ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $db->sql_query($sql); + + $i = 0; + while ($row = $db->sql_fetchrow($result)) + { + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + _sql($sql, $errored, $error_ary, ($i % 100 == 0)); + + ++$i; + } + } + $db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/v308.php b/phpBB/includes/db/migration/v308.php new file mode 100644 index 0000000000..8a0d96b2e7 --- /dev/null +++ b/phpBB/includes/db/migration/v308.php @@ -0,0 +1,25 @@ +sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx", + "{$phpbb_root_path}language/$lang_dir/install.$phpEx", + "{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $db->sql_escape($lang_val) . "'"; + _sql($sql, $errored, $error_ary); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $db->sql_freeresult($result); + + // Install modules + $modules_to_install = array( + 'post' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_POST_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_MESSAGES', + 'after' => array('message', 'ACP_MESSAGE_SETTINGS') + ), + ); + + _add_modules($modules_to_install); + + // update + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + _sql($sql, $errored, $error_ary); + + // add Bing Bot + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'"; + $result = $db->sql_query($sql); + $bing_already_added = (bool) $db->sql_fetchfield('user_id'); + $db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $db->sql_query($sql); + $group_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $config['default_lang'], + 'user_style' => $config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + _sql($sql, $errored, $error_ary); + } + // end Bing Bot addition + + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + do + { + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $db->sql_build_query('SELECT', $sql_array); + $result = $db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $topic_ids); + $db->sql_query($sql); + } + } + while (sizeof($topic_ids) == $batch_size); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + // Unread posts search load switch + set_config('load_unreads_search', '1'); + + // Reduce queue interval to 60 seconds, email package size to 20 + if ($config['queue_interval'] == 600) + { + set_config('queue_interval', '60'); + } + + if ($config['email_package_size'] == 50) + { + set_config('email_package_size', '20'); + } + } +} diff --git a/phpBB/includes/db/migration/v309.php b/phpBB/includes/db/migration/v309.php new file mode 100644 index 0000000000..ebb246da3a --- /dev/null +++ b/phpBB/includes/db/migration/v309.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcode' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + function update_data() + { + set_config('ip_login_limit_max', '50'); + set_config('ip_login_limit_time', '21600'); + set_config('ip_login_limit_use_forwarded', '0'); + + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + _sql($sql, $errored, $error_ary); + } + $db->sql_freeresult($result); + + global $db_tools, $table_prefix; + + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($db_tools->sql_layer == 'firebird') + { + $tables = array( + $table_prefix . 'captcha_questions', + $table_prefix . 'captcha_answers', + $table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($db_tools->sql_table_exists($table)) + { + $db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/v309rc2.php b/phpBB/includes/db/migration/v309rc2.php new file mode 100644 index 0000000000..d552b95e7a --- /dev/null +++ b/phpBB/includes/db/migration/v309rc2.php @@ -0,0 +1,25 @@ + Date: Fri, 9 Nov 2012 10:54:33 -0600 Subject: [feature/migrations] Some migrations data PHPBB3-9737 --- phpBB/includes/db/migration/v3010rc1.php | 7 ++-- phpBB/includes/db/migration/v3011rc1.php | 57 ++++++++++++++++++++------------ phpBB/includes/db/migration/v309rc1.php | 42 +++++++++++++---------- 3 files changed, 63 insertions(+), 43 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v3010rc1.php b/phpBB/includes/db/migration/v3010rc1.php index 9a43b4c81d..847fe7c250 100644 --- a/phpBB/includes/db/migration/v3010rc1.php +++ b/phpBB/includes/db/migration/v3010rc1.php @@ -21,9 +21,8 @@ class phpbb_db_migration_v3010rc1 extends phpbb_db_migration function update_data() { - if (!isset($config['email_max_chunk_size'])) - { - set_config('email_max_chunk_size', '50'); - } + return array( + array('config.add', array('email_max_chunk_size', 50)), + ); } } diff --git a/phpBB/includes/db/migration/v3011rc1.php b/phpBB/includes/db/migration/v3011rc1.php index 04f86b47ae..aad80ba59f 100644 --- a/phpBB/includes/db/migration/v3011rc1.php +++ b/phpBB/includes/db/migration/v3011rc1.php @@ -20,28 +20,39 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), + array('custom', array(array(&$this, 'delete_orphan_private_messages'))), + ); + } + + function cleanup_deactivated_styles() { // Updates users having current style a deactivated one $sql = 'SELECT style_id FROM ' . STYLES_TABLE . ' WHERE style_active = 0'; - $result = $db->sql_query($sql); + $result = $this->sql_query($sql); $deactivated_style_ids = array(); - while ($style_id = $db->sql_fetchfield('style_id', false, $result)) + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) { $deactivated_style_ids[] = (int) $style_id; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!empty($deactivated_style_ids)) { $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $config['default_style'] .' - WHERE ' . $db->sql_in_set('user_style', $deactivated_style_ids); - _sql($sql, $errored, $error_ary); + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql, $errored, $error_ary); } + } + function delete_orphan_private_messages() + { // Delete orphan private messages $batch_size = 500; @@ -58,26 +69,28 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration ), 'WHERE' => 't.user_id IS NULL', ); - $sql = $db->sql_build_query('SELECT', $sql_array); + $sql = $this->db->sql_build_query('SELECT', $sql_array); - do + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) { - $result = $db->sql_query_limit($sql, $batch_size); + $delete_pms[] = (int) $row['msg_id']; + } + $db->sql_freeresult($result); - $delete_pms = array(); - while ($row = $db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $db->sql_freeresult($result); + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql, $errored, $error_ary); - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $db->sql_in_set('msg_id', $delete_pms); - _sql($sql, $errored, $error_ary); - } + return true; + } + else + { + return false; } - while (sizeof($delete_pms) == $batch_size); } } diff --git a/phpBB/includes/db/migration/v309rc1.php b/phpBB/includes/db/migration/v309rc1.php index ca56a4e7d9..ce51e54642 100644 --- a/phpBB/includes/db/migration/v309rc1.php +++ b/phpBB/includes/db/migration/v309rc1.php @@ -53,46 +53,54 @@ class phpbb_db_migration_v309rc1 extends phpbb_db_migration function update_data() { - set_config('ip_login_limit_max', '50'); - set_config('ip_login_limit_time', '21600'); - set_config('ip_login_limit_use_forwarded', '0'); + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + ); + } + function update_file_extension_group_names() + { // Update file extension group names to use language strings, again. $sql = 'SELECT group_id, group_name FROM ' . EXTENSION_GROUPS_TABLE . ' - WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char); - $result = $db->sql_query($sql); + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $sql_ary = array( 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' ); $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE group_id = ' . $row['group_id']; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql, $errored, $error_ary); } - $db->sql_freeresult($result); - - global $db_tools, $table_prefix; + $this->db->sql_freeresult($result); + } + function fix_firebird_qa_captcha() + { // Recover from potentially broken Q&A CAPTCHA table on firebird // Q&A CAPTCHA was uninstallable, so it's safe to remove these // without data loss - if ($db_tools->sql_layer == 'firebird') + if ($this->db_tools->sql_layer == 'firebird') { $tables = array( - $table_prefix . 'captcha_questions', - $table_prefix . 'captcha_answers', - $table_prefix . 'qa_confirm', + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', ); foreach ($tables as $table) { - if ($db_tools->sql_table_exists($table)) + if ($this->db_tools->sql_table_exists($table)) { - $db_tools->sql_table_drop($table); + $this->db_tools->sql_table_drop($table); } } } -- cgit v1.2.1 From e7389e4c32f031fc6025880adf22b40d7d195f27 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 04:00:38 -0600 Subject: [feature/migrations] 3.0.8-rc1 migration, fix some calls PHPBB3-9737 --- phpBB/includes/db/migration/v3011rc1.php | 4 +- phpBB/includes/db/migration/v308rc1.php | 169 ++++++++++++++++--------------- phpBB/includes/db/migration/v309rc1.php | 2 +- 3 files changed, 89 insertions(+), 86 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v3011rc1.php b/phpBB/includes/db/migration/v3011rc1.php index aad80ba59f..3bae7a4a2d 100644 --- a/phpBB/includes/db/migration/v3011rc1.php +++ b/phpBB/includes/db/migration/v3011rc1.php @@ -47,7 +47,7 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = ' . (int) $this->config['default_style'] .' WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); - $this->sql_query($sql, $errored, $error_ary); + $this->sql_query($sql); } } @@ -84,7 +84,7 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration { $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql, $errored, $error_ary); + $this->sql_query($sql); return true; } diff --git a/phpBB/includes/db/migration/v308rc1.php b/phpBB/includes/db/migration/v308rc1.php index 13d0e98b1c..cbfedb1b53 100644 --- a/phpBB/includes/db/migration/v308rc1.php +++ b/phpBB/includes/db/migration/v308rc1.php @@ -20,14 +20,37 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'update_module_auth'))), + array('custom', array(array(&$this, 'update_bots'))), + array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))), + array('module.add', array( + 'post' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_POST_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_MESSAGES', + 'after' => array('message', 'ACP_MESSAGE_SETTINGS') + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if', array(600, 'queue_interval', 60)), + array('config.update_if', array(50, 'email_package_size', 20)), + ); + } + + function update_file_extension_group_names() { // Update file extension group names to use language strings. $sql = 'SELECT lang_dir FROM ' . LANG_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $extension_groups_updated = array(); - while ($lang_dir = $db->sql_fetchfield('lang_dir')) + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) { $lang_dir = basename($lang_dir); @@ -37,9 +60,9 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration // On an already updated board, they can also already be in language/.../acp/attachments.php // in the board root. $lang_files = array( - "{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx", - "{$phpbb_root_path}language/$lang_dir/install.$phpEx", - "{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx", + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", ); foreach ($lang_files as $lang_file) @@ -64,48 +87,38 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration ); $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $db->sql_escape($lang_val) . "'"; - _sql($sql, $errored, $error_ary); + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); $extension_groups_updated[$lang_key] = true; } } } - $db->sql_freeresult($result); - - // Install modules - $modules_to_install = array( - 'post' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_POST_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_MESSAGES', - 'after' => array('message', 'ACP_MESSAGE_SETTINGS') - ), - ); - - _add_modules($modules_to_install); + $this->db->sql_freeresult($result); + } - // update + function update_module_auth() + { $sql = 'UPDATE ' . MODULES_TABLE . ' SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' WHERE module_class = \'ucp\' AND module_basename = \'profile\' AND module_mode = \'avatar\''; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); + } - // add Bing Bot + function update_bots() + { $bot_name = 'Bing [Bot]'; $bot_name_clean = utf8_clean_string($bot_name); $sql = 'SELECT user_id FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'"; - $result = $db->sql_query($sql); - $bing_already_added = (bool) $db->sql_fetchfield('user_id'); - $db->sql_freeresult($result); + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); if (!$bing_already_added) { @@ -114,9 +127,9 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration $sql = 'SELECT group_id, group_colour FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'"; - $result = $db->sql_query($sql); - $group_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (!$group_row) { @@ -127,7 +140,7 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration if (!function_exists('user_add')) { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); } $user_row = array( @@ -138,16 +151,16 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration 'user_password' => '', 'user_colour' => $group_row['group_colour'], 'user_email' => '', - 'user_lang' => $config['default_lang'], - 'user_style' => $config['default_style'], + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], 'user_timezone' => 0, - 'user_dateformat' => $config['default_dateformat'], + 'user_dateformat' => $this->config['default_dateformat'], 'user_allow_massemail' => 0, ); $user_id = user_add($user_row); - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( 'bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, @@ -155,68 +168,58 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration 'bot_ip' => (string) $bot_ip, )); - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } - // end Bing Bot addition + } + function delete_orphan_shadow_topics() + { // Delete shadow topics pointing to not existing topics $batch_size = 500; // Set of affected forums we have to resync $sync_forum_ids = array(); - do - { - $sql_array = array( - 'SELECT' => 't1.topic_id, t1.forum_id', - 'FROM' => array( - TOPICS_TABLE => 't1', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(TOPICS_TABLE => 't2'), - 'ON' => 't1.topic_moved_id = t2.topic_id', - ), + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', ), - 'WHERE' => 't1.topic_moved_id <> 0 - AND t2.topic_id IS NULL', - ); - $sql = $db->sql_build_query('SELECT', $sql_array); - $result = $db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['topic_id']; + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $db->sql_freeresult($result); + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); - } + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; } - while (sizeof($topic_ids) == $batch_size); + $this->db->sql_freeresult($result); - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); - // Unread posts search load switch - set_config('load_unreads_search', '1'); + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); - // Reduce queue interval to 60 seconds, email package size to 20 - if ($config['queue_interval'] == 600) - { - set_config('queue_interval', '60'); + return true; } - - if ($config['email_package_size'] == 50) + else { - set_config('email_package_size', '20'); + return false; } } } diff --git a/phpBB/includes/db/migration/v309rc1.php b/phpBB/includes/db/migration/v309rc1.php index ce51e54642..e8db93c78d 100644 --- a/phpBB/includes/db/migration/v309rc1.php +++ b/phpBB/includes/db/migration/v309rc1.php @@ -79,7 +79,7 @@ class phpbb_db_migration_v309rc1 extends phpbb_db_migration $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql, $errored, $error_ary); + $this->sql_query($sql); } $this->db->sql_freeresult($result); } -- cgit v1.2.1 From 2a7985c26fcf558c30fa316262344307ffc99e9e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 05:59:01 -0600 Subject: [feature/migrations] Migrations back through 3.0.6 PHPBB3-9737 --- phpBB/includes/db/migration/v306rc1.php | 344 ++++++++++++++------------------ phpBB/includes/db/migration/v306rc3.php | 9 +- phpBB/includes/db/migration/v307rc1.php | 23 ++- phpBB/includes/db/migration/v307rc2.php | 29 ++- phpBB/includes/db/migration/v308rc1.php | 4 +- 5 files changed, 201 insertions(+), 208 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v306rc1.php b/phpBB/includes/db/migration/v306rc1.php index 63d1c66c2d..45b597d56b 100644 --- a/phpBB/includes/db/migration/v306rc1.php +++ b/phpBB/includes/db/migration/v306rc1.php @@ -61,109 +61,141 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration function update_data() { - // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled... - if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin'])) - { - set_config('captcha_plugin', 'phpbb_captcha_gd'); - } - else if (!isset($config['captcha_plugin'])) - { - set_config('captcha_plugin', 'phpbb_captcha_nogd'); - } - - // Entries for the Feed Feature - set_config('feed_enable', '0'); - set_config('feed_limit', '10'); - - set_config('feed_overall_forums', '1'); - set_config('feed_overall_forums_limit', '15'); - - set_config('feed_overall_topics', '0'); - set_config('feed_overall_topics_limit', '15'); - - set_config('feed_forum', '1'); - set_config('feed_topic', '1'); - set_config('feed_item_statistics', '1'); - - // Entries for smiley pagination - set_config('smilies_per_page', '50'); - - // Entry for reporting PMs - set_config('allow_pm_report', '1'); - - // Install modules - $modules_to_install = array( - 'feed' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_FEED_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_BOARD_CONFIGURATION', - 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') - ), - 'warnings' => array( - 'base' => 'users', - 'class' => 'acp', - 'title' => 'ACP_USER_WARNINGS', - 'auth' => 'acl_a_user', - 'display' => 0, - 'cat' => 'ACP_CAT_USERS', - 'after' => array('feedback', 'ACP_USER_FEEDBACK') - ), - 'send_statistics' => array( - 'base' => 'send_statistics', - 'class' => 'acp', - 'title' => 'ACP_SEND_STATISTICS', - 'auth' => 'acl_a_server', - 'cat' => 'ACP_SERVER_CONFIGURATION' - ), - 'setting_forum_copy' => array( - 'base' => 'permissions', - 'class' => 'acp', - 'title' => 'ACP_FORUM_PERMISSIONS_COPY', - 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', - 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', - 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') - ), - 'pm_reports' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_OPEN', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - 'pm_reports_closed' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_CLOSED', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - 'pm_report_details' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORT_DETAILS', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), + return array( + //array('custom', array(array(&$this, ''))) + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('config.update_if', array( + ($this->config['captcha_gd']), + 'captcha_plugin', + 'phpbb_captcha_gd', + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('config.add_if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + 'allow_avatar', + 1, + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('config.add_if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + 'allow_avatar_remote_upload', + 1, + )), + + array('module.add', array( + 'feed' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_FEED_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_BOARD_CONFIGURATION', + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') + ), + )), + array('module.add', array( + 'warnings' => array( + 'base' => 'users', + 'class' => 'acp', + 'title' => 'ACP_USER_WARNINGS', + 'auth' => 'acl_a_user', + 'display' => 0, + 'cat' => 'ACP_CAT_USERS', + 'after' => array('feedback', 'ACP_USER_FEEDBACK') + ), + )), + array('module.add', array( + 'send_statistics' => array( + 'base' => 'send_statistics', + 'class' => 'acp', + 'title' => 'ACP_SEND_STATISTICS', + 'auth' => 'acl_a_server', + 'cat' => 'ACP_SERVER_CONFIGURATION' + ), + )), + array('module.add', array( + 'setting_forum_copy' => array( + 'base' => 'permissions', + 'class' => 'acp', + 'title' => 'ACP_FORUM_PERMISSIONS_COPY', + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') + ), + )), + array('module.add', array( + 'pm_reports' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_OPEN', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_reports_closed' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_CLOSED', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_report_details' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORT_DETAILS', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), ); + } - _add_modules($modules_to_install); + function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + function add_newly_registered_group() + { // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = 'NEWLY_REGISTERED'"; - $result = $db->sql_query($sql); - $group_id = (int) $db->sql_fetchfield('group_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); if (!$group_id) { $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); - $group_id = $db->sql_nextid(); + $group_id = $this->db->sql_nextid(); } // Insert new user role... at the end of the chain @@ -171,35 +203,35 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration FROM ' . ACL_ROLES_TABLE . " WHERE role_name = 'ROLE_USER_NEW_MEMBER' AND role_type = 'u_'"; - $result = $db->sql_query($sql); - $u_role = (int) $db->sql_fetchfield('role_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); if (!$u_role) { $sql = 'SELECT MAX(role_order) as max_order_id FROM ' . ACL_ROLES_TABLE . " WHERE role_type = 'u_'"; - $result = $db->sql_query($sql); - $next_order_id = (int) $db->sql_fetchfield('max_order_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); $next_order_id++; $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; - _sql($sql, $errored, $error_ary); - $u_role = $db->sql_nextid(); + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); if (!$errored) { // Now add the correct data to the roles... // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); // Add user role to group $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } @@ -208,29 +240,29 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration FROM ' . ACL_ROLES_TABLE . " WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' AND role_type = 'f_'"; - $result = $db->sql_query($sql); - $f_role = (int) $db->sql_fetchfield('role_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); if (!$f_role) { $sql = 'SELECT MAX(role_order) as max_order_id FROM ' . ACL_ROLES_TABLE . " WHERE role_type = 'f_'"; - $result = $db->sql_query($sql); - $next_order_id = (int) $db->sql_fetchfield('max_order_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); $next_order_id++; $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; - _sql($sql, $errored, $error_ary); - $f_role = $db->sql_nextid(); + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); if (!$errored) { $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } @@ -238,25 +270,14 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration $sql = 'SELECT 1 FROM ' . USERS_TABLE . ' WHERE user_new = 0'; - $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (!$row) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; - _sql($sql, $errored, $error_ary); - } - - // Newly registered users limit - if (!isset($config['new_member_post_limit'])) - { - set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0); - } - - if (!isset($config['new_member_group_default'])) - { - set_config('new_member_group_default', 0); + $this->sql_query($sql); } // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... @@ -265,9 +286,9 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_id . ' AND auth_role_id = ' . $f_role; - $result = $db->sql_query($sql); - $is_options = (int) $db->sql_fetchfield('forum_id'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); // Not assigned at all... :/ if (!$is_options) @@ -276,75 +297,18 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type != ' . FORUM_LINK; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { - _sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary); + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } // Clear permissions... - include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); $auth_admin = new auth_admin(); $auth_admin->acl_clear_prefetch(); - - if (!isset($config['allow_avatar'])) - { - if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote']) - { - set_config('allow_avatar', '1'); - } - else - { - set_config('allow_avatar', '0'); - } - } - - if (!isset($config['allow_avatar_remote_upload'])) - { - if ($config['allow_avatar_remote'] && $config['allow_avatar_upload']) - { - set_config('allow_avatar_remote_upload', '1'); - } - else - { - set_config('allow_avatar_remote_upload', '0'); - } - } - - // Minimum number of characters - if (!isset($config['min_post_chars'])) - { - set_config('min_post_chars', '1'); - } - - if (!isset($config['allow_quick_reply'])) - { - set_config('allow_quick_reply', '1'); - } - - // Set every members user_options column to enable - // bbcode, smilies and URLs for signatures by default - $sql = 'SELECT user_options - FROM ' . USERS_TABLE . ' - WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')'; - $result = $db->sql_query_limit($sql, 1); - $user_option = (int) $db->sql_fetchfield('user_options'); - $db->sql_freeresult($result); - - // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option - if (!($user_option & 1 << 15)) - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - _sql($sql, $errored, $error_ary); - } - - if (!isset($config['delete_time'])) - { - set_config('delete_time', $config['edit_time']); - } } } diff --git a/phpBB/includes/db/migration/v306rc3.php b/phpBB/includes/db/migration/v306rc3.php index b3bd49eafa..e2c4e66ada 100644 --- a/phpBB/includes/db/migration/v306rc3.php +++ b/phpBB/includes/db/migration/v306rc3.php @@ -20,12 +20,19 @@ class phpbb_db_migration_v306rc3 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'update_cp_fields'))), + ); + } + + function update_cp_fields() { // Update the Custom Profile Fields based on previous settings to the new format $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' SET field_show_on_vt = 1 WHERE field_hide = 0 AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)'; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } diff --git a/phpBB/includes/db/migration/v307rc1.php b/phpBB/includes/db/migration/v307rc1.php index f1c8b3384a..9b55cb2757 100644 --- a/phpBB/includes/db/migration/v307rc1.php +++ b/phpBB/includes/db/migration/v307rc1.php @@ -30,17 +30,22 @@ class phpbb_db_migration_v307rc1 extends phpbb_db_migration function update_data() { - // ATOM Feeds - set_config('feed_overall', '1'); - set_config('feed_http_auth', '0'); - set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15)); - set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10)); - set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0')); - set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0')); + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + ); + } + function delete_text_templates() + { // Delete all text-templates from the template_data $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt'); - _sql($sql, $errored, $error_ary); + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); } } diff --git a/phpBB/includes/db/migration/v307rc2.php b/phpBB/includes/db/migration/v307rc2.php index f9492f3d1c..438ebfb8c2 100644 --- a/phpBB/includes/db/migration/v307rc2.php +++ b/phpBB/includes/db/migration/v307rc2.php @@ -21,15 +21,26 @@ class phpbb_db_migration_v307rc2 extends phpbb_db_migration function update_data() { + return array( + array('custom', array(array(&$this, 'update_email_hash'))), + ); + } + + function update_email_hash($start = 0) + { + $limit = 1000; + $sql = 'SELECT user_id, user_email, user_email_hash FROM ' . USERS_TABLE . ' WHERE user_type <> ' . USER_IGNORE . " AND user_email <> ''"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query_limit($sql, $limit, $start); $i = 0; - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { + $i++; + // Snapshot of the phpbb_email_hash() function // We cannot call it directly because the auto updater updates the DB first. :/ $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); @@ -41,13 +52,19 @@ class phpbb_db_migration_v307rc2 extends phpbb_db_migration ); $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . (int) $row['user_id']; - _sql($sql, $errored, $error_ary, ($i % 100 == 0)); - - ++$i; + $this->sql_query($sql); } } $db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return false; + } + + return $start + $limit; } } diff --git a/phpBB/includes/db/migration/v308rc1.php b/phpBB/includes/db/migration/v308rc1.php index cbfedb1b53..f365695058 100644 --- a/phpBB/includes/db/migration/v308rc1.php +++ b/phpBB/includes/db/migration/v308rc1.php @@ -37,8 +37,8 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration ), )), array('config.add', array('load_unreads_search', 1)), - array('config.update_if', array(600, 'queue_interval', 60)), - array('config.update_if', array(50, 'email_package_size', 20)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), ); } -- cgit v1.2.1 From ae8edf7b0e74c54b5b02b66a8b2a436a4172c63e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 06:26:38 -0600 Subject: [feature/migrations] Use $this->db PHPBB3-9737 --- phpBB/includes/db/migration.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index aca9d264bb..de9f6d07e3 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -95,29 +95,29 @@ class phpbb_db_migration echo "
\n{$sql}\n
"; } - $db->sql_return_on_error(true); + $this->db->sql_return_on_error(true); if ($sql === 'begin') { - $result = $db->sql_transaction('begin'); + $result = $this->db->sql_transaction('begin'); } else if ($sql === 'commit') { - $result = $db->sql_transaction('commit'); + $result = $this->db->sql_transaction('commit'); } else { - $result = $db->sql_query($sql); - if ($db->sql_error_triggered) + $result = $this->db->sql_query($sql); + if ($this->db->sql_error_triggered) { $this->errors[] = array( - 'sql' => $db->sql_error_sql, - 'code' => $db->sql_error_returned, + 'sql' => $this->db->sql_error_sql, + 'code' => $this->db->sql_error_returned, ); } } - $db->sql_return_on_error(false); + $this->db->sql_return_on_error(false); return $result; } -- cgit v1.2.1 From 167faed1630d01e3d592a6696f58316c1d832ff9 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 06:32:02 -0600 Subject: [feature/migrations] Depend on part2 PHPBB3-9737 --- phpBB/includes/db/migration/v305.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v305.php b/phpBB/includes/db/migration/v305.php index b4d676d72a..71e28c6b7b 100644 --- a/phpBB/includes/db/migration/v305.php +++ b/phpBB/includes/db/migration/v305.php @@ -11,7 +11,7 @@ class phpbb_db_migration_v305 extends phpbb_db_migration { function depends_on() { - return array('phpbb_db_migration_v305rc1'); + return array('phpbb_db_migration_v305rc1part2'); } function update_schema() -- cgit v1.2.1 From b52a0f50ab980ca941267ddb4f509f104b07db77 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sat, 10 Nov 2012 13:32:44 +0100 Subject: [feature/migrations] Update 3.0.3-3.0.5 migrations to work --- phpBB/includes/db/migration/305rc1part2.php | 34 +++++++++ phpBB/includes/db/migration/v303rc1.php | 100 ++++---------------------- phpBB/includes/db/migration/v304.php | 15 ++-- phpBB/includes/db/migration/v304rc1.php | 13 +++- phpBB/includes/db/migration/v305rc1.php | 105 +++++++++++----------------- 5 files changed, 107 insertions(+), 160 deletions(-) create mode 100644 phpBB/includes/db/migration/305rc1part2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/305rc1part2.php b/phpBB/includes/db/migration/305rc1part2.php new file mode 100644 index 0000000000..238e533b06 --- /dev/null +++ b/phpBB/includes/db/migration/305rc1part2.php @@ -0,0 +1,34 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/v303rc1.php b/phpBB/includes/db/migration/v303rc1.php index b8ec5668fd..7518a6ed54 100644 --- a/phpBB/includes/db/migration/v303rc1.php +++ b/phpBB/includes/db/migration/v303rc1.php @@ -35,93 +35,20 @@ class phpbb_db_migration_v303rc1 extends phpbb_db_migration array('config.add', array('enable_queue_trigger', '0')), array('config.add', array('queue_trigger_posts', '3')), array('config.add', array('pm_max_recipients', '0')), - array('custom', array('set_group_default_max_recipients')) - - // Not prefilling yet - set_config('dbms_version', ''); - - // Add new permission u_masspm_group and duplicate settings from u_masspm - include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - $auth_admin = new auth_admin(); - - // Only add the new permission if it does not already exist - if (empty($auth_admin->acl_options['id']['u_masspm_group'])) - { - $auth_admin->acl_add_option(array('global' => array('u_masspm_group'))); - - // Now the tricky part, filling the permission - $old_id = $auth_admin->acl_options['id']['u_masspm']; - $new_id = $auth_admin->acl_options['id']['u_masspm_group']; - - $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); - - foreach ($tables as $table) - { - $sql = 'SELECT * - FROM ' . $table . ' - WHERE auth_option_id = ' . $old_id; - $result = _sql($sql, $errored, $error_ary); - - $sql_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - $row['auth_option_id'] = $new_id; - $sql_ary[] = $row; - } - $db->sql_freeresult($result); - - if (sizeof($sql_ary)) - { - $db->sql_multi_insert($table, $sql_ary); - } - } - - // Remove any old permission entries - $auth_admin->acl_clear_prefetch(); - } - - /** - * Do not resync post counts here. An admin may do this later from the ACP - $start = 0; - $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000; - - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0'; - _sql($sql, $errored, $error_ary); - - do - { - $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id - FROM ' . POSTS_TABLE . ' - WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' - AND post_postcount = 1 AND post_approved = 1 - GROUP BY poster_id'; - $result = _sql($sql, $errored, $error_ary); - - if ($row = $db->sql_fetchrow($result)) - { - do - { - $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}"; - _sql($sql, $errored, $error_ary); - } - while ($row = $db->sql_fetchrow($result)); - - $start += $step; - } - else - { - $start = 0; - } - $db->sql_freeresult($result); - } - while ($start); - */ + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', '')), + array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + )); + } - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - _sql($sql, $errored, $error_ary); + function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); } function set_group_default_max_recipients() @@ -131,5 +58,4 @@ class phpbb_db_migration_v303rc1 extends phpbb_db_migration WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); $this->sql_query($sql); } - } diff --git a/phpBB/includes/db/migration/v304.php b/phpBB/includes/db/migration/v304.php index 2895caaa6d..5358bcc20f 100644 --- a/phpBB/includes/db/migration/v304.php +++ b/phpBB/includes/db/migration/v304.php @@ -20,21 +20,28 @@ class phpbb_db_migration_v304 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'rename_log_delete_topic'))), + ); + } + + function rename_log_delete_topic() { if ($db->sql_layer == 'oracle') { // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . LOG_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "log SET log_operation = 'LOG_DELETE_TOPIC' WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } else { - $sql = 'UPDATE ' . LOG_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "log SET log_operation = 'LOG_DELETE_TOPIC' WHERE log_operation = 'LOG_TOPIC_DELETED'"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } } diff --git a/phpBB/includes/db/migration/v304rc1.php b/phpBB/includes/db/migration/v304rc1.php index a7098ce62f..2daad4e826 100644 --- a/phpBB/includes/db/migration/v304rc1.php +++ b/phpBB/includes/db/migration/v304rc1.php @@ -56,13 +56,20 @@ class phpbb_db_migration_v304rc1 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + ); + } + + function update_custom_profile_fields() { // Update the Custom Profile Fields based on previous settings to the new format $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide FROM ' . PROFILE_FIELDS_TABLE; - $result = _sql($sql, $errored, $error_ary); + $result = $this->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $sql_ary = array( 'field_required' => 0, @@ -90,7 +97,7 @@ class phpbb_db_migration_v304rc1 extends phpbb_db_migration $sql_ary['field_show_profile'] = 1; } - _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); } } } diff --git a/phpBB/includes/db/migration/v305rc1.php b/phpBB/includes/db/migration/v305rc1.php index 8d9c4d2456..4f20796608 100644 --- a/phpBB/includes/db/migration/v305rc1.php +++ b/phpBB/includes/db/migration/v305rc1.php @@ -27,28 +27,29 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration function update_data() { - // Captcha config variables - set_config('captcha_gd_wave', 0); - set_config('captcha_gd_3d_noise', 1); - set_config('captcha_gd_fonts', 1); - set_config('confirm_refresh', 1); + $search_indexing_state = $this->config['search_indexing_state']; - // Maximum number of keywords - set_config('max_num_search_keywords', 10); - - // Remove static config var and put it back as dynamic variable - $sql = 'UPDATE ' . CONFIG_TABLE . " - SET is_dynamic = 1 - WHERE config_name = 'search_indexing_state'"; - _sql($sql, $errored, $error_ary); + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_refresh', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } - // Hash old MD5 passwords + function hash_old_passwords() + { $sql = 'SELECT user_id, user_password - FROM ' . USERS_TABLE . ' + FROM ' . $this->table_prefix . 'users WHERE user_pass_convert = 1'; - $result = _sql($sql, $errored, $error_ary); + $result = $this->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if (strlen($row['user_password']) == 32) { @@ -56,33 +57,36 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration 'user_password' => phpbb_hash($row['user_password']), ); - _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary); + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); } } $db->sql_freeresult($result); + } + function update_ichiro_bot() + { // Adjust bot entry - $sql = 'UPDATE ' . BOTS_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "bots SET bot_agent = 'ichiro/' WHERE bot_agent = 'ichiro/2'"; - _sql($sql, $errored, $error_ary); - + $this->sql_query($sql); + } + function remove_duplicate_auth_options() + { // Before we are able to add a unique key to auth_option, we need to remove duplicate entries - - // We get duplicate entries first $sql = 'SELECT auth_option - FROM ' . ACL_OPTIONS_TABLE . ' + FROM ' . $this->table_prefix . 'acl_options GROUP BY auth_option HAVING COUNT(*) >= 2'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $auth_options = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $auth_options[] = $row['auth_option']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // Remove specific auth options if (!empty($auth_options)) @@ -95,52 +99,21 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration WHERE auth_option = '" . $db->sql_escape($option) . "' ORDER BY auth_option_id DESC"; // sql_query_limit not possible here, due to bug in postgresql layer - $result = $db->sql_query($sql); + $result = $this->sql_query($sql); // Skip first row, this is our original auth option we want to preserve - $row = $db->sql_fetchrow($result); + $row = $this->db->sql_fetchrow($result); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { // Ok, remove this auth option... - _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); - _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); - _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); - _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } } - - // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one. - $changes = array( - 'drop_keys' => array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - ); - - global $db_tools; - - $statements = $db_tools->perform_schema_changes($changes); - - foreach ($statements as $sql) - { - _sql($sql, $errored, $error_ary); - } - - $changes = array( - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - - $statements = $db_tools->perform_schema_changes($changes); - - foreach ($statements as $sql) - { - _sql($sql, $errored, $error_ary); - } } } -- cgit v1.2.1 From ce021710fbe4d594e4f66c3338da8bb2610a0c75 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:01 -0600 Subject: [feature/migrations] Rename classes, depends on PHPBB3-9737 --- phpBB/includes/db/migration/305rc1part2.php | 34 - phpBB/includes/db/migration/3_0_1.php | 25 + phpBB/includes/db/migration/3_0_10.php | 25 + phpBB/includes/db/migration/3_0_10_rc1.php | 28 + phpBB/includes/db/migration/3_0_10_rc2.php | 25 + phpBB/includes/db/migration/3_0_10_rc3.php | 25 + phpBB/includes/db/migration/3_0_11.php | 25 + phpBB/includes/db/migration/3_0_11_rc1.php | 96 + phpBB/includes/db/migration/3_0_11_rc2 | 31 + phpBB/includes/db/migration/3_0_12_rc1.php | 26 + phpBB/includes/db/migration/3_0_1_rc1.php | 77 + phpBB/includes/db/migration/3_0_2.php | 25 + phpBB/includes/db/migration/3_0_2_rc1.php | 30 + phpBB/includes/db/migration/3_0_2_rc2.php | 52 + phpBB/includes/db/migration/3_0_3.php | 25 + phpBB/includes/db/migration/3_0_3_rc1.php | 61 + phpBB/includes/db/migration/3_0_4.php | 47 + phpBB/includes/db/migration/3_0_4_rc1.php | 103 + phpBB/includes/db/migration/3_0_5.php | 25 + phpBB/includes/db/migration/3_0_5_rc1.php | 119 + phpBB/includes/db/migration/3_0_5_rc1part2.php | 34 + phpBB/includes/db/migration/3_0_6.php | 25 + phpBB/includes/db/migration/3_0_6_rc1.php | 314 +++ phpBB/includes/db/migration/3_0_6_rc2.php | 25 + phpBB/includes/db/migration/3_0_6_rc3.php | 38 + phpBB/includes/db/migration/3_0_6_rc4.php | 25 + phpBB/includes/db/migration/3_0_7.php | 25 + phpBB/includes/db/migration/3_0_7_pl1.php | 25 + phpBB/includes/db/migration/3_0_7_rc1.php | 51 + phpBB/includes/db/migration/3_0_7_rc2.php | 70 + phpBB/includes/db/migration/3_0_8.php | 25 + phpBB/includes/db/migration/3_0_8_rc1.php | 225 ++ phpBB/includes/db/migration/3_0_9.php | 25 + phpBB/includes/db/migration/3_0_9_rc1.php | 108 + phpBB/includes/db/migration/3_0_9_rc2.php | 25 + phpBB/includes/db/migration/3_0_9_rc3.php | 25 + phpBB/includes/db/migration/3_0_9_rc4.php | 25 + phpBB/includes/db/migration/v301.php | 25 - phpBB/includes/db/migration/v3010.php | 25 - phpBB/includes/db/migration/v3010rc1.php | 28 - phpBB/includes/db/migration/v3010rc2.php | 25 - phpBB/includes/db/migration/v3010rc3.php | 25 - phpBB/includes/db/migration/v3011.php | 25 - phpBB/includes/db/migration/v3011rc1.php | 96 - phpBB/includes/db/migration/v3011rc2.php | 31 - phpBB/includes/db/migration/v3012rc1.php | 26 - phpBB/includes/db/migration/v301rc1.php | 77 - phpBB/includes/db/migration/v302.php | 25 - phpBB/includes/db/migration/v302rc1.php | 30 - phpBB/includes/db/migration/v302rc2.php | 52 - phpBB/includes/db/migration/v303.php | 25 - phpBB/includes/db/migration/v303rc1.php | 61 - phpBB/includes/db/migration/v304.php | 47 - phpBB/includes/db/migration/v304rc1.php | 103 - phpBB/includes/db/migration/v305.php | 25 - phpBB/includes/db/migration/v305rc1.php | 119 - phpBB/includes/db/migration/v306.php | 25 - phpBB/includes/db/migration/v306rc1.php | 314 --- phpBB/includes/db/migration/v306rc2.php | 25 - phpBB/includes/db/migration/v306rc3.php | 38 - phpBB/includes/db/migration/v306rc4.php | 25 - phpBB/includes/db/migration/v307.php | 25 - phpBB/includes/db/migration/v307pl1.php | 25 - phpBB/includes/db/migration/v307rc1.php | 51 - phpBB/includes/db/migration/v307rc2.php | 70 - phpBB/includes/db/migration/v308.php | 25 - phpBB/includes/db/migration/v308rc1.php | 225 -- phpBB/includes/db/migration/v309.php | 25 - phpBB/includes/db/migration/v309rc1.php | 108 - phpBB/includes/db/migration/v309rc2.php | 25 - phpBB/includes/db/migration/v309rc3.php | 25 - phpBB/includes/db/migration/v309rc4.php | 25 - phpBB/includes/db/migrationtools/base.php | 15 + phpBB/includes/db/migrationtools/config.php | 121 + phpBB/includes/db/migrationtools/umil.php | 3037 ++++++++++++++++++++++++ 75 files changed, 5133 insertions(+), 1960 deletions(-) delete mode 100644 phpBB/includes/db/migration/305rc1part2.php create mode 100644 phpBB/includes/db/migration/3_0_1.php create mode 100644 phpBB/includes/db/migration/3_0_10.php create mode 100644 phpBB/includes/db/migration/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/3_0_11.php create mode 100644 phpBB/includes/db/migration/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_11_rc2 create mode 100644 phpBB/includes/db/migration/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_2.php create mode 100644 phpBB/includes/db/migration/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_3.php create mode 100644 phpBB/includes/db/migration/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_4.php create mode 100644 phpBB/includes/db/migration/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_5.php create mode 100644 phpBB/includes/db/migration/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/3_0_6.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/3_0_7.php create mode 100644 phpBB/includes/db/migration/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_8.php create mode 100644 phpBB/includes/db/migration/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_9.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc4.php delete mode 100644 phpBB/includes/db/migration/v301.php delete mode 100644 phpBB/includes/db/migration/v3010.php delete mode 100644 phpBB/includes/db/migration/v3010rc1.php delete mode 100644 phpBB/includes/db/migration/v3010rc2.php delete mode 100644 phpBB/includes/db/migration/v3010rc3.php delete mode 100644 phpBB/includes/db/migration/v3011.php delete mode 100644 phpBB/includes/db/migration/v3011rc1.php delete mode 100644 phpBB/includes/db/migration/v3011rc2.php delete mode 100644 phpBB/includes/db/migration/v3012rc1.php delete mode 100644 phpBB/includes/db/migration/v301rc1.php delete mode 100644 phpBB/includes/db/migration/v302.php delete mode 100644 phpBB/includes/db/migration/v302rc1.php delete mode 100644 phpBB/includes/db/migration/v302rc2.php delete mode 100644 phpBB/includes/db/migration/v303.php delete mode 100644 phpBB/includes/db/migration/v303rc1.php delete mode 100644 phpBB/includes/db/migration/v304.php delete mode 100644 phpBB/includes/db/migration/v304rc1.php delete mode 100644 phpBB/includes/db/migration/v305.php delete mode 100644 phpBB/includes/db/migration/v305rc1.php delete mode 100644 phpBB/includes/db/migration/v306.php delete mode 100644 phpBB/includes/db/migration/v306rc1.php delete mode 100644 phpBB/includes/db/migration/v306rc2.php delete mode 100644 phpBB/includes/db/migration/v306rc3.php delete mode 100644 phpBB/includes/db/migration/v306rc4.php delete mode 100644 phpBB/includes/db/migration/v307.php delete mode 100644 phpBB/includes/db/migration/v307pl1.php delete mode 100644 phpBB/includes/db/migration/v307rc1.php delete mode 100644 phpBB/includes/db/migration/v307rc2.php delete mode 100644 phpBB/includes/db/migration/v308.php delete mode 100644 phpBB/includes/db/migration/v308rc1.php delete mode 100644 phpBB/includes/db/migration/v309.php delete mode 100644 phpBB/includes/db/migration/v309rc1.php delete mode 100644 phpBB/includes/db/migration/v309rc2.php delete mode 100644 phpBB/includes/db/migration/v309rc3.php delete mode 100644 phpBB/includes/db/migration/v309rc4.php create mode 100644 phpBB/includes/db/migrationtools/base.php create mode 100644 phpBB/includes/db/migrationtools/config.php create mode 100644 phpBB/includes/db/migrationtools/umil.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/305rc1part2.php b/phpBB/includes/db/migration/305rc1part2.php deleted file mode 100644 index 238e533b06..0000000000 --- a/phpBB/includes/db/migration/305rc1part2.php +++ /dev/null @@ -1,34 +0,0 @@ - array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_1.php b/phpBB/includes/db/migration/3_0_1.php new file mode 100644 index 0000000000..1cb069a2b1 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_1.php @@ -0,0 +1,25 @@ +sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $this->db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql); + } + } + + function delete_orphan_private_messages() + { + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql); + + return true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/3_0_11_rc2 b/phpBB/includes/db/migration/3_0_11_rc2 new file mode 100644 index 0000000000..f4e64871ed --- /dev/null +++ b/phpBB/includes/db/migration/3_0_11_rc2 @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/3_0_12_rc1.php b/phpBB/includes/db/migration/3_0_12_rc1.php new file mode 100644 index 0000000000..58e112a43a --- /dev/null +++ b/phpBB/includes/db/migration/3_0_12_rc1.php @@ -0,0 +1,26 @@ + array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array('group_legend'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + ); + } + + function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/3_0_2.php b/phpBB/includes/db/migration/3_0_2.php new file mode 100644 index 0000000000..36e8d52e6b --- /dev/null +++ b/phpBB/includes/db/migration/3_0_2.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/3_0_3.php b/phpBB/includes/db/migration/3_0_3.php new file mode 100644 index 0000000000..c9ca33ee88 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_3.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', '')), + array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + )); + } + + function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); + } + + function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/3_0_4.php b/phpBB/includes/db/migration/3_0_4.php new file mode 100644 index 0000000000..bbaaea54c9 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_4.php @@ -0,0 +1,47 @@ +sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/3_0_4_rc1.php b/phpBB/includes/db/migration/3_0_4_rc1.php new file mode 100644 index 0000000000..b783e58e24 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_4_rc1.php @@ -0,0 +1,103 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + ); + } + + function update_custom_profile_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = $this->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/3_0_5.php b/phpBB/includes/db/migration/3_0_5.php new file mode 100644 index 0000000000..272779f083 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_5.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + $search_indexing_state = $this->config['search_indexing_state']; + + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_refresh', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } + + function hash_old_passwords() + { + $sql = 'SELECT user_id, user_password + FROM ' . $this->table_prefix . 'users + WHERE user_pass_convert = 1'; + $result = $this->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); + } + } + $db->sql_freeresult($result); + } + + function update_ichiro_bot() + { + // Adjust bot entry + $sql = 'UPDATE ' . $this->table_prefix . "bots + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + $this->sql_query($sql); + } + + function remove_duplicate_auth_options() + { + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + $sql = 'SELECT auth_option + FROM ' . $this->table_prefix . 'acl_options + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $this->db->sql_query($sql); + + $auth_options = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $this->db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $this->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $this->db->sql_fetchrow($result); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + } + $this->db->sql_freeresult($result); + } + } + } +} diff --git a/phpBB/includes/db/migration/3_0_5_rc1part2.php b/phpBB/includes/db/migration/3_0_5_rc1part2.php new file mode 100644 index 0000000000..710c8dce91 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_5_rc1part2.php @@ -0,0 +1,34 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/3_0_6.php b/phpBB/includes/db/migration/3_0_6.php new file mode 100644 index 0000000000..9582038b36 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_6.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + function update_data() + { + return array( + //array('custom', array(array(&$this, ''))) + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('config.update_if', array( + ($this->config['captcha_gd']), + 'captcha_plugin', + 'phpbb_captcha_gd', + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('config.add_if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + 'allow_avatar', + 1, + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('config.add_if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + 'allow_avatar_remote_upload', + 1, + )), + + array('module.add', array( + 'feed' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_FEED_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_BOARD_CONFIGURATION', + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') + ), + )), + array('module.add', array( + 'warnings' => array( + 'base' => 'users', + 'class' => 'acp', + 'title' => 'ACP_USER_WARNINGS', + 'auth' => 'acl_a_user', + 'display' => 0, + 'cat' => 'ACP_CAT_USERS', + 'after' => array('feedback', 'ACP_USER_FEEDBACK') + ), + )), + array('module.add', array( + 'send_statistics' => array( + 'base' => 'send_statistics', + 'class' => 'acp', + 'title' => 'ACP_SEND_STATISTICS', + 'auth' => 'acl_a_server', + 'cat' => 'ACP_SERVER_CONFIGURATION' + ), + )), + array('module.add', array( + 'setting_forum_copy' => array( + 'base' => 'permissions', + 'class' => 'acp', + 'title' => 'ACP_FORUM_PERMISSIONS_COPY', + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') + ), + )), + array('module.add', array( + 'pm_reports' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_OPEN', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_reports_closed' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_CLOSED', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_report_details' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORT_DETAILS', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + ); + } + + function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + + function add_newly_registered_group() + { + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + $this->sql_query($sql); + + $group_id = $this->db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); + + if (!$errored) + { + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); + } + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); + + if (!$errored) + { + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); + } + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + $this->sql_query($sql); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); + } + $this->db->sql_freeresult($result); + } + + // Clear permissions... + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/3_0_6_rc2.php b/phpBB/includes/db/migration/3_0_6_rc2.php new file mode 100644 index 0000000000..1552485d0a --- /dev/null +++ b/phpBB/includes/db/migration/3_0_6_rc2.php @@ -0,0 +1,25 @@ +sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/3_0_6_rc4.php b/phpBB/includes/db/migration/3_0_6_rc4.php new file mode 100644 index 0000000000..00161456b6 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_6_rc4.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'log' => array('log_time'), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + ); + } + + function delete_text_templates() + { + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/3_0_7_rc2.php b/phpBB/includes/db/migration/3_0_7_rc2.php new file mode 100644 index 0000000000..4ab4e906d7 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_7_rc2.php @@ -0,0 +1,70 @@ + ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + $i = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + $this->sql_query($sql); + } + } + $db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return false; + } + + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/3_0_8.php b/phpBB/includes/db/migration/3_0_8.php new file mode 100644 index 0000000000..3e7f843a65 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_8.php @@ -0,0 +1,25 @@ + array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_POST_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_MESSAGES', + 'after' => array('message', 'ACP_MESSAGE_SETTINGS') + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $this->db->sql_freeresult($result); + } + + function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + $this->sql_query($sql); + } + + function update_bots() + { + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + $this->sql_query($sql); + } + } + + function delete_orphan_shadow_topics() + { + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + return true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/3_0_9.php b/phpBB/includes/db/migration/3_0_9.php new file mode 100644 index 0000000000..2e1eab26e7 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_9.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcode' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + function fix_firebird_qa_captcha() + { + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($this->db_tools->sql_layer == 'firebird') + { + $tables = array( + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($this->db_tools->sql_table_exists($table)) + { + $this->db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/3_0_9_rc2.php b/phpBB/includes/db/migration/3_0_9_rc2.php new file mode 100644 index 0000000000..96782b2b01 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_9_rc2.php @@ -0,0 +1,25 @@ +sql_query($sql); - - $deactivated_style_ids = array(); - while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) - { - $deactivated_style_ids[] = (int) $style_id; - } - $this->db->sql_freeresult($result); - - if (!empty($deactivated_style_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->config['default_style'] .' - WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); - $this->sql_query($sql); - } - } - - function delete_orphan_private_messages() - { - // Delete orphan private messages - $batch_size = 500; - - $sql_array = array( - 'SELECT' => 'p.msg_id', - 'FROM' => array( - PRIVMSGS_TABLE => 'p', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), - 'ON' => 'p.msg_id = t.msg_id', - ), - ), - 'WHERE' => 't.user_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - - $result = $this->db->sql_query_limit($sql, $batch_size); - - $delete_pms = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $db->sql_freeresult($result); - - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql); - - return true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/v3011rc2.php b/phpBB/includes/db/migration/v3011rc2.php deleted file mode 100644 index 0f66eff156..0000000000 --- a/phpBB/includes/db/migration/v3011rc2.php +++ /dev/null @@ -1,31 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/v3012rc1.php b/phpBB/includes/db/migration/v3012rc1.php deleted file mode 100644 index 67f7a29b02..0000000000 --- a/phpBB/includes/db/migration/v3012rc1.php +++ /dev/null @@ -1,26 +0,0 @@ - array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list' => array('BOOL', 1), - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('UINT', 0), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'groups' => array('group_legend'), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('session_forum_id'), - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name' => array('group_legend', 'group_name'), - ), - ), - ); - } - - function update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - ); - } - - function fix_unset_last_view_time() - { - $sql = 'UPDATE ' . $this->table_prefix . "topics - SET topic_last_view_time = topic_last_post_time - WHERE topic_last_view_time = 0"; - $this->sql_query($sql); - } - - function reset_smiley_size() - { - // Update smiley sizes - $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); - - foreach ($smileys as $smiley) - { - if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) - { - list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); - - $sql = 'UPDATE ' . SMILIES_TABLE . ' - SET smiley_width = ' . $width . ', smiley_height = ' . $height . " - WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; - - $this->sql_query($sql); - } - } - } -} diff --git a/phpBB/includes/db/migration/v302.php b/phpBB/includes/db/migration/v302.php deleted file mode 100644 index 942a0ac58c..0000000000 --- a/phpBB/includes/db/migration/v302.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'drafts' => array( - 'draft_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'forums' => array( - 'forum_last_post_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'posts' => array( - 'post_subject' => array('STEXT_UNI', '', 'true_sort'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'topics' => array( - 'topic_title' => array('STEXT_UNI', '', 'true_sort'), - 'topic_last_post_subject' => array('STEXT_UNI', ''), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid' => array('session_forum_id'), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/v303.php b/phpBB/includes/db/migration/v303.php deleted file mode 100644 index 409c396baf..0000000000 --- a/phpBB/includes/db/migration/v303.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('enable_queue_trigger', '0')), - array('config.add', array('queue_trigger_posts', '3')), - array('config.add', array('pm_max_recipients', '0')), - array('custom', array(array(&$this, 'set_group_default_max_recipients'))), - array('config.add', array('dbms_version', '')), - array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - )); - } - - function correct_acp_email_permissions() - { - $sql = 'UPDATE ' . $this->table_prefix . 'modules - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - $this->sql_query($sql); - } - - function set_group_default_max_recipients() - { - // Set maximum number of recipients for the registered users, bots, guests group - $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 - WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/v304.php b/phpBB/includes/db/migration/v304.php deleted file mode 100644 index 5358bcc20f..0000000000 --- a/phpBB/includes/db/migration/v304.php +++ /dev/null @@ -1,47 +0,0 @@ -sql_layer == 'oracle') - { - // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation = 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - } -} diff --git a/phpBB/includes/db/migration/v304rc1.php b/phpBB/includes/db/migration/v304rc1.php deleted file mode 100644 index 2daad4e826..0000000000 --- a/phpBB/includes/db/migration/v304rc1.php +++ /dev/null @@ -1,103 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile' => array('BOOL', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'styles' => array( - 'style_id' => array('UINT', NULL, 'auto_increment'), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_imageset' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_theme' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template_data' => array( - 'template_id' => array('UINT', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_style' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('custom', array(array(&$this, 'update_custom_profile_fields'))), - ); - } - - function update_custom_profile_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide - FROM ' . PROFILE_FIELDS_TABLE; - $result = $this->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'field_required' => 0, - 'field_show_on_reg' => 0, - 'field_hide' => 0, - 'field_show_profile'=> 0, - ); - - if ($row['field_required']) - { - $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_show_on_reg']) - { - $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_hide']) - { - // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module - $sql_ary['field_hide'] = 1; - } - else - { - // equivelant to "none", which is the "Display in user control panel" option - $sql_ary['field_show_profile'] = 1; - } - - $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); - } - } -} diff --git a/phpBB/includes/db/migration/v305.php b/phpBB/includes/db/migration/v305.php deleted file mode 100644 index 71e28c6b7b..0000000000 --- a/phpBB/includes/db/migration/v305.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - $search_indexing_state = $this->config['search_indexing_state']; - - return array( - array('config.add', array('captcha_gd_wave', 0)), - array('config.add', array('captcha_gd_3d_noise', 1)), - array('config.add', array('captcha_gd_refresh', 1)), - array('config.add', array('confirm_refresh', 1)), - array('config.add', array('max_num_search_keywords', 10)), - array('config.remove', array('search_indexing_state')), - array('config.add', array('search_indexing_state', $search_indexing_state, true)), - array('custom', array(array(&$this, 'hash_old_passwords'))), - array('custom', array(array(&$this, 'update_ichiro_bot'))), - ); - } - - function hash_old_passwords() - { - $sql = 'SELECT user_id, user_password - FROM ' . $this->table_prefix . 'users - WHERE user_pass_convert = 1'; - $result = $this->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (strlen($row['user_password']) == 32) - { - $sql_ary = array( - 'user_password' => phpbb_hash($row['user_password']), - ); - - $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); - } - } - $db->sql_freeresult($result); - } - - function update_ichiro_bot() - { - // Adjust bot entry - $sql = 'UPDATE ' . $this->table_prefix . "bots - SET bot_agent = 'ichiro/' - WHERE bot_agent = 'ichiro/2'"; - $this->sql_query($sql); - } - - function remove_duplicate_auth_options() - { - // Before we are able to add a unique key to auth_option, we need to remove duplicate entries - $sql = 'SELECT auth_option - FROM ' . $this->table_prefix . 'acl_options - GROUP BY auth_option - HAVING COUNT(*) >= 2'; - $result = $this->db->sql_query($sql); - - $auth_options = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $auth_options[] = $row['auth_option']; - } - $this->db->sql_freeresult($result); - - // Remove specific auth options - if (!empty($auth_options)) - { - foreach ($auth_options as $option) - { - // Select auth_option_ids... the largest id will be preserved - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $db->sql_escape($option) . "' - ORDER BY auth_option_id DESC"; - // sql_query_limit not possible here, due to bug in postgresql layer - $result = $this->sql_query($sql); - - // Skip first row, this is our original auth option we want to preserve - $row = $this->db->sql_fetchrow($result); - - while ($row = $this->db->sql_fetchrow($result)) - { - // Ok, remove this auth option... - $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - } - $this->db->sql_freeresult($result); - } - } - } -} diff --git a/phpBB/includes/db/migration/v306.php b/phpBB/includes/db/migration/v306.php deleted file mode 100644 index eec2f7c752..0000000000 --- a/phpBB/includes/db/migration/v306.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'confirm' => array( - 'attempts' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_new' => array('BOOL', 1), - 'user_reminded' => array('TINT:4', 0), - 'user_reminded_time' => array('TIMESTAMP', 0), - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported' => array('BOOL', 0), - ), - $this->table_prefix . 'reports' => array( - 'pm_id' => array('UINT', 0), - ), - $this->table_prefix . 'fields' => array( - 'field_show_on_vt' => array('BOOL', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_options' => array('UINT:20', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_options' => array('UINT:11', 230271), - ), - ), - 'add_index' => array( - $this->table_prefix . 'reports' => array( - 'post_id' => array('post_id'), - 'pm_id' => array('pm_id'), - ), - $this->table_prefix . 'posts' => array( - 'post_username' => array('post_username:255'), - ), - ), - ); - } - - function update_data() - { - return array( - //array('custom', array(array(&$this, ''))) - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('config.update_if', array( - ($this->config['captcha_gd']), - 'captcha_plugin', - 'phpbb_captcha_gd', - )), - - array('config.add', array('feed_enable', 0)), - array('config.add', array('feed_limit', 10)), - array('config.add', array('feed_overall_forums', 1)), - array('config.add', array('feed_overall_forums_limit', 15)), - array('config.add', array('feed_overall_topics', 0)), - array('config.add', array('feed_overall_topics_limit', 15)), - array('config.add', array('feed_forum', 1)), - array('config.add', array('feed_topic', 1)), - array('config.add', array('feed_item_statistics', 1)), - - array('config.add', array('smilies_per_page', 50)), - array('config.add', array('allow_pm_report', 1)), - array('config.add', array('min_post_chars', 1)), - array('config.add', array('allow_quick_reply', 1)), - array('config.add', array('new_member_post_limit', 0)), - array('config.add', array('new_member_group_default', 0)), - array('config.add', array('delete_time', $this->config['edit_time'])), - - array('config.add', array('allow_avatar', 0)), - array('config.add_if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - 'allow_avatar', - 1, - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('config.add_if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - 'allow_avatar_remote_upload', - 1, - )), - - array('module.add', array( - 'feed' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_FEED_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_BOARD_CONFIGURATION', - 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') - ), - )), - array('module.add', array( - 'warnings' => array( - 'base' => 'users', - 'class' => 'acp', - 'title' => 'ACP_USER_WARNINGS', - 'auth' => 'acl_a_user', - 'display' => 0, - 'cat' => 'ACP_CAT_USERS', - 'after' => array('feedback', 'ACP_USER_FEEDBACK') - ), - )), - array('module.add', array( - 'send_statistics' => array( - 'base' => 'send_statistics', - 'class' => 'acp', - 'title' => 'ACP_SEND_STATISTICS', - 'auth' => 'acl_a_server', - 'cat' => 'ACP_SERVER_CONFIGURATION' - ), - )), - array('module.add', array( - 'setting_forum_copy' => array( - 'base' => 'permissions', - 'class' => 'acp', - 'title' => 'ACP_FORUM_PERMISSIONS_COPY', - 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', - 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', - 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') - ), - )), - array('module.add', array( - 'pm_reports' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_OPEN', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_reports_closed' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_CLOSED', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_report_details' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORT_DETAILS', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - ); - } - - function set_user_options_default() - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - $this->sql_query($sql); - } - - function add_newly_registered_group() - { - // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'NEWLY_REGISTERED'"; - $result = $this->db->sql_query($sql); - $group_id = (int) $this->db->sql_fetchfield('group_id'); - $this->db->sql_freeresult($result); - - if (!$group_id) - { - $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; - $this->sql_query($sql); - - $group_id = $this->db->sql_nextid(); - } - - // Insert new user role... at the end of the chain - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_USER_NEW_MEMBER' - AND role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $u_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$u_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; - $this->sql_query($sql); - $u_role = $this->db->sql_nextid(); - - if (!$errored) - { - // Now add the correct data to the roles... - // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - $this->sql_query($sql); - - // Add user role to group - $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - $this->sql_query($sql); - } - } - - // Insert new forum role - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' - AND role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $f_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$f_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; - $this->sql_query($sql); - $f_role = $this->db->sql_nextid(); - - if (!$errored) - { - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - $this->sql_query($sql); - } - } - - // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) - $sql = 'SELECT 1 - FROM ' . USERS_TABLE . ' - WHERE user_new = 0'; - $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; - $this->sql_query($sql); - } - - // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... - // Check if the role is already assigned... - $sql = 'SELECT forum_id - FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id = ' . $f_role; - $result = $this->db->sql_query($sql); - $is_options = (int) $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - // Not assigned at all... :/ - if (!$is_options) - { - // Get postable forums - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type != ' . FORUM_LINK; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); - } - $this->db->sql_freeresult($result); - } - - // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/v306rc2.php b/phpBB/includes/db/migration/v306rc2.php deleted file mode 100644 index 0a6c388da6..0000000000 --- a/phpBB/includes/db/migration/v306rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/v306rc4.php b/phpBB/includes/db/migration/v306rc4.php deleted file mode 100644 index 92c1979311..0000000000 --- a/phpBB/includes/db/migration/v306rc4.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'log' => array('log_time'), - ), - 'add_index' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id' => array('topic_id'), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('feed_overall', 1)), - array('config.add', array('feed_http_auth', 0)), - array('config.add', array('feed_limit_post', $this->config['feed_limit'])), - array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), - array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), - array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), - array('custom', array(array(&$this, 'delete_text_templates'))), - ); - } - - function delete_text_templates() - { - // Delete all text-templates from the template_data - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/v307rc2.php b/phpBB/includes/db/migration/v307rc2.php deleted file mode 100644 index 438ebfb8c2..0000000000 --- a/phpBB/includes/db/migration/v307rc2.php +++ /dev/null @@ -1,70 +0,0 @@ - ' . USER_IGNORE . " - AND user_email <> ''"; - $result = $this->db->sql_query_limit($sql, $limit, $start); - - $i = 0; - while ($row = $this->db->sql_fetchrow($result)) - { - $i++; - - // Snapshot of the phpbb_email_hash() function - // We cannot call it directly because the auto updater updates the DB first. :/ - $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); - - if ($user_email_hash != $row['user_email_hash']) - { - $sql_ary = array( - 'user_email_hash' => $user_email_hash, - ); - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_id = ' . (int) $row['user_id']; - $this->sql_query($sql); - } - } - $db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return false; - } - - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/v308.php b/phpBB/includes/db/migration/v308.php deleted file mode 100644 index 8a0d96b2e7..0000000000 --- a/phpBB/includes/db/migration/v308.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_POST_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_MESSAGES', - 'after' => array('message', 'ACP_MESSAGE_SETTINGS') - ), - )), - array('config.add', array('load_unreads_search', 1)), - array('config.update_if_equals', array(600, 'queue_interval', 60)), - array('config.update_if_equals', array(50, 'email_package_size', 20)), - ); - } - - function update_file_extension_group_names() - { - // Update file extension group names to use language strings. - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - $extension_groups_updated = array(); - while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) - { - $lang_dir = basename($lang_dir); - - // The language strings we need are either in language/.../acp/attachments.php - // in the update package if we're updating to 3.0.8-RC1 or later, - // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. - // On an already updated board, they can also already be in language/.../acp/attachments.php - // in the board root. - $lang_files = array( - "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", - ); - - foreach ($lang_files as $lang_file) - { - if (!file_exists($lang_file)) - { - continue; - } - - $lang = array(); - include($lang_file); - - foreach($lang as $lang_key => $lang_val) - { - if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) - { - continue; - } - - $sql_ary = array( - 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; - $this->sql_query($sql); - - $extension_groups_updated[$lang_key] = true; - } - } - } - $this->db->sql_freeresult($result); - } - - function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'avatar\''; - $this->sql_query($sql); - } - - function update_bots() - { - $bot_name = 'Bing [Bot]'; - $bot_name_clean = utf8_clean_string($bot_name); - - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; - $result = $this->db->sql_query($sql); - $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if (!$bing_already_added) - { - $bot_agent = 'bingbot/'; - $bot_ip = ''; - $sql = 'SELECT group_id, group_colour - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'BOTS'"; - $result = $this->db->sql_query($sql); - $group_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$group_row) - { - // default fallback, should never get here - $group_row['group_id'] = 6; - $group_row['group_colour'] = '9E8DA7'; - } - - if (!function_exists('user_add')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); - } - - $user_row = array( - 'user_type' => USER_IGNORE, - 'group_id' => $group_row['group_id'], - 'username' => $bot_name, - 'user_regdate' => time(), - 'user_password' => '', - 'user_colour' => $group_row['group_colour'], - 'user_email' => '', - 'user_lang' => $this->config['default_lang'], - 'user_style' => $this->config['default_style'], - 'user_timezone' => 0, - 'user_dateformat' => $this->config['default_dateformat'], - 'user_allow_massemail' => 0, - ); - - $user_id = user_add($user_row); - - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'bot_active' => 1, - 'bot_name' => (string) $bot_name, - 'user_id' => (int) $user_id, - 'bot_agent' => (string) $bot_agent, - 'bot_ip' => (string) $bot_ip, - )); - - $this->sql_query($sql); - } - } - - function delete_orphan_shadow_topics() - { - // Delete shadow topics pointing to not existing topics - $batch_size = 500; - - // Set of affected forums we have to resync - $sync_forum_ids = array(); - - $sql_array = array( - 'SELECT' => 't1.topic_id, t1.forum_id', - 'FROM' => array( - TOPICS_TABLE => 't1', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(TOPICS_TABLE => 't2'), - 'ON' => 't1.topic_moved_id = t2.topic_id', - ), - ), - 'WHERE' => 't1.topic_moved_id <> 0 - AND t2.topic_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - $result = $this->db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['topic_id']; - - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); - $this->db->sql_query($sql); - - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); - - return true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/v309.php b/phpBB/includes/db/migration/v309.php deleted file mode 100644 index ebb246da3a..0000000000 --- a/phpBB/includes/db/migration/v309.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'login_attempts' => array( - 'COLUMNS' => array( - // this column was removed from the database updater - // after 3.0.9-RC3 was released. It might still exist - // in 3.0.9-RCX installations and has to be dropped in - // 3.0.12 after the db_tools class is capable of properly - // removing a primary key. - // 'attempt_id' => array('UINT', NULL, 'auto_increment'), - 'attempt_ip' => array('VCHAR:40', ''), - 'attempt_browser' => array('VCHAR:150', ''), - 'attempt_forwarded_for' => array('VCHAR:255', ''), - 'attempt_time' => array('TIMESTAMP', 0), - 'user_id' => array('UINT', 0), - 'username' => array('VCHAR_UNI:255', 0), - 'username_clean' => array('VCHAR_CI', 0), - ), - //'PRIMARY_KEY' => 'attempt_id', - 'KEYS' => array( - 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), - 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), - 'att_time' => array('INDEX', array('attempt_time')), - 'user_id' => array('INDEX', 'user_id'), - ), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'bbcode' => array( - 'bbcode_id' => array('USINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('ip_login_limit_max', 50)), - array('config.add', array('ip_login_limit_time', 21600)), - array('config.add', array('ip_login_limit_use_forwarded', 0)), - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), - ); - } - - function update_file_extension_group_names() - { - // Update file extension group names to use language strings, again. - $sql = 'SELECT group_id, group_name - FROM ' . EXTENSION_GROUPS_TABLE . ' - WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - function fix_firebird_qa_captcha() - { - // Recover from potentially broken Q&A CAPTCHA table on firebird - // Q&A CAPTCHA was uninstallable, so it's safe to remove these - // without data loss - if ($this->db_tools->sql_layer == 'firebird') - { - $tables = array( - $this->table_prefix . 'captcha_questions', - $this->table_prefix . 'captcha_answers', - $this->table_prefix . 'qa_confirm', - ); - foreach ($tables as $table) - { - if ($this->db_tools->sql_table_exists($table)) - { - $this->db_tools->sql_table_drop($table); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/v309rc2.php b/phpBB/includes/db/migration/v309rc2.php deleted file mode 100644 index d552b95e7a..0000000000 --- a/phpBB/includes/db/migration/v309rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -db->sql_escape($config_name) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + if (!isset($this->config[$config_name])) + { + $this->config[$config_name] = $row['config_value']; + + if (!$row['is_dynamic']) + { + $this->cache->destroy('config'); + } + } + + return ($return_result) ? $row : true; + } + + // this should never happen, but if it does, we need to remove the config from the array + if (isset($this->config[$config_name])) + { + unset($this->config[$config_name]); + $this->cache->destroy('config'); + } + + return false; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_add($config_name, $config_value = '', $is_dynamic = false) + { + if ($this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_update($config_name, $config_value = '') + { + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + set_config($config_name, $config_value); + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + * + * @return result + */ + function config_remove($config_name) + { + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + $sql = 'DELETE FROM ' . CONFIG_TABLE . " + WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $this->db->sql_query($sql); + + unset($this->config[$config_name]); + $this->cache->destroy('config'); + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migrationtools/umil.php b/phpBB/includes/db/migrationtools/umil.php new file mode 100644 index 0000000000..ce7b8ff3be --- /dev/null +++ b/phpBB/includes/db/migrationtools/umil.php @@ -0,0 +1,3037 @@ +config_add(array( +* array('config_name', 'config_value'), +* array('config_name1', 'config_value1'), +* array('config_name2', 'config_value2', true), +* array('config_name3', 'config_value3', true), +* ); +*/ + +/** +* UMIL - Unified MOD Installation Library class +* +* Cache Functions +* cache_purge($type = '', $style_id = 0) +* +* Config Functions: +* config_exists($config_name, $return_result = false) +* config_add($config_name, $config_value = '', $is_dynamic = false) +* config_update($config_name, $config_value, $is_dynamic = false) +* config_remove($config_name) +* +* Module Functions +* module_exists($class, $parent, $module) +* module_add($class, $parent = 0, $data = array()) +* module_remove($class, $parent = 0, $module = '') +* +* Permissions/Auth Functions +* permission_exists($auth_option, $global = true) +* permission_add($auth_option, $global = true) +* permission_remove($auth_option, $global = true) +* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) +* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) +* +* Table Functions +* table_exists($table_name) +* table_add($table_name, $table_data = array()) +* table_remove($table_name) +* +* Table Column Functions +* table_column_exists($table_name, $column_name) +* table_column_add($table_name, $column_name = '', $column_data = array()) +* table_column_update($table_name, $column_name = '', $column_data = array()) +* table_column_remove($table_name, $column_name = '') +* +* Table Key/Index Functions +* table_index_exists($table_name, $index_name) +* table_index_add($table_name, $index_name = '', $column = array()) +* table_index_remove($table_name, $index_name = '') +* +* Table Row Functions (note that these actions are not reversed automatically during uninstallation) +* table_row_insert($table_name, $data = array()) +* table_row_remove($table_name, $data = array()) +* table_row_update($table_name, $data = array(), $new_data = array()) +* +* Version Check Function +* version_check($url, $path, $file) +*/ +class umil +{ + /** + * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) + * + * @var string + */ + var $command = ''; + + /** + * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. + * + * @var string + */ + var $result = ''; + + /** + * Auto run $this->display_results after running a command + */ + var $auto_display_results = false; + + /** + * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff + */ + var $stand_alone = false; + + /** + * Were any new permissions added (used in umil_frontend)? + */ + var $permissions_added = false; + + /** + * Database Object + */ + var $db = false; + + /** + * Database Tools Object + */ + var $db_tools = false; + + /** + * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... + */ + var $table_prefix = false; + + /** + * Constructor + */ + function umil($stand_alone = false, $db = false) + { + // Setup $this->db + if ($db !== false) + { + if (!is_object($db) || !method_exists($db, 'sql_query')) + { + trigger_error('Invalid $db Object'); + } + + $this->db = $db; + } + else + { + global $db; + $this->db = $db; + } + + // Setup $this->db_tools + if (!class_exists('phpbb_db_tools')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + $this->db_tools = new phpbb_db_tools($this->db); + + $this->stand_alone = $stand_alone; + + if (!$stand_alone) + { + global $config, $user, $phpbb_root_path, $phpEx; + + /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. + if (method_exists('user', 'set_custom_lang_path')) + { + $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); + $user->add_lang('umil'); + $user->set_custom_lang_path($phpbb_root_path . 'language/'); + } + else + {*/ + // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. + if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) + { + $path = $user->data['user_lang']; + } + else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) + { + $path = basename($config['default_lang']); + } + else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) + { + $path = 'en'; + } + else + { + trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); + } + + $user->add_lang('./../../umil/language/' . $path . '/umil'); + //} + + $user->add_lang(array('acp/common', 'acp/permissions')); + + // Check to see if a newer version is available. + $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); + if (is_array($info) && isset($info[0]) && isset($info[1])) + { + if (version_compare(UMIL_VERSION, $info[0], '<')) + { + global $template; + + // Make sure user->setup() has been called + if (empty($user->lang)) + { + $user->setup(); + } + + page_header('', false); + + $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; + $template->assign_vars(array( + 'S_BOARD_DISABLED' => true, + 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), + )); + } + } + } + } + + /** + * umil_start + * + * A function which runs (almost) every time a function here is ran + */ + function umil_start() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + $this->command = call_user_func_array(array($this, 'get_output_text'), $args); + + $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; + $this->db->sql_return_on_error(true); + + //$this->db->sql_transaction('begin'); + } + + /** + * umil_end + * + * A function which runs (almost) every time a function here is ran + */ + function umil_end() + { + global $user; + + // Set up the result. This will get the arguments sent to the function. + $args = func_get_args(); + $result = call_user_func_array(array($this, 'get_output_text'), $args); + $this->result = ($result) ? $result : $this->result; + + if ($this->db->sql_error_triggered) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; + } + else + { + $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; + } + + //$this->db->sql_transaction('rollback'); + } + else + { + //$this->db->sql_transaction('commit'); + } + + $this->db->sql_return_on_error(false); + + // Auto output if requested. + if ($this->auto_display_results && method_exists($this, 'display_results')) + { + $this->display_results(); + } + + return '' . $this->command . '
' . $this->result; + } + + /** + * Get text for output + * + * Takes the given arguments and prepares them for the UI + * + * First argument sent is used as the language key + * Further arguments (if send) are used on the language key through vsprintf() + * + * @return string Returns the prepared string for output + */ + function get_output_text() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + if (sizeof($args)) + { + $lang_key = array_shift($args); + + if (sizeof($args)) + { + $lang_args = array(); + foreach ($args as $arg) + { + $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; + } + + return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); + } + else + { + return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); + } + } + + return ''; + } + + /** + * Run Actions + * + * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. + * + * @param string $action The action. install|update|uninstall + * @param array $versions The array of versions and the actions for each + * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version + * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. + */ + function run_actions($action, $versions, $version_config_name, $version_select = '') + { + // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers + uksort($versions, 'version_compare'); + + // Find the current version to install + $current_version = '0.0.0'; + foreach ($versions as $version => $actions) + { + $current_version = $version; + } + + $db_version = ''; + if ($this->config_exists($version_config_name)) + { + global $config; + $db_version = $config[$version_config_name]; + } + + // Set the action to install from update if nothing is currently installed + if ($action == 'update' && !$db_version) + { + $action = 'install'; + } + + if ($action == 'install' || $action == 'update') + { + $version_installed = $db_version; + foreach ($versions as $version => $version_actions) + { + // If we are updating + if ($db_version && version_compare($version, $db_version, '<=')) + { + continue; + } + + if ($version_select && version_compare($version, $version_select, '>')) + { + break; + } + + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), $params); + } + } + } + + $version_installed = $version; + } + + // update the version number or add it + if ($this->config_exists($version_config_name)) + { + $this->config_update($version_config_name, $version_installed); + } + else + { + $this->config_add($version_config_name, $version_installed); + } + } + else if ($action == 'uninstall' && $db_version) + { + // reverse version list + $versions = array_reverse($versions); + + foreach ($versions as $version => $version_actions) + { + // Uninstalling and this listed version is newer than installed + if (version_compare($version, $db_version, '>')) + { + continue; + } + + // Version selection stuff + if ($version_select && version_compare($version, $version_select, '<=')) + { + // update the version number + $this->config_update($version_config_name, $version); + break; + } + + $cache_purge = false; + $version_actions = array_reverse($version_actions); + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). + if ($method == 'cache_purge') + { + $cache_purge = $params; + continue; + } + + // A few things are not possible for uninstallations update actions and table_row actions + if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) + { + continue; + } + + // reverse function call + $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); + $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); + + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); + } + } + } + + if ($cache_purge !== false) + { + $this->cache_purge($cache_purge); + } + } + + if (!$version_select) + { + // Unset the version number + $this->config_remove($version_config_name); + } + } + } + + /** + * Call custom function helper + */ + function _call_custom_function($functions, $action, $version) + { + if (!is_array($functions)) + { + $functions = array($functions); + } + + $return = ''; + + foreach ($functions as $function) + { + if (function_exists($function)) + { + // Must reset before calling the function + $this->umil_start(); + + $returned = call_user_func($function, $action, $version); + if (is_string($returned)) + { + $this->command = $this->get_output_text($returned); + } + else if (is_array($returned) && isset($returned['command'])) + { + if (is_array($returned['command'])) + { + $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); + } + else + { + $this->command = $this->get_output_text($returned['command']); + } + + if (isset($returned['result'])) + { + $this->result = $this->get_output_text($returned['result']); + } + } + else + { + $this->command = $this->get_output_text('UNKNOWN'); + } + + $return .= $this->umil_end() . '
'; + } + } + + return $return; + } + + /** + * Multicall Helper + * + * @param mixed $function Function name to call + * @param mixed $params The parameters array + * + * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) + */ + function multicall($function, $params) + { + if (is_array($params) && !empty($params)) + { + foreach ($params as $param) + { + if (!is_array($param)) + { + call_user_func(array($this, $function), $param); + } + else + { + call_user_func_array(array($this, $function), $param); + } + } + return true; + } + + return false; + } + + /** + * Cache Purge + * + * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. + * + * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. + * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) + */ + function cache_purge($type = '', $style_id = 0) + { + global $auth, $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $type)) + { + return; + } + + $style_id = (int) $style_id; + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'auth' : + $this->umil_start('AUTH_CACHE_PURGE'); + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + break; + + case 'imageset' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT imageset_id + FROM ' . STYLES_IMAGESET_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('imageset', $row['imageset_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_IMAGESET_TABLE . " + WHERE imageset_id = $style_id"; + $result = $this->db->sql_query($sql); + $imageset_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$imageset_row) + { + $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); + + // The following is from includes/acp/acp_styles.php (edited) + $sql_ary = array(); + + $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); + + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $style_id; + $result = $this->db->sql_query($sql); + + foreach ($cfg_data_imageset as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => '', + ); + } + } + + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) + { + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => (string) $row['lang_dir'], + ); + } + } + } + } + $this->db->sql_freeresult($result); + + $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); + + $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + + return $this->umil_end(); + } + break; + //case 'imageset' : + + case 'template' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT template_id + FROM ' . STYLES_TEMPLATE_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('template', $row['template_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_TEMPLATE_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + $template_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$template_row) + { + $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); + + // The following is from includes/acp/acp_styles.php + if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) + { + $filelist = array('' => array()); + + $sql = 'SELECT template_filename, template_mtime + FROM ' . STYLES_TEMPLATE_DATA_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { +// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) +// { + // get folder info from the filename + if (($slash_pos = strrpos($row['template_filename'], '/')) === false) + { + $filelist[''][] = $row['template_filename']; + } + else + { + $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); + } +// } + } + $this->db->sql_freeresult($result); + + $includes = array(); + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) + { + return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); + } + $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); + fclose($fp); + + if (preg_match_all('##is', $template_data, $matches)) + { + foreach ($matches[1] as $match) + { + $includes[trim($match)][] = $file; + } + } + } + } + + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + // Skip index. + if (strpos($file, 'index.') === 0) + { + continue; + } + + // We could do this using extended inserts ... but that could be one + // heck of a lot of data ... + $sql_ary = array( + 'template_id' => (int) $style_id, + 'template_filename' => "$pathfile$file", + 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', + 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + ); + + $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE template_id = $style_id + AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; + $this->db->sql_query($sql); + } + } + unset($filelist); + } + + // Purge the forum's cache as well. + $cache->purge(); + + return $this->umil_end(); + } + break; + //case 'template' : + + case 'theme' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT theme_id + FROM ' . STYLES_THEME_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('theme', $row['theme_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_THEME_TABLE . " + WHERE theme_id = $style_id"; + $result = $this->db->sql_query($sql); + $theme_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$theme_row) + { + $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); + + // The following is from includes/acp/acp_styles.php + if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) + { + $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); + + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + foreach ($matches[0] as $idx => $match) + { + if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) + { + continue; + } + + $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); + $stylesheet = str_replace($match, $content, $stylesheet); + } + } + + // adjust paths + $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); + + // Save CSS contents + $sql_ary = array( + 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), + 'theme_data' => $db_theme_data, + ); + + $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE theme_id = $style_id"; + $this->db->sql_query($sql); + + $cache->destroy('sql', STYLES_THEME_TABLE); + } + + return $this->umil_end(); + } + break; + //case 'theme' : + + default: + $this->umil_start('CACHE_PURGE'); + $cache->purge(); + + return $this->umil_end(); + break; + } + } + + /** + * Config Exists + * + * This function is to check to see if a config variable exists or if it does not. + * + * @param string $config_name The name of the config setting you wish to check for. + * @param bool $return_result - return the config value/default if true : default false. + * + * @return bool true/false if config exists + */ + function config_exists($config_name, $return_result = false) + { + global $config, $cache; + + $sql = 'SELECT * + FROM ' . CONFIG_TABLE . " + WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + if (!isset($config[$config_name])) + { + $config[$config_name] = $row['config_value']; + + if (!$row['is_dynamic']) + { + $cache->destroy('config'); + } + } + + return ($return_result) ? $row : true; + } + + // this should never happen, but if it does, we need to remove the config from the array + if (isset($config[$config_name])) + { + unset($config[$config_name]); + $cache->destroy('config'); + } + + return false; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_add($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_ADD', $config_name); + + if ($this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_update($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_UPDATE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + * + * @return result + */ + function config_remove($config_name) + { + global $cache, $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_REMOVE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $this->db->sql_query($sql); + + unset($config[$config_name]); + $cache->destroy('config'); + + return $this->umil_end(); + } + + /** + * Module Exists + * + * Check if a module exists + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + */ + function module_exists($class, $parent, $module) + { + // the main root directory should return true + if (!$module) + { + return true; + } + + $class = $this->db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_add($class, $parent = 0, $data = array(), $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Prevent stupid things like trying to add a module with no name or any data on it + if (empty($data)) + { + $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_ADD', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->module_exists($class, false, $parent)) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + if ($this->module_exists($class, $parent, $data['module_langname'])) + { + return $this->umil_end('MODULE_ALREADY_EXIST'); + } + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + $this->result = $this->get_output_text($result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_remove($class, $parent = 0, $module = '', $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->module_remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_REMOVE', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + $result = ''; + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $result .= $this->module_remove($class, $parent, $info['title']) . '
'; + } + } + return $result; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->module_exists($class, $parent, $module)) + { + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); + return $this->umil_end('MODULE_NOT_EXIST'); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = implode('
', $result); + } + else + { + $this->result .= '
' . implode('
', $result); + } + } + } + + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + } + + /** + * Permission Exists + * + * Check if a permission (auth) setting exists + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return bool true if it exists, false if not + */ + function permission_exists($auth_option, $global = true) + { + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_add($auth_option, $global = true) + { + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_ADD', $auth_option); + + if ($this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->permission_exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + return $this->umil_end(); + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_remove($auth_option, $global = true) + { + global $auth, $cache; + + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_REMOVE', $auth_option); + + if (!$this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + function permission_role_add($role_name, $role_type = '', $role_description = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_ADD', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' + WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + function permission_role_update($old_role_name, $new_role_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' + SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + function permission_role_remove($role_name) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_SET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_SET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_set($role_name, $auth_option, 'role', $has_permission); + } + + $this->umil_start('PERMISSION_SET_GROUP', $name); + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + function permission_unset($name, $auth_option = array(), $type = 'role') + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_UNSET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Table Exists + * + * Check if a table exists in the DB or not + * + * @param string $table_name The table name to check for + * + * @return bool true if the table exists, false if not + */ + function table_exists($table_name) + { + $this->get_table_name($table_name); + + // Use sql_table_exists if available + if (method_exists($this->db_tools, 'sql_table_exists')) + { + $roe = $this->db->return_on_error; + $result = $this->db_tools->sql_table_exists($table_name); + + // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before + if ($roe) + { + $this->db->sql_return_on_error(true); + } + + return $result; + } + + if (!function_exists('get_tables')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_install.' . $phpEx); + } + + $tables = get_tables($this->db); + + if (in_array($table_name, $tables)) + { + return true; + } + else + { + return false; + } + } + + /** + * Table Add + * + * This only supports input from the array format of db_tools or create_schema_files. + */ + function table_add($table_name, $table_data = array()) + { + global $dbms, $user; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error + */ + if (empty($table_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ADD', $table_name); + + if ($this->table_exists($table_name)) + { + return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); + } + + if (!is_array($table_data)) + { + return $this->umil_end('NO_TABLE_DATA'); + } + + if (!function_exists('get_available_dbms')) + { + global $phpbb_root_path, $phpEx; + include("{$phpbb_root_path}includes/functions_install.$phpEx"); + } + + /* + * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore + if (method_exists($this->db_tools, 'sql_create_table')) + { + // Added in 3.0.5 + $this->db_tools->sql_create_table($table_name, $table_data); + } + else + {*/ + $available_dbms = get_available_dbms($dbms); + + $sql_query = $this->create_table_sql($table_name, $table_data); + $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); + + foreach ($sql_query as $sql) + { + $this->db->sql_query($sql); + } + //} + + return $this->umil_end(); + } + + /** + * Table Remove + * + * Delete/Drop a DB table + */ + function table_remove($table_name) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_REMOVE', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + if (method_exists($this->db_tools, 'sql_table_drop')) + { + // Added in 3.0.5 + $this->db_tools->sql_table_drop($table_name); + } + else + { + $this->db->sql_query('DROP TABLE ' . $table_name); + } + + return $this->umil_end(); + } + + /** + * Table Column Exists + * + * Check to see if a column exists in a table + */ + function table_column_exists($table_name, $column_name) + { + $this->get_table_name($table_name); + + return $this->db_tools->sql_column_exists($table_name, $column_name); + } + + /** + * Table Column Add + * + * Add a new column to a table. + */ + function table_column_add($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error + */ + if (empty($column_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); + + if ($this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); + } + + $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Update + * + * Alter/Update a column in a table. You can not change a column name with this. + */ + function table_column_update($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_change($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Remove + * + * Remove a column from a table + */ + function table_column_remove($table_name, $column_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_remove($table_name, $column_name); + + return $this->umil_end(); + } + + /** + * Table Index Exists + * + * Check if a table key/index exists on a table (can not check primary or unique) + */ + function table_index_exists($table_name, $index_name) + { + $this->get_table_name($table_name); + + $indexes = $this->db_tools->sql_list_index($table_name); + + if (in_array($index_name, $indexes)) + { + return true; + } + + return false; + } + + /** + * Table Index Add + * + * Add a new key/index to a table + */ + function table_index_add($table_name, $index_name = '', $column = array()) + { + global $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + // Let them skip the column field and just use the index name in that case as the column as well + if (empty($column)) + { + $column = array($index_name); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); + + if ($this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); + } + + if (!is_array($column)) + { + $column = array($column); + } + + // remove index length if we are before 3.0.8 + // the feature (required for some types when using MySQL4) + // was added in that release (ticket PHPBB3-8944) + if (version_compare($config['version'], '3.0.7-pl1', '<=')) + { + $column = preg_replace('#:.*$#', '', $column); + } + + $this->db_tools->sql_create_index($table_name, $index_name, $column); + + return $this->umil_end(); + } + + /** + * Table Index Remove + * + * Remove a key/index from a table + */ + function table_index_remove($table_name, $index_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); + + if (!$this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); + } + + $this->db_tools->sql_index_drop($table_name, $index_name); + + return $this->umil_end(); + } + + // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility + function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } + + /** + * Table Insert + * + * Insert data into a table + */ + function table_row_insert($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $this->db->sql_multi_insert($table_name, $data); + + return $this->umil_end(); + } + + /** + * Table Row Update + * + * Update a row in a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + * + * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). + */ + function table_row_update($table_name, $data = array(), $new_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'UPDATE ' . $table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' + WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Table Row Remove + * + * Remove a row from a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + */ + function table_row_remove($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Version Checker + * + * Format the file like the following: + * http://www.phpbb.com/updatecheck/30x.txt + * + * @param string $url The url to access (ex: www.phpbb.com) + * @param string $path The path to access (ex: /updatecheck) + * @param string $file The name of the file to access (ex: 30x.txt) + * + * @return array|string Error Message if there was any error, or an array (each line in the file as a value) + */ + function version_check($url, $path, $file, $timeout = 10, $port = 80) + { + if (!function_exists('get_remote_file')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } + + $errstr = $errno = ''; + + $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); + + if ($info === false) + { + return $errstr . ' [ ' . $errno . ' ]'; + } + + $info = str_replace("\r\n", "\n", $info); + $info = explode("\n", $info); + + return $info; + } + + /** + * Create table SQL + * + * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array + * + * @param string $table_name The name of the table + * @param array $table_data The table data (formatted in the array format used by create_schema_files) + * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) + * + * @return The sql query to run for the submitted dbms to insert the table + */ + function create_table_sql($table_name, $table_data, $dbms = '') + { + // To allow testing + $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; + + // A list of types being unsigned for better reference in some db's + $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); + $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); + + $sql = ''; + + // Create Table statement + $generator = $textimage = false; + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'firebird': + case 'oracle': + case 'sqlite': + case 'postgres': + $sql .= "CREATE TABLE {$table_name} (\n"; + break; + + case 'mssql': + $sql .= "CREATE TABLE [{$table_name}] (\n"; + break; + } + + // Table specific so we don't get overlap + $modded_array = array(); + + // Write columns one by one... + foreach ($table_data['COLUMNS'] as $column_name => $column_data) + { + // Get type + if (strpos($column_data[0], ':') !== false) + { + list($orig_column_type, $column_length) = explode(':', $column_data[0]); + if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); + } + else + { + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) + { + case 'div': + $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; + $column_length = ceil($column_length); + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + break; + } + } + + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) + { + case 'mult': + $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; + if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) + { + $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; + $modded_array[$column_name] = $column_type; + } + else + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + } + break; + } + } + } + $orig_column_type .= ':'; + } + else + { + $orig_column_type = $column_data[0]; + $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; + if ($column_type == 'text' || $column_type == 'blob') + { + $modded_array[$column_name] = $column_type; + } + } + + // Adjust default value if db-dependant specified + if (is_array($column_data[1])) + { + $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= "\t{$column_name} {$column_type} "; + + // For hexadecimal values do not use single quotes + if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') + { + $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; + } + $sql .= 'NOT NULL'; + + if (isset($column_data[2])) + { + if ($column_data[2] == 'auto_increment') + { + $sql .= ' auto_increment'; + } + else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') + { + $sql .= ' COLLATE utf8_unicode_ci'; + } + } + + $sql .= ",\n"; + break; + + case 'sqlite': + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; + $generator = $column_name; + } + else + { + $sql .= "\t{$column_name} {$column_type} "; + } + + $sql .= 'NOT NULL '; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; + $sql .= ",\n"; + break; + + case 'firebird': + $sql .= "\t{$column_name} {$column_type} "; + + if (!is_null($column_data[1])) + { + $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; + } + + $sql .= 'NOT NULL'; + + // This is a UNICODE column and thus should be given it's fair share + if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) + { + $sql .= ' COLLATE UNICODE'; + } + + $sql .= ",\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'mssql': + if ($column_type == '[text]') + { + $textimage = true; + } + + $sql .= "\t[{$column_name}] {$column_type} "; + + if (!is_null($column_data[1])) + { + // For hexadecimal values do not use single quotes + if (strpos($column_data[1], '0x') === 0) + { + $sql .= 'DEFAULT (' . $column_data[1] . ') '; + } + else + { + $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; + } + } + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= 'IDENTITY (1, 1) '; + } + + $sql .= 'NOT NULL'; + $sql .= " ,\n"; + break; + + case 'oracle': + $sql .= "\t{$column_name} {$column_type} "; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + + // In Oracle empty strings ('') are treated as NULL. + // Therefore in oracle we allow NULL's for all DEFAULT '' entries + $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'postgres': + $sql .= "\t{$column_name} {$column_type} "; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; + + // Make sure the sequence will be created before creating the table + $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; + } + else + { + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + $sql .= "NOT NULL"; + + // Unsigned? Then add a CHECK contraint + if (in_array($orig_column_type, $unsigned_types)) + { + $sql .= " CHECK ({$column_name} >= 0)"; + } + + $sql .= ",\n"; + } + break; + } + } + + switch ($dbms) + { + case 'firebird': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);;\n\n"; + break; + + case 'mssql': + $sql = substr($sql, 0, -2); + $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; + $sql .= "GO\n\n"; + break; + } + + // Write primary key + if (isset($table_data['PRIMARY_KEY'])) + { + if (!is_array($table_data['PRIMARY_KEY'])) + { + $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'postgres': + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + + case 'firebird': + $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; + break; + + case 'sqlite': + if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) + { + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + } + break; + + case 'mssql': + $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; + $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; + $sql .= "\t(\n"; + $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; + $sql .= "\t) ON [PRIMARY] \n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + } + } + + switch ($dbms) + { + case 'oracle': + // UNIQUE contrains to be added? + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + if ($key_data[0] == 'UNIQUE') + { + $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; + } + } + } + + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n)\n/\n\n"; + break; + + case 'postgres': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'sqlite': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + } + + // Write Keys + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; + foreach ($key_data[1] as $key => $col_name) + { + if (isset($modded_array[$col_name])) + { + switch ($modded_array[$col_name]) + { + case 'text': + case 'blob': + $key_data[1][$key] = $col_name . '(255)'; + break; + } + } + } + $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; + break; + + case 'firebird': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; + break; + + case 'mssql': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + if ($key_data[0] == 'UNIQUE') + { + continue; + } + + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; + $sql .= "/\n"; + break; + + case 'sqlite': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + + case 'postgres': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + } + } + } + + switch ($dbms) + { + case 'mysql_40': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'mysql_41': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; + break; + + // Create Generator + case 'firebird': + if ($generator !== false) + { + $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; + $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; + + $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; + $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; + $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; + } + break; + + case 'oracle': + if ($generator !== false) + { + $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; + + $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; + $sql .= "BEFORE INSERT ON {$table_name}\n"; + $sql .= "FOR EACH ROW WHEN (\n"; + $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; + $sql .= ")\nBEGIN\n"; + $sql .= "\tSELECT {$table_name}_seq.nextval\n"; + $sql .= "\tINTO :new.{$generator}\n"; + $sql .= "\tFROM dual;\nEND;\n/\n\n"; + } + break; + } + + return $sql; + } + + /** + * Get the real table name + * By A_Jelly_Doughnut + * + * @param string $table_name The table name to get the real table name from + */ + function get_table_name(&$table_name) + { + // Use the global table prefix if a custom one is not specified + if ($this->table_prefix === false) + { + global $table_prefix; + } + else + { + $table_prefix = $this->table_prefix; + } + + static $constants = NULL; + + if (is_null($constants)) + { + $constants = get_defined_constants(); + } + + /** + * only do the replace if the table prefix is not already present + * this is required since UMIL supports specifying a table via phpbb_foo + * (where a replace would be needed) + * or by FOO_TABLE (where a replace is already done at constant-define time) + */ + if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) + { + $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); + } + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From 91a921a96bf26607879de850fca105be78eadf1d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 09:43:07 +0100 Subject: [feature/migrations] Change migration data processing to run step by step --- phpBB/includes/db/migrator.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4ce54a4b92..912a7b34ba 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -167,7 +167,7 @@ class phpbb_db_migrator } else { - $migration->update_data(); + $this->process_data_step($migration); $state['migration_data_done'] = true; $state['migration_end_time'] = time(); } @@ -182,6 +182,28 @@ class phpbb_db_migrator return true; } + function process_data_step(&$migration) + { + $continue = false; + $steps = $migration->update_data(); + + foreach ($steps as $step) + { + $continue = $this->run_step($step); + if (!$continue) + { + return false; + } + } + + return $continue; + } + + function run_step(&$step) + { + + } + function insert_migration($name, $state) { $migration_row = $state; -- cgit v1.2.1 From 82efb3e446efbb8ef05c6a777e3866901abfd07a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:12 -0600 Subject: [feature/migrations] Remove references as it is now 3.1 code PHPBB3-9737 --- phpBB/includes/db/migration.php | 6 +- phpBB/includes/db/migration/3_0_1.php | 25 - phpBB/includes/db/migration/3_0_10.php | 25 - phpBB/includes/db/migration/3_0_10_rc1.php | 28 - phpBB/includes/db/migration/3_0_10_rc2.php | 25 - phpBB/includes/db/migration/3_0_10_rc3.php | 25 - phpBB/includes/db/migration/3_0_11.php | 25 - phpBB/includes/db/migration/3_0_11_rc1.php | 96 - phpBB/includes/db/migration/3_0_11_rc2 | 31 - phpBB/includes/db/migration/3_0_12_rc1.php | 26 - phpBB/includes/db/migration/3_0_1_rc1.php | 77 - phpBB/includes/db/migration/3_0_2.php | 25 - phpBB/includes/db/migration/3_0_2_rc1.php | 30 - phpBB/includes/db/migration/3_0_2_rc2.php | 52 - phpBB/includes/db/migration/3_0_3.php | 25 - phpBB/includes/db/migration/3_0_3_rc1.php | 61 - phpBB/includes/db/migration/3_0_4.php | 47 - phpBB/includes/db/migration/3_0_4_rc1.php | 103 - phpBB/includes/db/migration/3_0_5.php | 25 - phpBB/includes/db/migration/3_0_5_rc1.php | 119 - phpBB/includes/db/migration/3_0_5_rc1part2.php | 34 - phpBB/includes/db/migration/3_0_6.php | 25 - phpBB/includes/db/migration/3_0_6_rc1.php | 314 -- phpBB/includes/db/migration/3_0_6_rc2.php | 25 - phpBB/includes/db/migration/3_0_6_rc3.php | 38 - phpBB/includes/db/migration/3_0_6_rc4.php | 25 - phpBB/includes/db/migration/3_0_7.php | 25 - phpBB/includes/db/migration/3_0_7_pl1.php | 25 - phpBB/includes/db/migration/3_0_7_rc1.php | 51 - phpBB/includes/db/migration/3_0_7_rc2.php | 70 - phpBB/includes/db/migration/3_0_8.php | 25 - phpBB/includes/db/migration/3_0_8_rc1.php | 225 -- phpBB/includes/db/migration/3_0_9.php | 25 - phpBB/includes/db/migration/3_0_9_rc1.php | 108 - phpBB/includes/db/migration/3_0_9_rc2.php | 25 - phpBB/includes/db/migration/3_0_9_rc3.php | 25 - phpBB/includes/db/migration/3_0_9_rc4.php | 25 - phpBB/includes/db/migration/data/3_0_1.php | 25 + phpBB/includes/db/migration/data/3_0_10.php | 25 + phpBB/includes/db/migration/data/3_0_10_rc1.php | 28 + phpBB/includes/db/migration/data/3_0_10_rc2.php | 25 + phpBB/includes/db/migration/data/3_0_10_rc3.php | 25 + phpBB/includes/db/migration/data/3_0_11.php | 25 + phpBB/includes/db/migration/data/3_0_11_rc1.php | 96 + phpBB/includes/db/migration/data/3_0_11_rc2 | 31 + phpBB/includes/db/migration/data/3_0_12_rc1.php | 26 + phpBB/includes/db/migration/data/3_0_1_rc1.php | 77 + phpBB/includes/db/migration/data/3_0_2.php | 25 + phpBB/includes/db/migration/data/3_0_2_rc1.php | 30 + phpBB/includes/db/migration/data/3_0_2_rc2.php | 52 + phpBB/includes/db/migration/data/3_0_3.php | 25 + phpBB/includes/db/migration/data/3_0_3_rc1.php | 61 + phpBB/includes/db/migration/data/3_0_4.php | 47 + phpBB/includes/db/migration/data/3_0_4_rc1.php | 103 + phpBB/includes/db/migration/data/3_0_5.php | 25 + phpBB/includes/db/migration/data/3_0_5_rc1.php | 119 + .../includes/db/migration/data/3_0_5_rc1part2.php | 34 + phpBB/includes/db/migration/data/3_0_6.php | 25 + phpBB/includes/db/migration/data/3_0_6_rc1.php | 299 ++ phpBB/includes/db/migration/data/3_0_6_rc2.php | 25 + phpBB/includes/db/migration/data/3_0_6_rc3.php | 38 + phpBB/includes/db/migration/data/3_0_6_rc4.php | 25 + phpBB/includes/db/migration/data/3_0_7.php | 25 + phpBB/includes/db/migration/data/3_0_7_pl1.php | 25 + phpBB/includes/db/migration/data/3_0_7_rc1.php | 51 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 70 + phpBB/includes/db/migration/data/3_0_8.php | 25 + phpBB/includes/db/migration/data/3_0_8_rc1.php | 223 ++ phpBB/includes/db/migration/data/3_0_9.php | 25 + phpBB/includes/db/migration/data/3_0_9_rc1.php | 108 + phpBB/includes/db/migration/data/3_0_9_rc2.php | 25 + phpBB/includes/db/migration/data/3_0_9_rc3.php | 25 + phpBB/includes/db/migration/data/3_0_9_rc4.php | 25 + phpBB/includes/db/migration/tools/base.php | 47 + phpBB/includes/db/migration/tools/config.php | 106 + phpBB/includes/db/migration/tools/module.php | 419 +++ phpBB/includes/db/migration/tools/permission.php | 480 ++++ phpBB/includes/db/migration/tools/umil.php | 3037 ++++++++++++++++++++ phpBB/includes/db/migrationtools/base.php | 15 - phpBB/includes/db/migrationtools/config.php | 121 - phpBB/includes/db/migrationtools/umil.php | 3037 -------------------- phpBB/includes/db/migrator.php | 14 +- 82 files changed, 6042 insertions(+), 5143 deletions(-) delete mode 100644 phpBB/includes/db/migration/3_0_1.php delete mode 100644 phpBB/includes/db/migration/3_0_10.php delete mode 100644 phpBB/includes/db/migration/3_0_10_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_10_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_10_rc3.php delete mode 100644 phpBB/includes/db/migration/3_0_11.php delete mode 100644 phpBB/includes/db/migration/3_0_11_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_11_rc2 delete mode 100644 phpBB/includes/db/migration/3_0_12_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_1_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_2.php delete mode 100644 phpBB/includes/db/migration/3_0_2_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_2_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_3.php delete mode 100644 phpBB/includes/db/migration/3_0_3_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_4.php delete mode 100644 phpBB/includes/db/migration/3_0_4_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_5.php delete mode 100644 phpBB/includes/db/migration/3_0_5_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_5_rc1part2.php delete mode 100644 phpBB/includes/db/migration/3_0_6.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc3.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc4.php delete mode 100644 phpBB/includes/db/migration/3_0_7.php delete mode 100644 phpBB/includes/db/migration/3_0_7_pl1.php delete mode 100644 phpBB/includes/db/migration/3_0_7_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_7_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_8.php delete mode 100644 phpBB/includes/db/migration/3_0_8_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_9.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc3.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc4.php create mode 100644 phpBB/includes/db/migration/data/3_0_1.php create mode 100644 phpBB/includes/db/migration/data/3_0_10.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_11.php create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2 create mode 100644 phpBB/includes/db/migration/data/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_2.php create mode 100644 phpBB/includes/db/migration/data/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_3.php create mode 100644 phpBB/includes/db/migration/data/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_4.php create mode 100644 phpBB/includes/db/migration/data/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_5.php create mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/data/3_0_6.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/data/3_0_7.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_8.php create mode 100644 phpBB/includes/db/migration/data/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_9.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc4.php create mode 100644 phpBB/includes/db/migration/tools/base.php create mode 100644 phpBB/includes/db/migration/tools/config.php create mode 100644 phpBB/includes/db/migration/tools/module.php create mode 100644 phpBB/includes/db/migration/tools/permission.php create mode 100644 phpBB/includes/db/migration/tools/umil.php delete mode 100644 phpBB/includes/db/migrationtools/base.php delete mode 100644 phpBB/includes/db/migrationtools/config.php delete mode 100644 phpBB/includes/db/migrationtools/umil.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index de9f6d07e3..c98ac8728a 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -44,10 +44,10 @@ class phpbb_db_migration * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migration(&$db, &$db_tools, $table_prefix, $phpbb_root_path, $php_ext) + function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) { - $this->db = &$db; - $this->db_tools = &$db_tools; + $this->db = $db; + $this->db_tools = $db_tools; $this->table_prefix = $table_prefix; $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/db/migration/3_0_1.php b/phpBB/includes/db/migration/3_0_1.php deleted file mode 100644 index 1cb069a2b1..0000000000 --- a/phpBB/includes/db/migration/3_0_1.php +++ /dev/null @@ -1,25 +0,0 @@ -sql_query($sql); - - $deactivated_style_ids = array(); - while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) - { - $deactivated_style_ids[] = (int) $style_id; - } - $this->db->sql_freeresult($result); - - if (!empty($deactivated_style_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->config['default_style'] .' - WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); - $this->sql_query($sql); - } - } - - function delete_orphan_private_messages() - { - // Delete orphan private messages - $batch_size = 500; - - $sql_array = array( - 'SELECT' => 'p.msg_id', - 'FROM' => array( - PRIVMSGS_TABLE => 'p', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), - 'ON' => 'p.msg_id = t.msg_id', - ), - ), - 'WHERE' => 't.user_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - - $result = $this->db->sql_query_limit($sql, $batch_size); - - $delete_pms = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $db->sql_freeresult($result); - - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql); - - return true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/3_0_11_rc2 b/phpBB/includes/db/migration/3_0_11_rc2 deleted file mode 100644 index f4e64871ed..0000000000 --- a/phpBB/includes/db/migration/3_0_11_rc2 +++ /dev/null @@ -1,31 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_12_rc1.php b/phpBB/includes/db/migration/3_0_12_rc1.php deleted file mode 100644 index 58e112a43a..0000000000 --- a/phpBB/includes/db/migration/3_0_12_rc1.php +++ /dev/null @@ -1,26 +0,0 @@ - array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list' => array('BOOL', 1), - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('UINT', 0), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'groups' => array('group_legend'), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('session_forum_id'), - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name' => array('group_legend', 'group_name'), - ), - ), - ); - } - - function update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - ); - } - - function fix_unset_last_view_time() - { - $sql = 'UPDATE ' . $this->table_prefix . "topics - SET topic_last_view_time = topic_last_post_time - WHERE topic_last_view_time = 0"; - $this->sql_query($sql); - } - - function reset_smiley_size() - { - // Update smiley sizes - $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); - - foreach ($smileys as $smiley) - { - if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) - { - list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); - - $sql = 'UPDATE ' . SMILIES_TABLE . ' - SET smiley_width = ' . $width . ', smiley_height = ' . $height . " - WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; - - $this->sql_query($sql); - } - } - } -} diff --git a/phpBB/includes/db/migration/3_0_2.php b/phpBB/includes/db/migration/3_0_2.php deleted file mode 100644 index 36e8d52e6b..0000000000 --- a/phpBB/includes/db/migration/3_0_2.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'drafts' => array( - 'draft_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'forums' => array( - 'forum_last_post_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'posts' => array( - 'post_subject' => array('STEXT_UNI', '', 'true_sort'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'topics' => array( - 'topic_title' => array('STEXT_UNI', '', 'true_sort'), - 'topic_last_post_subject' => array('STEXT_UNI', ''), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid' => array('session_forum_id'), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_3.php b/phpBB/includes/db/migration/3_0_3.php deleted file mode 100644 index c9ca33ee88..0000000000 --- a/phpBB/includes/db/migration/3_0_3.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('enable_queue_trigger', '0')), - array('config.add', array('queue_trigger_posts', '3')), - array('config.add', array('pm_max_recipients', '0')), - array('custom', array(array(&$this, 'set_group_default_max_recipients'))), - array('config.add', array('dbms_version', '')), - array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - )); - } - - function correct_acp_email_permissions() - { - $sql = 'UPDATE ' . $this->table_prefix . 'modules - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - $this->sql_query($sql); - } - - function set_group_default_max_recipients() - { - // Set maximum number of recipients for the registered users, bots, guests group - $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 - WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/3_0_4.php b/phpBB/includes/db/migration/3_0_4.php deleted file mode 100644 index bbaaea54c9..0000000000 --- a/phpBB/includes/db/migration/3_0_4.php +++ /dev/null @@ -1,47 +0,0 @@ -sql_layer == 'oracle') - { - // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation = 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - } -} diff --git a/phpBB/includes/db/migration/3_0_4_rc1.php b/phpBB/includes/db/migration/3_0_4_rc1.php deleted file mode 100644 index b783e58e24..0000000000 --- a/phpBB/includes/db/migration/3_0_4_rc1.php +++ /dev/null @@ -1,103 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile' => array('BOOL', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'styles' => array( - 'style_id' => array('UINT', NULL, 'auto_increment'), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_imageset' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_theme' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template_data' => array( - 'template_id' => array('UINT', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_style' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('custom', array(array(&$this, 'update_custom_profile_fields'))), - ); - } - - function update_custom_profile_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide - FROM ' . PROFILE_FIELDS_TABLE; - $result = $this->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'field_required' => 0, - 'field_show_on_reg' => 0, - 'field_hide' => 0, - 'field_show_profile'=> 0, - ); - - if ($row['field_required']) - { - $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_show_on_reg']) - { - $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_hide']) - { - // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module - $sql_ary['field_hide'] = 1; - } - else - { - // equivelant to "none", which is the "Display in user control panel" option - $sql_ary['field_show_profile'] = 1; - } - - $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); - } - } -} diff --git a/phpBB/includes/db/migration/3_0_5.php b/phpBB/includes/db/migration/3_0_5.php deleted file mode 100644 index 272779f083..0000000000 --- a/phpBB/includes/db/migration/3_0_5.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - $search_indexing_state = $this->config['search_indexing_state']; - - return array( - array('config.add', array('captcha_gd_wave', 0)), - array('config.add', array('captcha_gd_3d_noise', 1)), - array('config.add', array('captcha_gd_refresh', 1)), - array('config.add', array('confirm_refresh', 1)), - array('config.add', array('max_num_search_keywords', 10)), - array('config.remove', array('search_indexing_state')), - array('config.add', array('search_indexing_state', $search_indexing_state, true)), - array('custom', array(array(&$this, 'hash_old_passwords'))), - array('custom', array(array(&$this, 'update_ichiro_bot'))), - ); - } - - function hash_old_passwords() - { - $sql = 'SELECT user_id, user_password - FROM ' . $this->table_prefix . 'users - WHERE user_pass_convert = 1'; - $result = $this->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (strlen($row['user_password']) == 32) - { - $sql_ary = array( - 'user_password' => phpbb_hash($row['user_password']), - ); - - $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); - } - } - $db->sql_freeresult($result); - } - - function update_ichiro_bot() - { - // Adjust bot entry - $sql = 'UPDATE ' . $this->table_prefix . "bots - SET bot_agent = 'ichiro/' - WHERE bot_agent = 'ichiro/2'"; - $this->sql_query($sql); - } - - function remove_duplicate_auth_options() - { - // Before we are able to add a unique key to auth_option, we need to remove duplicate entries - $sql = 'SELECT auth_option - FROM ' . $this->table_prefix . 'acl_options - GROUP BY auth_option - HAVING COUNT(*) >= 2'; - $result = $this->db->sql_query($sql); - - $auth_options = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $auth_options[] = $row['auth_option']; - } - $this->db->sql_freeresult($result); - - // Remove specific auth options - if (!empty($auth_options)) - { - foreach ($auth_options as $option) - { - // Select auth_option_ids... the largest id will be preserved - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $db->sql_escape($option) . "' - ORDER BY auth_option_id DESC"; - // sql_query_limit not possible here, due to bug in postgresql layer - $result = $this->sql_query($sql); - - // Skip first row, this is our original auth option we want to preserve - $row = $this->db->sql_fetchrow($result); - - while ($row = $this->db->sql_fetchrow($result)) - { - // Ok, remove this auth option... - $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - } - $this->db->sql_freeresult($result); - } - } - } -} diff --git a/phpBB/includes/db/migration/3_0_5_rc1part2.php b/phpBB/includes/db/migration/3_0_5_rc1part2.php deleted file mode 100644 index 710c8dce91..0000000000 --- a/phpBB/includes/db/migration/3_0_5_rc1part2.php +++ /dev/null @@ -1,34 +0,0 @@ - array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_6.php b/phpBB/includes/db/migration/3_0_6.php deleted file mode 100644 index 9582038b36..0000000000 --- a/phpBB/includes/db/migration/3_0_6.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'confirm' => array( - 'attempts' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_new' => array('BOOL', 1), - 'user_reminded' => array('TINT:4', 0), - 'user_reminded_time' => array('TIMESTAMP', 0), - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported' => array('BOOL', 0), - ), - $this->table_prefix . 'reports' => array( - 'pm_id' => array('UINT', 0), - ), - $this->table_prefix . 'fields' => array( - 'field_show_on_vt' => array('BOOL', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_options' => array('UINT:20', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_options' => array('UINT:11', 230271), - ), - ), - 'add_index' => array( - $this->table_prefix . 'reports' => array( - 'post_id' => array('post_id'), - 'pm_id' => array('pm_id'), - ), - $this->table_prefix . 'posts' => array( - 'post_username' => array('post_username:255'), - ), - ), - ); - } - - function update_data() - { - return array( - //array('custom', array(array(&$this, ''))) - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('config.update_if', array( - ($this->config['captcha_gd']), - 'captcha_plugin', - 'phpbb_captcha_gd', - )), - - array('config.add', array('feed_enable', 0)), - array('config.add', array('feed_limit', 10)), - array('config.add', array('feed_overall_forums', 1)), - array('config.add', array('feed_overall_forums_limit', 15)), - array('config.add', array('feed_overall_topics', 0)), - array('config.add', array('feed_overall_topics_limit', 15)), - array('config.add', array('feed_forum', 1)), - array('config.add', array('feed_topic', 1)), - array('config.add', array('feed_item_statistics', 1)), - - array('config.add', array('smilies_per_page', 50)), - array('config.add', array('allow_pm_report', 1)), - array('config.add', array('min_post_chars', 1)), - array('config.add', array('allow_quick_reply', 1)), - array('config.add', array('new_member_post_limit', 0)), - array('config.add', array('new_member_group_default', 0)), - array('config.add', array('delete_time', $this->config['edit_time'])), - - array('config.add', array('allow_avatar', 0)), - array('config.add_if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - 'allow_avatar', - 1, - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('config.add_if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - 'allow_avatar_remote_upload', - 1, - )), - - array('module.add', array( - 'feed' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_FEED_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_BOARD_CONFIGURATION', - 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') - ), - )), - array('module.add', array( - 'warnings' => array( - 'base' => 'users', - 'class' => 'acp', - 'title' => 'ACP_USER_WARNINGS', - 'auth' => 'acl_a_user', - 'display' => 0, - 'cat' => 'ACP_CAT_USERS', - 'after' => array('feedback', 'ACP_USER_FEEDBACK') - ), - )), - array('module.add', array( - 'send_statistics' => array( - 'base' => 'send_statistics', - 'class' => 'acp', - 'title' => 'ACP_SEND_STATISTICS', - 'auth' => 'acl_a_server', - 'cat' => 'ACP_SERVER_CONFIGURATION' - ), - )), - array('module.add', array( - 'setting_forum_copy' => array( - 'base' => 'permissions', - 'class' => 'acp', - 'title' => 'ACP_FORUM_PERMISSIONS_COPY', - 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', - 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', - 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') - ), - )), - array('module.add', array( - 'pm_reports' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_OPEN', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_reports_closed' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_CLOSED', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_report_details' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORT_DETAILS', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - ); - } - - function set_user_options_default() - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - $this->sql_query($sql); - } - - function add_newly_registered_group() - { - // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'NEWLY_REGISTERED'"; - $result = $this->db->sql_query($sql); - $group_id = (int) $this->db->sql_fetchfield('group_id'); - $this->db->sql_freeresult($result); - - if (!$group_id) - { - $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; - $this->sql_query($sql); - - $group_id = $this->db->sql_nextid(); - } - - // Insert new user role... at the end of the chain - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_USER_NEW_MEMBER' - AND role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $u_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$u_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; - $this->sql_query($sql); - $u_role = $this->db->sql_nextid(); - - if (!$errored) - { - // Now add the correct data to the roles... - // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - $this->sql_query($sql); - - // Add user role to group - $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - $this->sql_query($sql); - } - } - - // Insert new forum role - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' - AND role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $f_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$f_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; - $this->sql_query($sql); - $f_role = $this->db->sql_nextid(); - - if (!$errored) - { - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - $this->sql_query($sql); - } - } - - // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) - $sql = 'SELECT 1 - FROM ' . USERS_TABLE . ' - WHERE user_new = 0'; - $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; - $this->sql_query($sql); - } - - // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... - // Check if the role is already assigned... - $sql = 'SELECT forum_id - FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id = ' . $f_role; - $result = $this->db->sql_query($sql); - $is_options = (int) $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - // Not assigned at all... :/ - if (!$is_options) - { - // Get postable forums - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type != ' . FORUM_LINK; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); - } - $this->db->sql_freeresult($result); - } - - // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/3_0_6_rc2.php b/phpBB/includes/db/migration/3_0_6_rc2.php deleted file mode 100644 index 1552485d0a..0000000000 --- a/phpBB/includes/db/migration/3_0_6_rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/3_0_6_rc4.php b/phpBB/includes/db/migration/3_0_6_rc4.php deleted file mode 100644 index 00161456b6..0000000000 --- a/phpBB/includes/db/migration/3_0_6_rc4.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'log' => array('log_time'), - ), - 'add_index' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id' => array('topic_id'), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('feed_overall', 1)), - array('config.add', array('feed_http_auth', 0)), - array('config.add', array('feed_limit_post', $this->config['feed_limit'])), - array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), - array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), - array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), - array('custom', array(array(&$this, 'delete_text_templates'))), - ); - } - - function delete_text_templates() - { - // Delete all text-templates from the template_data - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/3_0_7_rc2.php b/phpBB/includes/db/migration/3_0_7_rc2.php deleted file mode 100644 index 4ab4e906d7..0000000000 --- a/phpBB/includes/db/migration/3_0_7_rc2.php +++ /dev/null @@ -1,70 +0,0 @@ - ' . USER_IGNORE . " - AND user_email <> ''"; - $result = $this->db->sql_query_limit($sql, $limit, $start); - - $i = 0; - while ($row = $this->db->sql_fetchrow($result)) - { - $i++; - - // Snapshot of the phpbb_email_hash() function - // We cannot call it directly because the auto updater updates the DB first. :/ - $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); - - if ($user_email_hash != $row['user_email_hash']) - { - $sql_ary = array( - 'user_email_hash' => $user_email_hash, - ); - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_id = ' . (int) $row['user_id']; - $this->sql_query($sql); - } - } - $db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return false; - } - - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/3_0_8.php b/phpBB/includes/db/migration/3_0_8.php deleted file mode 100644 index 3e7f843a65..0000000000 --- a/phpBB/includes/db/migration/3_0_8.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_POST_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_MESSAGES', - 'after' => array('message', 'ACP_MESSAGE_SETTINGS') - ), - )), - array('config.add', array('load_unreads_search', 1)), - array('config.update_if_equals', array(600, 'queue_interval', 60)), - array('config.update_if_equals', array(50, 'email_package_size', 20)), - ); - } - - function update_file_extension_group_names() - { - // Update file extension group names to use language strings. - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - $extension_groups_updated = array(); - while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) - { - $lang_dir = basename($lang_dir); - - // The language strings we need are either in language/.../acp/attachments.php - // in the update package if we're updating to 3.0.8-RC1 or later, - // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. - // On an already updated board, they can also already be in language/.../acp/attachments.php - // in the board root. - $lang_files = array( - "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", - ); - - foreach ($lang_files as $lang_file) - { - if (!file_exists($lang_file)) - { - continue; - } - - $lang = array(); - include($lang_file); - - foreach($lang as $lang_key => $lang_val) - { - if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) - { - continue; - } - - $sql_ary = array( - 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; - $this->sql_query($sql); - - $extension_groups_updated[$lang_key] = true; - } - } - } - $this->db->sql_freeresult($result); - } - - function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'avatar\''; - $this->sql_query($sql); - } - - function update_bots() - { - $bot_name = 'Bing [Bot]'; - $bot_name_clean = utf8_clean_string($bot_name); - - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; - $result = $this->db->sql_query($sql); - $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if (!$bing_already_added) - { - $bot_agent = 'bingbot/'; - $bot_ip = ''; - $sql = 'SELECT group_id, group_colour - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'BOTS'"; - $result = $this->db->sql_query($sql); - $group_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$group_row) - { - // default fallback, should never get here - $group_row['group_id'] = 6; - $group_row['group_colour'] = '9E8DA7'; - } - - if (!function_exists('user_add')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); - } - - $user_row = array( - 'user_type' => USER_IGNORE, - 'group_id' => $group_row['group_id'], - 'username' => $bot_name, - 'user_regdate' => time(), - 'user_password' => '', - 'user_colour' => $group_row['group_colour'], - 'user_email' => '', - 'user_lang' => $this->config['default_lang'], - 'user_style' => $this->config['default_style'], - 'user_timezone' => 0, - 'user_dateformat' => $this->config['default_dateformat'], - 'user_allow_massemail' => 0, - ); - - $user_id = user_add($user_row); - - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'bot_active' => 1, - 'bot_name' => (string) $bot_name, - 'user_id' => (int) $user_id, - 'bot_agent' => (string) $bot_agent, - 'bot_ip' => (string) $bot_ip, - )); - - $this->sql_query($sql); - } - } - - function delete_orphan_shadow_topics() - { - // Delete shadow topics pointing to not existing topics - $batch_size = 500; - - // Set of affected forums we have to resync - $sync_forum_ids = array(); - - $sql_array = array( - 'SELECT' => 't1.topic_id, t1.forum_id', - 'FROM' => array( - TOPICS_TABLE => 't1', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(TOPICS_TABLE => 't2'), - 'ON' => 't1.topic_moved_id = t2.topic_id', - ), - ), - 'WHERE' => 't1.topic_moved_id <> 0 - AND t2.topic_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - $result = $this->db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['topic_id']; - - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); - $this->db->sql_query($sql); - - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); - - return true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/3_0_9.php b/phpBB/includes/db/migration/3_0_9.php deleted file mode 100644 index 2e1eab26e7..0000000000 --- a/phpBB/includes/db/migration/3_0_9.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - $this->table_prefix . 'login_attempts' => array( - 'COLUMNS' => array( - // this column was removed from the database updater - // after 3.0.9-RC3 was released. It might still exist - // in 3.0.9-RCX installations and has to be dropped in - // 3.0.12 after the db_tools class is capable of properly - // removing a primary key. - // 'attempt_id' => array('UINT', NULL, 'auto_increment'), - 'attempt_ip' => array('VCHAR:40', ''), - 'attempt_browser' => array('VCHAR:150', ''), - 'attempt_forwarded_for' => array('VCHAR:255', ''), - 'attempt_time' => array('TIMESTAMP', 0), - 'user_id' => array('UINT', 0), - 'username' => array('VCHAR_UNI:255', 0), - 'username_clean' => array('VCHAR_CI', 0), - ), - //'PRIMARY_KEY' => 'attempt_id', - 'KEYS' => array( - 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), - 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), - 'att_time' => array('INDEX', array('attempt_time')), - 'user_id' => array('INDEX', 'user_id'), - ), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'bbcode' => array( - 'bbcode_id' => array('USINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('ip_login_limit_max', 50)), - array('config.add', array('ip_login_limit_time', 21600)), - array('config.add', array('ip_login_limit_use_forwarded', 0)), - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), - ); - } - - function update_file_extension_group_names() - { - // Update file extension group names to use language strings, again. - $sql = 'SELECT group_id, group_name - FROM ' . EXTENSION_GROUPS_TABLE . ' - WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - function fix_firebird_qa_captcha() - { - // Recover from potentially broken Q&A CAPTCHA table on firebird - // Q&A CAPTCHA was uninstallable, so it's safe to remove these - // without data loss - if ($this->db_tools->sql_layer == 'firebird') - { - $tables = array( - $this->table_prefix . 'captcha_questions', - $this->table_prefix . 'captcha_answers', - $this->table_prefix . 'qa_confirm', - ); - foreach ($tables as $table) - { - if ($this->db_tools->sql_table_exists($table)) - { - $this->db_tools->sql_table_drop($table); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/3_0_9_rc2.php b/phpBB/includes/db/migration/3_0_9_rc2.php deleted file mode 100644 index 96782b2b01..0000000000 --- a/phpBB/includes/db/migration/3_0_9_rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $this->db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql); + } + } + + function delete_orphan_private_messages() + { + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql); + + return true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2 b/phpBB/includes/db/migration/data/3_0_11_rc2 new file mode 100644 index 0000000000..6add980c73 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_11_rc2 @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php new file mode 100644 index 0000000000..734a57ecee --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -0,0 +1,26 @@ + array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array('group_legend'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + ); + } + + function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php new file mode 100644 index 0000000000..a5f94e644b --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php new file mode 100644 index 0000000000..f989eea025 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', '')), + array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + )); + } + + function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); + } + + function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php new file mode 100644 index 0000000000..cd34fda9ab --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -0,0 +1,47 @@ +sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php new file mode 100644 index 0000000000..342f1fa910 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -0,0 +1,103 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + ); + } + + function update_custom_profile_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = $this->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php new file mode 100644 index 0000000000..5671832a82 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + $search_indexing_state = $this->config['search_indexing_state']; + + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_refresh', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } + + function hash_old_passwords() + { + $sql = 'SELECT user_id, user_password + FROM ' . $this->table_prefix . 'users + WHERE user_pass_convert = 1'; + $result = $this->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); + } + } + $db->sql_freeresult($result); + } + + function update_ichiro_bot() + { + // Adjust bot entry + $sql = 'UPDATE ' . $this->table_prefix . "bots + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + $this->sql_query($sql); + } + + function remove_duplicate_auth_options() + { + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + $sql = 'SELECT auth_option + FROM ' . $this->table_prefix . 'acl_options + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $this->db->sql_query($sql); + + $auth_options = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $this->db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $this->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $this->db->sql_fetchrow($result); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + } + $this->db->sql_freeresult($result); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php new file mode 100644 index 0000000000..6be8ea9845 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -0,0 +1,34 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php new file mode 100644 index 0000000000..c2cb59e62a --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('if', array( + ($this->config['captcha_gd']), + array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + array('config.add', array('allow_avatar', 1)), + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + array('config.add', array('allow_avatar_remote_upload', 1)), + )), + + array('module.add', array( + 'acp', + 'ACP_BOARD_CONFIGURATION', + array( + 'module_basename' => 'board', + 'modes' => array('feed'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_CAT_USERS', + array( + 'module_basename' => 'users', + 'modes' => array('warnings'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_SERVER_CONFIGURATION', + array( + 'module_basename' => 'send_statistics', + 'modes' => array('send_statistics'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_FORUM_BASED_PERMISSIONS', + array( + 'module_basename' => 'permissions', + 'modes' => array('setting_forum_copy'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'pm_reports', + 'modes' => array('pm_reports'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'pm_reports', + 'modes' => array('pm_reports_closed'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'pm_reports', + 'modes' => array('pm_report_details'), + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + ); + } + + function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + + function add_newly_registered_group() + { + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + $this->sql_query($sql); + + $group_id = $this->db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); + + if (!$errored) + { + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); + } + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); + + if (!$errored) + { + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); + } + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + $this->sql_query($sql); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); + } + $this->db->sql_freeresult($result); + } + + // Clear permissions... + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php new file mode 100644 index 0000000000..07b31a53b9 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -0,0 +1,25 @@ +sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php new file mode 100644 index 0000000000..c48b1ca394 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'log' => array('log_time'), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + ); + } + + function delete_text_templates() + { + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php new file mode 100644 index 0000000000..8a751328bf --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -0,0 +1,70 @@ + ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + $i = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + $this->sql_query($sql); + } + } + $db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return false; + } + + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php new file mode 100644 index 0000000000..a714a3d2f6 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -0,0 +1,25 @@ + 'board', + 'modes' => array('post'), + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $this->db->sql_freeresult($result); + } + + function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + $this->sql_query($sql); + } + + function update_bots() + { + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + $this->sql_query($sql); + } + } + + function delete_orphan_shadow_topics() + { + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + return true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php new file mode 100644 index 0000000000..4b2c08a256 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcode' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + function fix_firebird_qa_captcha() + { + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($this->db_tools->sql_layer == 'firebird') + { + $tables = array( + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($this->db_tools->sql_table_exists($table)) + { + $this->db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php new file mode 100644 index 0000000000..589047670a --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -0,0 +1,25 @@ +db = $db; + $this->cache = $cache; + $this->template = $template; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tools/config.php new file mode 100644 index 0000000000..965ba1d136 --- /dev/null +++ b/phpBB/includes/db/migration/tools/config.php @@ -0,0 +1,106 @@ +config->offsetExists($config_name); + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + */ + public function add($config_name, $config_value = '', $is_dynamic = false) + { + if ($this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); + } + + $this->config->set($config_name, $config_value, $is_dynamic); + + return false; + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update($config_name, $config_value = '') + { + if (!$this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set($config_name, $config_value); + + return false; + } + + /** + * Config Update If Equals + * + * This function allows you to update a config setting if the first argument equal to the current config value + * + * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update_if_equals($compare, $config_name, $config_value = '') + { + if (!$this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set_atomic($config_name, $compare, $config_value); + + return false; + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + */ + public function remove($config_name) + { + if (!$this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->delete($config_name); + + return false; + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tools/module.php new file mode 100644 index 0000000000..df1912a022 --- /dev/null +++ b/phpBB/includes/db/migration/tools/module.php @@ -0,0 +1,419 @@ +db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function add($class, $parent = 0, $data = array(), $include_path = false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_ADD', $class, $info_file); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->exists($class, false, $parent)) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + if ($this->exists($class, $parent, $data['module_langname'])) + { + throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + throw new phpbb_db_migration_exception('MODULE_ERROR', $result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $this->cache->destroy("_modules_$class"); + + return false; + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function remove($class, $parent = 0, $module = '', $include_path = false) + { + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $this->remove($class, $parent, $info['title']) . '
'; + } + } + return false; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->exists($class, $parent, $module)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); + } + } + + $cache->destroy("_modules_$class"); + + return false; + } + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tools/permission.php new file mode 100644 index 0000000000..3fbe7c649c --- /dev/null +++ b/phpBB/includes/db/migration/tools/permission.php @@ -0,0 +1,480 @@ +db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function add($auth_option, $global = true) + { + if ($this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + include($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + return false; + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function remove($auth_option, $global = true) + { + if (!$this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $this->cache->destroy('_acl_options'); + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + public function role_add($role_name, $role_type = '', $role_description = '') + { + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' + WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return false; + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + public function role_update($old_role_name, $new_role_name = '') + { + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' + SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + + return false; + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + public function role_remove($role_name) + { + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->set($role_name, $auth_option, 'role', $has_permission); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + public function permission_unset($name, $auth_option = array(), $type = 'role') + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' + WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/umil.php b/phpBB/includes/db/migration/tools/umil.php new file mode 100644 index 0000000000..ce7b8ff3be --- /dev/null +++ b/phpBB/includes/db/migration/tools/umil.php @@ -0,0 +1,3037 @@ +config_add(array( +* array('config_name', 'config_value'), +* array('config_name1', 'config_value1'), +* array('config_name2', 'config_value2', true), +* array('config_name3', 'config_value3', true), +* ); +*/ + +/** +* UMIL - Unified MOD Installation Library class +* +* Cache Functions +* cache_purge($type = '', $style_id = 0) +* +* Config Functions: +* config_exists($config_name, $return_result = false) +* config_add($config_name, $config_value = '', $is_dynamic = false) +* config_update($config_name, $config_value, $is_dynamic = false) +* config_remove($config_name) +* +* Module Functions +* module_exists($class, $parent, $module) +* module_add($class, $parent = 0, $data = array()) +* module_remove($class, $parent = 0, $module = '') +* +* Permissions/Auth Functions +* permission_exists($auth_option, $global = true) +* permission_add($auth_option, $global = true) +* permission_remove($auth_option, $global = true) +* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) +* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) +* +* Table Functions +* table_exists($table_name) +* table_add($table_name, $table_data = array()) +* table_remove($table_name) +* +* Table Column Functions +* table_column_exists($table_name, $column_name) +* table_column_add($table_name, $column_name = '', $column_data = array()) +* table_column_update($table_name, $column_name = '', $column_data = array()) +* table_column_remove($table_name, $column_name = '') +* +* Table Key/Index Functions +* table_index_exists($table_name, $index_name) +* table_index_add($table_name, $index_name = '', $column = array()) +* table_index_remove($table_name, $index_name = '') +* +* Table Row Functions (note that these actions are not reversed automatically during uninstallation) +* table_row_insert($table_name, $data = array()) +* table_row_remove($table_name, $data = array()) +* table_row_update($table_name, $data = array(), $new_data = array()) +* +* Version Check Function +* version_check($url, $path, $file) +*/ +class umil +{ + /** + * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) + * + * @var string + */ + var $command = ''; + + /** + * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. + * + * @var string + */ + var $result = ''; + + /** + * Auto run $this->display_results after running a command + */ + var $auto_display_results = false; + + /** + * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff + */ + var $stand_alone = false; + + /** + * Were any new permissions added (used in umil_frontend)? + */ + var $permissions_added = false; + + /** + * Database Object + */ + var $db = false; + + /** + * Database Tools Object + */ + var $db_tools = false; + + /** + * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... + */ + var $table_prefix = false; + + /** + * Constructor + */ + function umil($stand_alone = false, $db = false) + { + // Setup $this->db + if ($db !== false) + { + if (!is_object($db) || !method_exists($db, 'sql_query')) + { + trigger_error('Invalid $db Object'); + } + + $this->db = $db; + } + else + { + global $db; + $this->db = $db; + } + + // Setup $this->db_tools + if (!class_exists('phpbb_db_tools')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + $this->db_tools = new phpbb_db_tools($this->db); + + $this->stand_alone = $stand_alone; + + if (!$stand_alone) + { + global $config, $user, $phpbb_root_path, $phpEx; + + /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. + if (method_exists('user', 'set_custom_lang_path')) + { + $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); + $user->add_lang('umil'); + $user->set_custom_lang_path($phpbb_root_path . 'language/'); + } + else + {*/ + // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. + if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) + { + $path = $user->data['user_lang']; + } + else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) + { + $path = basename($config['default_lang']); + } + else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) + { + $path = 'en'; + } + else + { + trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); + } + + $user->add_lang('./../../umil/language/' . $path . '/umil'); + //} + + $user->add_lang(array('acp/common', 'acp/permissions')); + + // Check to see if a newer version is available. + $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); + if (is_array($info) && isset($info[0]) && isset($info[1])) + { + if (version_compare(UMIL_VERSION, $info[0], '<')) + { + global $template; + + // Make sure user->setup() has been called + if (empty($user->lang)) + { + $user->setup(); + } + + page_header('', false); + + $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; + $template->assign_vars(array( + 'S_BOARD_DISABLED' => true, + 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), + )); + } + } + } + } + + /** + * umil_start + * + * A function which runs (almost) every time a function here is ran + */ + function umil_start() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + $this->command = call_user_func_array(array($this, 'get_output_text'), $args); + + $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; + $this->db->sql_return_on_error(true); + + //$this->db->sql_transaction('begin'); + } + + /** + * umil_end + * + * A function which runs (almost) every time a function here is ran + */ + function umil_end() + { + global $user; + + // Set up the result. This will get the arguments sent to the function. + $args = func_get_args(); + $result = call_user_func_array(array($this, 'get_output_text'), $args); + $this->result = ($result) ? $result : $this->result; + + if ($this->db->sql_error_triggered) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; + } + else + { + $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; + } + + //$this->db->sql_transaction('rollback'); + } + else + { + //$this->db->sql_transaction('commit'); + } + + $this->db->sql_return_on_error(false); + + // Auto output if requested. + if ($this->auto_display_results && method_exists($this, 'display_results')) + { + $this->display_results(); + } + + return '' . $this->command . '
' . $this->result; + } + + /** + * Get text for output + * + * Takes the given arguments and prepares them for the UI + * + * First argument sent is used as the language key + * Further arguments (if send) are used on the language key through vsprintf() + * + * @return string Returns the prepared string for output + */ + function get_output_text() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + if (sizeof($args)) + { + $lang_key = array_shift($args); + + if (sizeof($args)) + { + $lang_args = array(); + foreach ($args as $arg) + { + $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; + } + + return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); + } + else + { + return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); + } + } + + return ''; + } + + /** + * Run Actions + * + * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. + * + * @param string $action The action. install|update|uninstall + * @param array $versions The array of versions and the actions for each + * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version + * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. + */ + function run_actions($action, $versions, $version_config_name, $version_select = '') + { + // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers + uksort($versions, 'version_compare'); + + // Find the current version to install + $current_version = '0.0.0'; + foreach ($versions as $version => $actions) + { + $current_version = $version; + } + + $db_version = ''; + if ($this->config_exists($version_config_name)) + { + global $config; + $db_version = $config[$version_config_name]; + } + + // Set the action to install from update if nothing is currently installed + if ($action == 'update' && !$db_version) + { + $action = 'install'; + } + + if ($action == 'install' || $action == 'update') + { + $version_installed = $db_version; + foreach ($versions as $version => $version_actions) + { + // If we are updating + if ($db_version && version_compare($version, $db_version, '<=')) + { + continue; + } + + if ($version_select && version_compare($version, $version_select, '>')) + { + break; + } + + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), $params); + } + } + } + + $version_installed = $version; + } + + // update the version number or add it + if ($this->config_exists($version_config_name)) + { + $this->config_update($version_config_name, $version_installed); + } + else + { + $this->config_add($version_config_name, $version_installed); + } + } + else if ($action == 'uninstall' && $db_version) + { + // reverse version list + $versions = array_reverse($versions); + + foreach ($versions as $version => $version_actions) + { + // Uninstalling and this listed version is newer than installed + if (version_compare($version, $db_version, '>')) + { + continue; + } + + // Version selection stuff + if ($version_select && version_compare($version, $version_select, '<=')) + { + // update the version number + $this->config_update($version_config_name, $version); + break; + } + + $cache_purge = false; + $version_actions = array_reverse($version_actions); + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). + if ($method == 'cache_purge') + { + $cache_purge = $params; + continue; + } + + // A few things are not possible for uninstallations update actions and table_row actions + if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) + { + continue; + } + + // reverse function call + $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); + $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); + + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); + } + } + } + + if ($cache_purge !== false) + { + $this->cache_purge($cache_purge); + } + } + + if (!$version_select) + { + // Unset the version number + $this->config_remove($version_config_name); + } + } + } + + /** + * Call custom function helper + */ + function _call_custom_function($functions, $action, $version) + { + if (!is_array($functions)) + { + $functions = array($functions); + } + + $return = ''; + + foreach ($functions as $function) + { + if (function_exists($function)) + { + // Must reset before calling the function + $this->umil_start(); + + $returned = call_user_func($function, $action, $version); + if (is_string($returned)) + { + $this->command = $this->get_output_text($returned); + } + else if (is_array($returned) && isset($returned['command'])) + { + if (is_array($returned['command'])) + { + $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); + } + else + { + $this->command = $this->get_output_text($returned['command']); + } + + if (isset($returned['result'])) + { + $this->result = $this->get_output_text($returned['result']); + } + } + else + { + $this->command = $this->get_output_text('UNKNOWN'); + } + + $return .= $this->umil_end() . '
'; + } + } + + return $return; + } + + /** + * Multicall Helper + * + * @param mixed $function Function name to call + * @param mixed $params The parameters array + * + * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) + */ + function multicall($function, $params) + { + if (is_array($params) && !empty($params)) + { + foreach ($params as $param) + { + if (!is_array($param)) + { + call_user_func(array($this, $function), $param); + } + else + { + call_user_func_array(array($this, $function), $param); + } + } + return true; + } + + return false; + } + + /** + * Cache Purge + * + * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. + * + * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. + * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) + */ + function cache_purge($type = '', $style_id = 0) + { + global $auth, $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $type)) + { + return; + } + + $style_id = (int) $style_id; + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'auth' : + $this->umil_start('AUTH_CACHE_PURGE'); + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + break; + + case 'imageset' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT imageset_id + FROM ' . STYLES_IMAGESET_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('imageset', $row['imageset_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_IMAGESET_TABLE . " + WHERE imageset_id = $style_id"; + $result = $this->db->sql_query($sql); + $imageset_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$imageset_row) + { + $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); + + // The following is from includes/acp/acp_styles.php (edited) + $sql_ary = array(); + + $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); + + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $style_id; + $result = $this->db->sql_query($sql); + + foreach ($cfg_data_imageset as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => '', + ); + } + } + + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) + { + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => (string) $row['lang_dir'], + ); + } + } + } + } + $this->db->sql_freeresult($result); + + $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); + + $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + + return $this->umil_end(); + } + break; + //case 'imageset' : + + case 'template' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT template_id + FROM ' . STYLES_TEMPLATE_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('template', $row['template_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_TEMPLATE_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + $template_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$template_row) + { + $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); + + // The following is from includes/acp/acp_styles.php + if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) + { + $filelist = array('' => array()); + + $sql = 'SELECT template_filename, template_mtime + FROM ' . STYLES_TEMPLATE_DATA_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { +// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) +// { + // get folder info from the filename + if (($slash_pos = strrpos($row['template_filename'], '/')) === false) + { + $filelist[''][] = $row['template_filename']; + } + else + { + $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); + } +// } + } + $this->db->sql_freeresult($result); + + $includes = array(); + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) + { + return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); + } + $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); + fclose($fp); + + if (preg_match_all('##is', $template_data, $matches)) + { + foreach ($matches[1] as $match) + { + $includes[trim($match)][] = $file; + } + } + } + } + + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + // Skip index. + if (strpos($file, 'index.') === 0) + { + continue; + } + + // We could do this using extended inserts ... but that could be one + // heck of a lot of data ... + $sql_ary = array( + 'template_id' => (int) $style_id, + 'template_filename' => "$pathfile$file", + 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', + 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + ); + + $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE template_id = $style_id + AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; + $this->db->sql_query($sql); + } + } + unset($filelist); + } + + // Purge the forum's cache as well. + $cache->purge(); + + return $this->umil_end(); + } + break; + //case 'template' : + + case 'theme' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT theme_id + FROM ' . STYLES_THEME_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('theme', $row['theme_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_THEME_TABLE . " + WHERE theme_id = $style_id"; + $result = $this->db->sql_query($sql); + $theme_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$theme_row) + { + $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); + + // The following is from includes/acp/acp_styles.php + if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) + { + $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); + + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + foreach ($matches[0] as $idx => $match) + { + if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) + { + continue; + } + + $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); + $stylesheet = str_replace($match, $content, $stylesheet); + } + } + + // adjust paths + $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); + + // Save CSS contents + $sql_ary = array( + 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), + 'theme_data' => $db_theme_data, + ); + + $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE theme_id = $style_id"; + $this->db->sql_query($sql); + + $cache->destroy('sql', STYLES_THEME_TABLE); + } + + return $this->umil_end(); + } + break; + //case 'theme' : + + default: + $this->umil_start('CACHE_PURGE'); + $cache->purge(); + + return $this->umil_end(); + break; + } + } + + /** + * Config Exists + * + * This function is to check to see if a config variable exists or if it does not. + * + * @param string $config_name The name of the config setting you wish to check for. + * @param bool $return_result - return the config value/default if true : default false. + * + * @return bool true/false if config exists + */ + function config_exists($config_name, $return_result = false) + { + global $config, $cache; + + $sql = 'SELECT * + FROM ' . CONFIG_TABLE . " + WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + if (!isset($config[$config_name])) + { + $config[$config_name] = $row['config_value']; + + if (!$row['is_dynamic']) + { + $cache->destroy('config'); + } + } + + return ($return_result) ? $row : true; + } + + // this should never happen, but if it does, we need to remove the config from the array + if (isset($config[$config_name])) + { + unset($config[$config_name]); + $cache->destroy('config'); + } + + return false; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_add($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_ADD', $config_name); + + if ($this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_update($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_UPDATE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + * + * @return result + */ + function config_remove($config_name) + { + global $cache, $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_REMOVE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $this->db->sql_query($sql); + + unset($config[$config_name]); + $cache->destroy('config'); + + return $this->umil_end(); + } + + /** + * Module Exists + * + * Check if a module exists + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + */ + function module_exists($class, $parent, $module) + { + // the main root directory should return true + if (!$module) + { + return true; + } + + $class = $this->db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_add($class, $parent = 0, $data = array(), $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Prevent stupid things like trying to add a module with no name or any data on it + if (empty($data)) + { + $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_ADD', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->module_exists($class, false, $parent)) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + if ($this->module_exists($class, $parent, $data['module_langname'])) + { + return $this->umil_end('MODULE_ALREADY_EXIST'); + } + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + $this->result = $this->get_output_text($result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_remove($class, $parent = 0, $module = '', $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->module_remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_REMOVE', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + $result = ''; + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $result .= $this->module_remove($class, $parent, $info['title']) . '
'; + } + } + return $result; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->module_exists($class, $parent, $module)) + { + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); + return $this->umil_end('MODULE_NOT_EXIST'); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = implode('
', $result); + } + else + { + $this->result .= '
' . implode('
', $result); + } + } + } + + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + } + + /** + * Permission Exists + * + * Check if a permission (auth) setting exists + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return bool true if it exists, false if not + */ + function permission_exists($auth_option, $global = true) + { + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_add($auth_option, $global = true) + { + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_ADD', $auth_option); + + if ($this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->permission_exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + return $this->umil_end(); + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_remove($auth_option, $global = true) + { + global $auth, $cache; + + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_REMOVE', $auth_option); + + if (!$this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + function permission_role_add($role_name, $role_type = '', $role_description = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_ADD', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' + WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + function permission_role_update($old_role_name, $new_role_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' + SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + function permission_role_remove($role_name) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_SET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_SET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_set($role_name, $auth_option, 'role', $has_permission); + } + + $this->umil_start('PERMISSION_SET_GROUP', $name); + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + function permission_unset($name, $auth_option = array(), $type = 'role') + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_UNSET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Table Exists + * + * Check if a table exists in the DB or not + * + * @param string $table_name The table name to check for + * + * @return bool true if the table exists, false if not + */ + function table_exists($table_name) + { + $this->get_table_name($table_name); + + // Use sql_table_exists if available + if (method_exists($this->db_tools, 'sql_table_exists')) + { + $roe = $this->db->return_on_error; + $result = $this->db_tools->sql_table_exists($table_name); + + // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before + if ($roe) + { + $this->db->sql_return_on_error(true); + } + + return $result; + } + + if (!function_exists('get_tables')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_install.' . $phpEx); + } + + $tables = get_tables($this->db); + + if (in_array($table_name, $tables)) + { + return true; + } + else + { + return false; + } + } + + /** + * Table Add + * + * This only supports input from the array format of db_tools or create_schema_files. + */ + function table_add($table_name, $table_data = array()) + { + global $dbms, $user; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error + */ + if (empty($table_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ADD', $table_name); + + if ($this->table_exists($table_name)) + { + return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); + } + + if (!is_array($table_data)) + { + return $this->umil_end('NO_TABLE_DATA'); + } + + if (!function_exists('get_available_dbms')) + { + global $phpbb_root_path, $phpEx; + include("{$phpbb_root_path}includes/functions_install.$phpEx"); + } + + /* + * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore + if (method_exists($this->db_tools, 'sql_create_table')) + { + // Added in 3.0.5 + $this->db_tools->sql_create_table($table_name, $table_data); + } + else + {*/ + $available_dbms = get_available_dbms($dbms); + + $sql_query = $this->create_table_sql($table_name, $table_data); + $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); + + foreach ($sql_query as $sql) + { + $this->db->sql_query($sql); + } + //} + + return $this->umil_end(); + } + + /** + * Table Remove + * + * Delete/Drop a DB table + */ + function table_remove($table_name) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_REMOVE', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + if (method_exists($this->db_tools, 'sql_table_drop')) + { + // Added in 3.0.5 + $this->db_tools->sql_table_drop($table_name); + } + else + { + $this->db->sql_query('DROP TABLE ' . $table_name); + } + + return $this->umil_end(); + } + + /** + * Table Column Exists + * + * Check to see if a column exists in a table + */ + function table_column_exists($table_name, $column_name) + { + $this->get_table_name($table_name); + + return $this->db_tools->sql_column_exists($table_name, $column_name); + } + + /** + * Table Column Add + * + * Add a new column to a table. + */ + function table_column_add($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error + */ + if (empty($column_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); + + if ($this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); + } + + $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Update + * + * Alter/Update a column in a table. You can not change a column name with this. + */ + function table_column_update($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_change($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Remove + * + * Remove a column from a table + */ + function table_column_remove($table_name, $column_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_remove($table_name, $column_name); + + return $this->umil_end(); + } + + /** + * Table Index Exists + * + * Check if a table key/index exists on a table (can not check primary or unique) + */ + function table_index_exists($table_name, $index_name) + { + $this->get_table_name($table_name); + + $indexes = $this->db_tools->sql_list_index($table_name); + + if (in_array($index_name, $indexes)) + { + return true; + } + + return false; + } + + /** + * Table Index Add + * + * Add a new key/index to a table + */ + function table_index_add($table_name, $index_name = '', $column = array()) + { + global $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + // Let them skip the column field and just use the index name in that case as the column as well + if (empty($column)) + { + $column = array($index_name); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); + + if ($this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); + } + + if (!is_array($column)) + { + $column = array($column); + } + + // remove index length if we are before 3.0.8 + // the feature (required for some types when using MySQL4) + // was added in that release (ticket PHPBB3-8944) + if (version_compare($config['version'], '3.0.7-pl1', '<=')) + { + $column = preg_replace('#:.*$#', '', $column); + } + + $this->db_tools->sql_create_index($table_name, $index_name, $column); + + return $this->umil_end(); + } + + /** + * Table Index Remove + * + * Remove a key/index from a table + */ + function table_index_remove($table_name, $index_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); + + if (!$this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); + } + + $this->db_tools->sql_index_drop($table_name, $index_name); + + return $this->umil_end(); + } + + // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility + function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } + + /** + * Table Insert + * + * Insert data into a table + */ + function table_row_insert($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $this->db->sql_multi_insert($table_name, $data); + + return $this->umil_end(); + } + + /** + * Table Row Update + * + * Update a row in a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + * + * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). + */ + function table_row_update($table_name, $data = array(), $new_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'UPDATE ' . $table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' + WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Table Row Remove + * + * Remove a row from a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + */ + function table_row_remove($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Version Checker + * + * Format the file like the following: + * http://www.phpbb.com/updatecheck/30x.txt + * + * @param string $url The url to access (ex: www.phpbb.com) + * @param string $path The path to access (ex: /updatecheck) + * @param string $file The name of the file to access (ex: 30x.txt) + * + * @return array|string Error Message if there was any error, or an array (each line in the file as a value) + */ + function version_check($url, $path, $file, $timeout = 10, $port = 80) + { + if (!function_exists('get_remote_file')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } + + $errstr = $errno = ''; + + $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); + + if ($info === false) + { + return $errstr . ' [ ' . $errno . ' ]'; + } + + $info = str_replace("\r\n", "\n", $info); + $info = explode("\n", $info); + + return $info; + } + + /** + * Create table SQL + * + * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array + * + * @param string $table_name The name of the table + * @param array $table_data The table data (formatted in the array format used by create_schema_files) + * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) + * + * @return The sql query to run for the submitted dbms to insert the table + */ + function create_table_sql($table_name, $table_data, $dbms = '') + { + // To allow testing + $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; + + // A list of types being unsigned for better reference in some db's + $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); + $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); + + $sql = ''; + + // Create Table statement + $generator = $textimage = false; + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'firebird': + case 'oracle': + case 'sqlite': + case 'postgres': + $sql .= "CREATE TABLE {$table_name} (\n"; + break; + + case 'mssql': + $sql .= "CREATE TABLE [{$table_name}] (\n"; + break; + } + + // Table specific so we don't get overlap + $modded_array = array(); + + // Write columns one by one... + foreach ($table_data['COLUMNS'] as $column_name => $column_data) + { + // Get type + if (strpos($column_data[0], ':') !== false) + { + list($orig_column_type, $column_length) = explode(':', $column_data[0]); + if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); + } + else + { + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) + { + case 'div': + $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; + $column_length = ceil($column_length); + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + break; + } + } + + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) + { + case 'mult': + $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; + if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) + { + $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; + $modded_array[$column_name] = $column_type; + } + else + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + } + break; + } + } + } + $orig_column_type .= ':'; + } + else + { + $orig_column_type = $column_data[0]; + $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; + if ($column_type == 'text' || $column_type == 'blob') + { + $modded_array[$column_name] = $column_type; + } + } + + // Adjust default value if db-dependant specified + if (is_array($column_data[1])) + { + $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= "\t{$column_name} {$column_type} "; + + // For hexadecimal values do not use single quotes + if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') + { + $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; + } + $sql .= 'NOT NULL'; + + if (isset($column_data[2])) + { + if ($column_data[2] == 'auto_increment') + { + $sql .= ' auto_increment'; + } + else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') + { + $sql .= ' COLLATE utf8_unicode_ci'; + } + } + + $sql .= ",\n"; + break; + + case 'sqlite': + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; + $generator = $column_name; + } + else + { + $sql .= "\t{$column_name} {$column_type} "; + } + + $sql .= 'NOT NULL '; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; + $sql .= ",\n"; + break; + + case 'firebird': + $sql .= "\t{$column_name} {$column_type} "; + + if (!is_null($column_data[1])) + { + $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; + } + + $sql .= 'NOT NULL'; + + // This is a UNICODE column and thus should be given it's fair share + if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) + { + $sql .= ' COLLATE UNICODE'; + } + + $sql .= ",\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'mssql': + if ($column_type == '[text]') + { + $textimage = true; + } + + $sql .= "\t[{$column_name}] {$column_type} "; + + if (!is_null($column_data[1])) + { + // For hexadecimal values do not use single quotes + if (strpos($column_data[1], '0x') === 0) + { + $sql .= 'DEFAULT (' . $column_data[1] . ') '; + } + else + { + $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; + } + } + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= 'IDENTITY (1, 1) '; + } + + $sql .= 'NOT NULL'; + $sql .= " ,\n"; + break; + + case 'oracle': + $sql .= "\t{$column_name} {$column_type} "; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + + // In Oracle empty strings ('') are treated as NULL. + // Therefore in oracle we allow NULL's for all DEFAULT '' entries + $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'postgres': + $sql .= "\t{$column_name} {$column_type} "; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; + + // Make sure the sequence will be created before creating the table + $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; + } + else + { + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + $sql .= "NOT NULL"; + + // Unsigned? Then add a CHECK contraint + if (in_array($orig_column_type, $unsigned_types)) + { + $sql .= " CHECK ({$column_name} >= 0)"; + } + + $sql .= ",\n"; + } + break; + } + } + + switch ($dbms) + { + case 'firebird': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);;\n\n"; + break; + + case 'mssql': + $sql = substr($sql, 0, -2); + $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; + $sql .= "GO\n\n"; + break; + } + + // Write primary key + if (isset($table_data['PRIMARY_KEY'])) + { + if (!is_array($table_data['PRIMARY_KEY'])) + { + $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'postgres': + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + + case 'firebird': + $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; + break; + + case 'sqlite': + if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) + { + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + } + break; + + case 'mssql': + $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; + $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; + $sql .= "\t(\n"; + $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; + $sql .= "\t) ON [PRIMARY] \n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + } + } + + switch ($dbms) + { + case 'oracle': + // UNIQUE contrains to be added? + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + if ($key_data[0] == 'UNIQUE') + { + $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; + } + } + } + + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n)\n/\n\n"; + break; + + case 'postgres': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'sqlite': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + } + + // Write Keys + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; + foreach ($key_data[1] as $key => $col_name) + { + if (isset($modded_array[$col_name])) + { + switch ($modded_array[$col_name]) + { + case 'text': + case 'blob': + $key_data[1][$key] = $col_name . '(255)'; + break; + } + } + } + $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; + break; + + case 'firebird': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; + break; + + case 'mssql': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + if ($key_data[0] == 'UNIQUE') + { + continue; + } + + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; + $sql .= "/\n"; + break; + + case 'sqlite': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + + case 'postgres': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + } + } + } + + switch ($dbms) + { + case 'mysql_40': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'mysql_41': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; + break; + + // Create Generator + case 'firebird': + if ($generator !== false) + { + $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; + $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; + + $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; + $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; + $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; + } + break; + + case 'oracle': + if ($generator !== false) + { + $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; + + $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; + $sql .= "BEFORE INSERT ON {$table_name}\n"; + $sql .= "FOR EACH ROW WHEN (\n"; + $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; + $sql .= ")\nBEGIN\n"; + $sql .= "\tSELECT {$table_name}_seq.nextval\n"; + $sql .= "\tINTO :new.{$generator}\n"; + $sql .= "\tFROM dual;\nEND;\n/\n\n"; + } + break; + } + + return $sql; + } + + /** + * Get the real table name + * By A_Jelly_Doughnut + * + * @param string $table_name The table name to get the real table name from + */ + function get_table_name(&$table_name) + { + // Use the global table prefix if a custom one is not specified + if ($this->table_prefix === false) + { + global $table_prefix; + } + else + { + $table_prefix = $this->table_prefix; + } + + static $constants = NULL; + + if (is_null($constants)) + { + $constants = get_defined_constants(); + } + + /** + * only do the replace if the table prefix is not already present + * this is required since UMIL supports specifying a table via phpbb_foo + * (where a replace would be needed) + * or by FOO_TABLE (where a replace is already done at constant-define time) + */ + if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) + { + $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); + } + } +} + +?> \ No newline at end of file diff --git a/phpBB/includes/db/migrationtools/base.php b/phpBB/includes/db/migrationtools/base.php deleted file mode 100644 index 7fc6057e3a..0000000000 --- a/phpBB/includes/db/migrationtools/base.php +++ /dev/null @@ -1,15 +0,0 @@ -db->sql_escape($config_name) . "'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - if (!isset($this->config[$config_name])) - { - $this->config[$config_name] = $row['config_value']; - - if (!$row['is_dynamic']) - { - $this->cache->destroy('config'); - } - } - - return ($return_result) ? $row : true; - } - - // this should never happen, but if it does, we need to remove the config from the array - if (isset($this->config[$config_name])) - { - unset($this->config[$config_name]); - $this->cache->destroy('config'); - } - - return false; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_add($config_name, $config_value = '', $is_dynamic = false) - { - if ($this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_update($config_name, $config_value = '') - { - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - set_config($config_name, $config_value); - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - * - * @return result - */ - function config_remove($config_name) - { - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - $sql = 'DELETE FROM ' . CONFIG_TABLE . " - WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $this->db->sql_query($sql); - - unset($this->config[$config_name]); - $this->cache->destroy('config'); - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migrationtools/umil.php b/phpBB/includes/db/migrationtools/umil.php deleted file mode 100644 index ce7b8ff3be..0000000000 --- a/phpBB/includes/db/migrationtools/umil.php +++ /dev/null @@ -1,3037 +0,0 @@ -config_add(array( -* array('config_name', 'config_value'), -* array('config_name1', 'config_value1'), -* array('config_name2', 'config_value2', true), -* array('config_name3', 'config_value3', true), -* ); -*/ - -/** -* UMIL - Unified MOD Installation Library class -* -* Cache Functions -* cache_purge($type = '', $style_id = 0) -* -* Config Functions: -* config_exists($config_name, $return_result = false) -* config_add($config_name, $config_value = '', $is_dynamic = false) -* config_update($config_name, $config_value, $is_dynamic = false) -* config_remove($config_name) -* -* Module Functions -* module_exists($class, $parent, $module) -* module_add($class, $parent = 0, $data = array()) -* module_remove($class, $parent = 0, $module = '') -* -* Permissions/Auth Functions -* permission_exists($auth_option, $global = true) -* permission_add($auth_option, $global = true) -* permission_remove($auth_option, $global = true) -* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) -* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) -* -* Table Functions -* table_exists($table_name) -* table_add($table_name, $table_data = array()) -* table_remove($table_name) -* -* Table Column Functions -* table_column_exists($table_name, $column_name) -* table_column_add($table_name, $column_name = '', $column_data = array()) -* table_column_update($table_name, $column_name = '', $column_data = array()) -* table_column_remove($table_name, $column_name = '') -* -* Table Key/Index Functions -* table_index_exists($table_name, $index_name) -* table_index_add($table_name, $index_name = '', $column = array()) -* table_index_remove($table_name, $index_name = '') -* -* Table Row Functions (note that these actions are not reversed automatically during uninstallation) -* table_row_insert($table_name, $data = array()) -* table_row_remove($table_name, $data = array()) -* table_row_update($table_name, $data = array(), $new_data = array()) -* -* Version Check Function -* version_check($url, $path, $file) -*/ -class umil -{ - /** - * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) - * - * @var string - */ - var $command = ''; - - /** - * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. - * - * @var string - */ - var $result = ''; - - /** - * Auto run $this->display_results after running a command - */ - var $auto_display_results = false; - - /** - * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff - */ - var $stand_alone = false; - - /** - * Were any new permissions added (used in umil_frontend)? - */ - var $permissions_added = false; - - /** - * Database Object - */ - var $db = false; - - /** - * Database Tools Object - */ - var $db_tools = false; - - /** - * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... - */ - var $table_prefix = false; - - /** - * Constructor - */ - function umil($stand_alone = false, $db = false) - { - // Setup $this->db - if ($db !== false) - { - if (!is_object($db) || !method_exists($db, 'sql_query')) - { - trigger_error('Invalid $db Object'); - } - - $this->db = $db; - } - else - { - global $db; - $this->db = $db; - } - - // Setup $this->db_tools - if (!class_exists('phpbb_db_tools')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } - $this->db_tools = new phpbb_db_tools($this->db); - - $this->stand_alone = $stand_alone; - - if (!$stand_alone) - { - global $config, $user, $phpbb_root_path, $phpEx; - - /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. - if (method_exists('user', 'set_custom_lang_path')) - { - $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); - $user->add_lang('umil'); - $user->set_custom_lang_path($phpbb_root_path . 'language/'); - } - else - {*/ - // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. - if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) - { - $path = $user->data['user_lang']; - } - else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) - { - $path = basename($config['default_lang']); - } - else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) - { - $path = 'en'; - } - else - { - trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); - } - - $user->add_lang('./../../umil/language/' . $path . '/umil'); - //} - - $user->add_lang(array('acp/common', 'acp/permissions')); - - // Check to see if a newer version is available. - $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); - if (is_array($info) && isset($info[0]) && isset($info[1])) - { - if (version_compare(UMIL_VERSION, $info[0], '<')) - { - global $template; - - // Make sure user->setup() has been called - if (empty($user->lang)) - { - $user->setup(); - } - - page_header('', false); - - $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; - $template->assign_vars(array( - 'S_BOARD_DISABLED' => true, - 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), - )); - } - } - } - } - - /** - * umil_start - * - * A function which runs (almost) every time a function here is ran - */ - function umil_start() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - $this->command = call_user_func_array(array($this, 'get_output_text'), $args); - - $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; - $this->db->sql_return_on_error(true); - - //$this->db->sql_transaction('begin'); - } - - /** - * umil_end - * - * A function which runs (almost) every time a function here is ran - */ - function umil_end() - { - global $user; - - // Set up the result. This will get the arguments sent to the function. - $args = func_get_args(); - $result = call_user_func_array(array($this, 'get_output_text'), $args); - $this->result = ($result) ? $result : $this->result; - - if ($this->db->sql_error_triggered) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; - } - else - { - $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; - } - - //$this->db->sql_transaction('rollback'); - } - else - { - //$this->db->sql_transaction('commit'); - } - - $this->db->sql_return_on_error(false); - - // Auto output if requested. - if ($this->auto_display_results && method_exists($this, 'display_results')) - { - $this->display_results(); - } - - return '' . $this->command . '
' . $this->result; - } - - /** - * Get text for output - * - * Takes the given arguments and prepares them for the UI - * - * First argument sent is used as the language key - * Further arguments (if send) are used on the language key through vsprintf() - * - * @return string Returns the prepared string for output - */ - function get_output_text() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - if (sizeof($args)) - { - $lang_key = array_shift($args); - - if (sizeof($args)) - { - $lang_args = array(); - foreach ($args as $arg) - { - $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; - } - - return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); - } - else - { - return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); - } - } - - return ''; - } - - /** - * Run Actions - * - * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. - * - * @param string $action The action. install|update|uninstall - * @param array $versions The array of versions and the actions for each - * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version - * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. - */ - function run_actions($action, $versions, $version_config_name, $version_select = '') - { - // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers - uksort($versions, 'version_compare'); - - // Find the current version to install - $current_version = '0.0.0'; - foreach ($versions as $version => $actions) - { - $current_version = $version; - } - - $db_version = ''; - if ($this->config_exists($version_config_name)) - { - global $config; - $db_version = $config[$version_config_name]; - } - - // Set the action to install from update if nothing is currently installed - if ($action == 'update' && !$db_version) - { - $action = 'install'; - } - - if ($action == 'install' || $action == 'update') - { - $version_installed = $db_version; - foreach ($versions as $version => $version_actions) - { - // If we are updating - if ($db_version && version_compare($version, $db_version, '<=')) - { - continue; - } - - if ($version_select && version_compare($version, $version_select, '>')) - { - break; - } - - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), $params); - } - } - } - - $version_installed = $version; - } - - // update the version number or add it - if ($this->config_exists($version_config_name)) - { - $this->config_update($version_config_name, $version_installed); - } - else - { - $this->config_add($version_config_name, $version_installed); - } - } - else if ($action == 'uninstall' && $db_version) - { - // reverse version list - $versions = array_reverse($versions); - - foreach ($versions as $version => $version_actions) - { - // Uninstalling and this listed version is newer than installed - if (version_compare($version, $db_version, '>')) - { - continue; - } - - // Version selection stuff - if ($version_select && version_compare($version, $version_select, '<=')) - { - // update the version number - $this->config_update($version_config_name, $version); - break; - } - - $cache_purge = false; - $version_actions = array_reverse($version_actions); - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). - if ($method == 'cache_purge') - { - $cache_purge = $params; - continue; - } - - // A few things are not possible for uninstallations update actions and table_row actions - if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) - { - continue; - } - - // reverse function call - $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); - $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); - - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); - } - } - } - - if ($cache_purge !== false) - { - $this->cache_purge($cache_purge); - } - } - - if (!$version_select) - { - // Unset the version number - $this->config_remove($version_config_name); - } - } - } - - /** - * Call custom function helper - */ - function _call_custom_function($functions, $action, $version) - { - if (!is_array($functions)) - { - $functions = array($functions); - } - - $return = ''; - - foreach ($functions as $function) - { - if (function_exists($function)) - { - // Must reset before calling the function - $this->umil_start(); - - $returned = call_user_func($function, $action, $version); - if (is_string($returned)) - { - $this->command = $this->get_output_text($returned); - } - else if (is_array($returned) && isset($returned['command'])) - { - if (is_array($returned['command'])) - { - $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); - } - else - { - $this->command = $this->get_output_text($returned['command']); - } - - if (isset($returned['result'])) - { - $this->result = $this->get_output_text($returned['result']); - } - } - else - { - $this->command = $this->get_output_text('UNKNOWN'); - } - - $return .= $this->umil_end() . '
'; - } - } - - return $return; - } - - /** - * Multicall Helper - * - * @param mixed $function Function name to call - * @param mixed $params The parameters array - * - * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) - */ - function multicall($function, $params) - { - if (is_array($params) && !empty($params)) - { - foreach ($params as $param) - { - if (!is_array($param)) - { - call_user_func(array($this, $function), $param); - } - else - { - call_user_func_array(array($this, $function), $param); - } - } - return true; - } - - return false; - } - - /** - * Cache Purge - * - * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. - * - * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. - * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) - */ - function cache_purge($type = '', $style_id = 0) - { - global $auth, $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $type)) - { - return; - } - - $style_id = (int) $style_id; - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'auth' : - $this->umil_start('AUTH_CACHE_PURGE'); - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - break; - - case 'imageset' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT imageset_id - FROM ' . STYLES_IMAGESET_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('imageset', $row['imageset_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_IMAGESET_TABLE . " - WHERE imageset_id = $style_id"; - $result = $this->db->sql_query($sql); - $imageset_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$imageset_row) - { - $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); - - // The following is from includes/acp/acp_styles.php (edited) - $sql_ary = array(); - - $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); - - $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' - WHERE imageset_id = ' . $style_id; - $result = $this->db->sql_query($sql); - - foreach ($cfg_data_imageset as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => '', - ); - } - } - - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) - { - $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => (string) $row['lang_dir'], - ); - } - } - } - } - $this->db->sql_freeresult($result); - - $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); - - $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); - - return $this->umil_end(); - } - break; - //case 'imageset' : - - case 'template' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT template_id - FROM ' . STYLES_TEMPLATE_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('template', $row['template_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - $template_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$template_row) - { - $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); - - // The following is from includes/acp/acp_styles.php - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) - { - $filelist = array('' => array()); - - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { -// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) -// { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); - } -// } - } - $this->db->sql_freeresult($result); - - $includes = array(); - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) - { - return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); - } - $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); - fclose($fp); - - if (preg_match_all('##is', $template_data, $matches)) - { - foreach ($matches[1] as $match) - { - $includes[trim($match)][] = $file; - } - } - } - } - - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - // Skip index. - if (strpos($file, 'index.') === 0) - { - continue; - } - - // We could do this using extended inserts ... but that could be one - // heck of a lot of data ... - $sql_ary = array( - 'template_id' => (int) $style_id, - 'template_filename' => "$pathfile$file", - 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', - 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - ); - - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE template_id = $style_id - AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; - $this->db->sql_query($sql); - } - } - unset($filelist); - } - - // Purge the forum's cache as well. - $cache->purge(); - - return $this->umil_end(); - } - break; - //case 'template' : - - case 'theme' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT theme_id - FROM ' . STYLES_THEME_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('theme', $row['theme_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $style_id"; - $result = $this->db->sql_query($sql); - $theme_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$theme_row) - { - $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); - - // The following is from includes/acp/acp_styles.php - if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) - { - $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) - { - continue; - } - - $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); - $stylesheet = str_replace($match, $content, $stylesheet); - } - } - - // adjust paths - $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); - - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => $db_theme_data, - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $this->db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - } - - return $this->umil_end(); - } - break; - //case 'theme' : - - default: - $this->umil_start('CACHE_PURGE'); - $cache->purge(); - - return $this->umil_end(); - break; - } - } - - /** - * Config Exists - * - * This function is to check to see if a config variable exists or if it does not. - * - * @param string $config_name The name of the config setting you wish to check for. - * @param bool $return_result - return the config value/default if true : default false. - * - * @return bool true/false if config exists - */ - function config_exists($config_name, $return_result = false) - { - global $config, $cache; - - $sql = 'SELECT * - FROM ' . CONFIG_TABLE . " - WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - if (!isset($config[$config_name])) - { - $config[$config_name] = $row['config_value']; - - if (!$row['is_dynamic']) - { - $cache->destroy('config'); - } - } - - return ($return_result) ? $row : true; - } - - // this should never happen, but if it does, we need to remove the config from the array - if (isset($config[$config_name])) - { - unset($config[$config_name]); - $cache->destroy('config'); - } - - return false; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_add($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_ADD', $config_name); - - if ($this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_update($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_UPDATE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - * - * @return result - */ - function config_remove($config_name) - { - global $cache, $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_REMOVE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $this->db->sql_query($sql); - - unset($config[$config_name]); - $cache->destroy('config'); - - return $this->umil_end(); - } - - /** - * Module Exists - * - * Check if a module exists - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - */ - function module_exists($class, $parent, $module) - { - // the main root directory should return true - if (!$module) - { - return true; - } - - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return false; - } - - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_class = '$class' - $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Module Add - * - * Add a new module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_add($class, $parent = 0, $data = array(), $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Prevent stupid things like trying to add a module with no name or any data on it - if (empty($data)) - { - $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - // allow sending the name as a string in $data to create a category - if (!is_array($data)) - { - $data = array('module_langname' => $data); - } - - if (!isset($data['module_langname'])) - { - // The "automatic" way - $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; - $basename = str_replace(array('/', '\\'), '', $basename); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_ADD', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module = $info->module(); - unset($info); - - $result = ''; - foreach ($module['modes'] as $mode => $module_info) - { - if (!isset($data['modes']) || in_array($mode, $data['modes'])) - { - $new_module = array( - 'module_basename' => $basename, - 'module_langname' => $module_info['title'], - 'module_mode' => $mode, - 'module_auth' => $module_info['auth'], - 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, - 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, - 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, - ); - - // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); - } - } - - return $result; - } - - // The "manual" way - $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - $parent = $data['parent_id'] = $row['module_id']; - } - else if (!$this->module_exists($class, false, $parent)) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - if ($this->module_exists($class, $parent, $data['module_langname'])) - { - return $this->umil_end('MODULE_ALREADY_EXIST'); - } - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - - $module_data = array( - 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, - 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, - 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', - 'module_class' => $class, - 'parent_id' => (int) $parent, - 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', - 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', - 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', - ); - $result = $acp_modules->update_module_data($module_data, true); - - // update_module_data can either return a string or an empty array... - if (is_string($result)) - { - // Error - $this->result = $this->get_output_text($result); - } - else - { - // Success - - // Move the module if requested above/below an existing one - if (isset($data['before']) && $data['before']) - { - $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; - $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_left - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - else if (isset($data['after']) && $data['after']) - { - $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; - $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_right - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - } - - // Clear the Modules Cache - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - - /** - * Module Remove - * - * Remove a module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_remove($class, $parent = 0, $module = '', $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto - if (is_array($module)) - { - if (isset($module['module_langname'])) - { - // Manual Method - return $this->module_remove($class, $parent, $module['module_langname'], $include_path); - } - - // Failed. - if (!isset($module['module_basename'])) - { - $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Automatic method - $basename = str_replace(array('/', '\\'), '', $module['module_basename']); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_REMOVE', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module_info = $info->module(); - unset($info); - - $result = ''; - foreach ($module_info['modes'] as $mode => $info) - { - if (!isset($module['modes']) || in_array($mode, $module['modes'])) - { - $result .= $this->module_remove($class, $parent, $info['title']) . '
'; - } - } - return $result; - } - else - { - $class = $this->db->sql_escape($class); - - if (!$this->module_exists($class, $parent, $module)) - { - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); - return $this->umil_end('MODULE_NOT_EXIST'); - } - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $module_ids = array(); - if (!is_numeric($module)) - { - $module = $this->db->sql_escape($module); - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $module_ids[] = (int) $row['module_id']; - } - $this->db->sql_freeresult($result); - - $module_name = $module; - } - else - { - $module = (int) $module; - $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " - WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $module_name = $row['module_langname']; - $module_ids[] = $module; - } - - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - $acp_modules->module_class = $class; - - foreach ($module_ids as $module_id) - { - $result = $acp_modules->delete_module($module_id); - if (!empty($result)) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = implode('
', $result); - } - else - { - $this->result .= '
' . implode('
', $result); - } - } - } - - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - } - - /** - * Permission Exists - * - * Check if a permission (auth) setting exists - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return bool true if it exists, false if not - */ - function permission_exists($auth_option, $global = true) - { - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" - . $type_sql; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Permission Add - * - * Add a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_add($auth_option, $global = true) - { - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_ADD', $auth_option); - - if ($this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); - } - - // We've added permissions, so set to true to notify the user. - $this->permissions_added = true; - - if (!class_exists('auth_admin')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - } - $auth_admin = new auth_admin(); - - // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. - if ($this->permission_exists($auth_option, !$global)) - { - $sql_ary = array( - 'is_global' => 1, - 'is_local' => 1, - ); - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; - $this->db->sql_query($sql); - } - else - { - if ($global) - { - $auth_admin->acl_add_option(array('global' => array($auth_option))); - } - else - { - $auth_admin->acl_add_option(array('local' => array($auth_option))); - } - } - - return $this->umil_end(); - } - - /** - * Permission Remove - * - * Remove a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_remove($auth_option, $global = true) - { - global $auth, $cache; - - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_REMOVE', $auth_option); - - if (!$this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); - } - - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . - $type_sql; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $id = $row['auth_option_id']; - - // If it is a local and global permission, do not remove the row! :P - if ($row['is_global'] && $row['is_local']) - { - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' - WHERE auth_option_id = ' . $id; - $this->db->sql_query($sql); - } - else - { - // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); - } - - // Purge the auth cache - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Add a new permission role - * - * @param string $role_name The new role name - * @param sting $role_type The type (u_, m_, a_) - */ - function permission_role_add($role_name, $role_type = '', $role_description = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_ADD', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if ($role_id) - { - return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); - } - - $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' - WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; - $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); - $role_order = (!$role_order) ? 1 : $role_order + 1; - - $sql_ary = array( - 'role_name' => $role_name, - 'role_description' => $role_description, - 'role_type' => $role_type, - 'role_order' => $role_order, - ); - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Update the name on a permission role - * - * @param string $old_role_name The old role name - * @param string $new_role_name The new role name - */ - function permission_role_update($old_role_name, $new_role_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); - } - - $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' - SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Remove a permission role - * - * @param string $role_name The role name to remove - */ - function permission_role_remove($role_name) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $role_name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Set - * - * Allows you to set permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission - */ - function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $new_auth = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $new_auth[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($new_auth)) - { - return false; - } - - $current_auth = array(); - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_SET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_SET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will add the requested permissions to that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0 - AND forum_id = 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_set($role_name, $auth_option, 'role', $has_permission); - } - - $this->umil_start('PERMISSION_SET_GROUP', $name); - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - } - - $sql_ary = array(); - switch ($type) - { - case 'role' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'role_id' => $role_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); - break; - - case 'group' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'group_id' => $group_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Unset - * - * Allows you to unset (remove) permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - */ - function permission_unset($name, $auth_option = array(), $type = 'role') - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $to_remove = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $to_remove[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($to_remove)) - { - return false; - } - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_UNSET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will remove the requested permissions from that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_unset($role_name, $auth_option, 'role'); - } - - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - - $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Table Exists - * - * Check if a table exists in the DB or not - * - * @param string $table_name The table name to check for - * - * @return bool true if the table exists, false if not - */ - function table_exists($table_name) - { - $this->get_table_name($table_name); - - // Use sql_table_exists if available - if (method_exists($this->db_tools, 'sql_table_exists')) - { - $roe = $this->db->return_on_error; - $result = $this->db_tools->sql_table_exists($table_name); - - // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before - if ($roe) - { - $this->db->sql_return_on_error(true); - } - - return $result; - } - - if (!function_exists('get_tables')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/functions_install.' . $phpEx); - } - - $tables = get_tables($this->db); - - if (in_array($table_name, $tables)) - { - return true; - } - else - { - return false; - } - } - - /** - * Table Add - * - * This only supports input from the array format of db_tools or create_schema_files. - */ - function table_add($table_name, $table_data = array()) - { - global $dbms, $user; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error - */ - if (empty($table_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ADD', $table_name); - - if ($this->table_exists($table_name)) - { - return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); - } - - if (!is_array($table_data)) - { - return $this->umil_end('NO_TABLE_DATA'); - } - - if (!function_exists('get_available_dbms')) - { - global $phpbb_root_path, $phpEx; - include("{$phpbb_root_path}includes/functions_install.$phpEx"); - } - - /* - * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore - if (method_exists($this->db_tools, 'sql_create_table')) - { - // Added in 3.0.5 - $this->db_tools->sql_create_table($table_name, $table_data); - } - else - {*/ - $available_dbms = get_available_dbms($dbms); - - $sql_query = $this->create_table_sql($table_name, $table_data); - $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); - - foreach ($sql_query as $sql) - { - $this->db->sql_query($sql); - } - //} - - return $this->umil_end(); - } - - /** - * Table Remove - * - * Delete/Drop a DB table - */ - function table_remove($table_name) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_REMOVE', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - if (method_exists($this->db_tools, 'sql_table_drop')) - { - // Added in 3.0.5 - $this->db_tools->sql_table_drop($table_name); - } - else - { - $this->db->sql_query('DROP TABLE ' . $table_name); - } - - return $this->umil_end(); - } - - /** - * Table Column Exists - * - * Check to see if a column exists in a table - */ - function table_column_exists($table_name, $column_name) - { - $this->get_table_name($table_name); - - return $this->db_tools->sql_column_exists($table_name, $column_name); - } - - /** - * Table Column Add - * - * Add a new column to a table. - */ - function table_column_add($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error - */ - if (empty($column_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); - - if ($this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); - } - - $this->db_tools->sql_column_add($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Update - * - * Alter/Update a column in a table. You can not change a column name with this. - */ - function table_column_update($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_change($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Remove - * - * Remove a column from a table - */ - function table_column_remove($table_name, $column_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_remove($table_name, $column_name); - - return $this->umil_end(); - } - - /** - * Table Index Exists - * - * Check if a table key/index exists on a table (can not check primary or unique) - */ - function table_index_exists($table_name, $index_name) - { - $this->get_table_name($table_name); - - $indexes = $this->db_tools->sql_list_index($table_name); - - if (in_array($index_name, $indexes)) - { - return true; - } - - return false; - } - - /** - * Table Index Add - * - * Add a new key/index to a table - */ - function table_index_add($table_name, $index_name = '', $column = array()) - { - global $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - // Let them skip the column field and just use the index name in that case as the column as well - if (empty($column)) - { - $column = array($index_name); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); - - if ($this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); - } - - if (!is_array($column)) - { - $column = array($column); - } - - // remove index length if we are before 3.0.8 - // the feature (required for some types when using MySQL4) - // was added in that release (ticket PHPBB3-8944) - if (version_compare($config['version'], '3.0.7-pl1', '<=')) - { - $column = preg_replace('#:.*$#', '', $column); - } - - $this->db_tools->sql_create_index($table_name, $index_name, $column); - - return $this->umil_end(); - } - - /** - * Table Index Remove - * - * Remove a key/index from a table - */ - function table_index_remove($table_name, $index_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); - - if (!$this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); - } - - $this->db_tools->sql_index_drop($table_name, $index_name); - - return $this->umil_end(); - } - - // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility - function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } - - /** - * Table Insert - * - * Insert data into a table - */ - function table_row_insert($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $this->db->sql_multi_insert($table_name, $data); - - return $this->umil_end(); - } - - /** - * Table Row Update - * - * Update a row in a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - * - * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). - */ - function table_row_update($table_name, $data = array(), $new_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'UPDATE ' . $table_name . ' - SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' - WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Table Row Remove - * - * Remove a row from a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - */ - function table_row_remove($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Version Checker - * - * Format the file like the following: - * http://www.phpbb.com/updatecheck/30x.txt - * - * @param string $url The url to access (ex: www.phpbb.com) - * @param string $path The path to access (ex: /updatecheck) - * @param string $file The name of the file to access (ex: 30x.txt) - * - * @return array|string Error Message if there was any error, or an array (each line in the file as a value) - */ - function version_check($url, $path, $file, $timeout = 10, $port = 80) - { - if (!function_exists('get_remote_file')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } - - $errstr = $errno = ''; - - $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); - - if ($info === false) - { - return $errstr . ' [ ' . $errno . ' ]'; - } - - $info = str_replace("\r\n", "\n", $info); - $info = explode("\n", $info); - - return $info; - } - - /** - * Create table SQL - * - * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array - * - * @param string $table_name The name of the table - * @param array $table_data The table data (formatted in the array format used by create_schema_files) - * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) - * - * @return The sql query to run for the submitted dbms to insert the table - */ - function create_table_sql($table_name, $table_data, $dbms = '') - { - // To allow testing - $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; - - // A list of types being unsigned for better reference in some db's - $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); - $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); - - $sql = ''; - - // Create Table statement - $generator = $textimage = false; - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'firebird': - case 'oracle': - case 'sqlite': - case 'postgres': - $sql .= "CREATE TABLE {$table_name} (\n"; - break; - - case 'mssql': - $sql .= "CREATE TABLE [{$table_name}] (\n"; - break; - } - - // Table specific so we don't get overlap - $modded_array = array(); - - // Write columns one by one... - foreach ($table_data['COLUMNS'] as $column_name => $column_data) - { - // Get type - if (strpos($column_data[0], ':') !== false) - { - list($orig_column_type, $column_length) = explode(':', $column_data[0]); - if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); - } - else - { - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) - { - case 'div': - $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; - $column_length = ceil($column_length); - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - break; - } - } - - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) - { - case 'mult': - $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; - if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) - { - $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; - $modded_array[$column_name] = $column_type; - } - else - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - } - break; - } - } - } - $orig_column_type .= ':'; - } - else - { - $orig_column_type = $column_data[0]; - $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; - if ($column_type == 'text' || $column_type == 'blob') - { - $modded_array[$column_name] = $column_type; - } - } - - // Adjust default value if db-dependant specified - if (is_array($column_data[1])) - { - $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= "\t{$column_name} {$column_type} "; - - // For hexadecimal values do not use single quotes - if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') - { - $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; - } - $sql .= 'NOT NULL'; - - if (isset($column_data[2])) - { - if ($column_data[2] == 'auto_increment') - { - $sql .= ' auto_increment'; - } - else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') - { - $sql .= ' COLLATE utf8_unicode_ci'; - } - } - - $sql .= ",\n"; - break; - - case 'sqlite': - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; - $generator = $column_name; - } - else - { - $sql .= "\t{$column_name} {$column_type} "; - } - - $sql .= 'NOT NULL '; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; - $sql .= ",\n"; - break; - - case 'firebird': - $sql .= "\t{$column_name} {$column_type} "; - - if (!is_null($column_data[1])) - { - $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; - } - - $sql .= 'NOT NULL'; - - // This is a UNICODE column and thus should be given it's fair share - if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) - { - $sql .= ' COLLATE UNICODE'; - } - - $sql .= ",\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'mssql': - if ($column_type == '[text]') - { - $textimage = true; - } - - $sql .= "\t[{$column_name}] {$column_type} "; - - if (!is_null($column_data[1])) - { - // For hexadecimal values do not use single quotes - if (strpos($column_data[1], '0x') === 0) - { - $sql .= 'DEFAULT (' . $column_data[1] . ') '; - } - else - { - $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; - } - } - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= 'IDENTITY (1, 1) '; - } - - $sql .= 'NOT NULL'; - $sql .= " ,\n"; - break; - - case 'oracle': - $sql .= "\t{$column_name} {$column_type} "; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - - // In Oracle empty strings ('') are treated as NULL. - // Therefore in oracle we allow NULL's for all DEFAULT '' entries - $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'postgres': - $sql .= "\t{$column_name} {$column_type} "; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; - - // Make sure the sequence will be created before creating the table - $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; - } - else - { - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - $sql .= "NOT NULL"; - - // Unsigned? Then add a CHECK contraint - if (in_array($orig_column_type, $unsigned_types)) - { - $sql .= " CHECK ({$column_name} >= 0)"; - } - - $sql .= ",\n"; - } - break; - } - } - - switch ($dbms) - { - case 'firebird': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);;\n\n"; - break; - - case 'mssql': - $sql = substr($sql, 0, -2); - $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; - $sql .= "GO\n\n"; - break; - } - - // Write primary key - if (isset($table_data['PRIMARY_KEY'])) - { - if (!is_array($table_data['PRIMARY_KEY'])) - { - $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'postgres': - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - - case 'firebird': - $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; - break; - - case 'sqlite': - if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) - { - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - } - break; - - case 'mssql': - $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; - $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; - $sql .= "\t(\n"; - $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; - $sql .= "\t) ON [PRIMARY] \n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - } - } - - switch ($dbms) - { - case 'oracle': - // UNIQUE contrains to be added? - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - if ($key_data[0] == 'UNIQUE') - { - $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; - } - } - } - - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n)\n/\n\n"; - break; - - case 'postgres': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'sqlite': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - } - - // Write Keys - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; - foreach ($key_data[1] as $key => $col_name) - { - if (isset($modded_array[$col_name])) - { - switch ($modded_array[$col_name]) - { - case 'text': - case 'blob': - $key_data[1][$key] = $col_name . '(255)'; - break; - } - } - } - $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; - break; - - case 'firebird': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; - break; - - case 'mssql': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - if ($key_data[0] == 'UNIQUE') - { - continue; - } - - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; - $sql .= "/\n"; - break; - - case 'sqlite': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - - case 'postgres': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - } - } - } - - switch ($dbms) - { - case 'mysql_40': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'mysql_41': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; - break; - - // Create Generator - case 'firebird': - if ($generator !== false) - { - $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; - $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; - - $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; - $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; - $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; - } - break; - - case 'oracle': - if ($generator !== false) - { - $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; - - $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; - $sql .= "BEFORE INSERT ON {$table_name}\n"; - $sql .= "FOR EACH ROW WHEN (\n"; - $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; - $sql .= ")\nBEGIN\n"; - $sql .= "\tSELECT {$table_name}_seq.nextval\n"; - $sql .= "\tINTO :new.{$generator}\n"; - $sql .= "\tFROM dual;\nEND;\n/\n\n"; - } - break; - } - - return $sql; - } - - /** - * Get the real table name - * By A_Jelly_Doughnut - * - * @param string $table_name The table name to get the real table name from - */ - function get_table_name(&$table_name) - { - // Use the global table prefix if a custom one is not specified - if ($this->table_prefix === false) - { - global $table_prefix; - } - else - { - $table_prefix = $this->table_prefix; - } - - static $constants = NULL; - - if (is_null($constants)) - { - $constants = get_defined_constants(); - } - - /** - * only do the replace if the table prefix is not already present - * this is required since UMIL supports specifying a table via phpbb_foo - * (where a replace would be needed) - * or by FOO_TABLE (where a replace is already done at constant-define time) - */ - if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) - { - $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); - } - } -} - -?> \ No newline at end of file diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 912a7b34ba..9f94273c63 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -45,10 +45,10 @@ class phpbb_db_migrator * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migrator(&$db, &$db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { - $this->db = &$db; - $this->db_tools = &$db_tools; + $this->db = $db; + $this->db_tools = $db_tools; $this->table_prefix = $table_prefix; $this->migrations_table = $migrations_table; $this->migrations = array(); @@ -131,7 +131,7 @@ class phpbb_db_migrator return false; } - $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -182,7 +182,7 @@ class phpbb_db_migrator return true; } - function process_data_step(&$migration) + function process_data_step($migration) { $continue = false; $steps = $migration->update_data(); @@ -199,7 +199,7 @@ class phpbb_db_migrator return $continue; } - function run_step(&$step) + function run_step($step) { } @@ -234,7 +234,7 @@ class phpbb_db_migrator return true; } - $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $depends = $migration->depends_on(); foreach ($depends as $depend) -- cgit v1.2.1 From 41de95bc11c0b64eafa294f03432f619d3d712d5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 12:12:05 +0100 Subject: [feature/migrations] Process migration steps and move to PHP5 code --- phpBB/includes/db/migration.php | 26 ++++----- phpBB/includes/db/migrator.php | 126 ++++++++++++++++++++++++++++++++++------ 2 files changed, 120 insertions(+), 32 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index c98ac8728a..4e83d2570c 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -26,14 +26,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration { - var $db; - var $db_tools; - var $table_prefix; + protected $db; + protected $db_tools; + protected $table_prefix; - var $phpbb_root_path; - var $php_ext; + protected $phpbb_root_path; + protected $php_ext; - var $errors; + protected $errors; /** * Migration constructor @@ -44,7 +44,7 @@ class phpbb_db_migration * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) + public function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) { $this->db = $db; $this->db_tools = $db_tools; @@ -61,7 +61,7 @@ class phpbb_db_migration * * @return array An array of migration class names */ - function depends_on() + public function depends_on() { return array(); } @@ -71,24 +71,24 @@ class phpbb_db_migration * * @return array */ - function update_schema() + public function update_schema() { return array(); } /** - * Updates data + * Updates data by returning a list of instructions to be executed * - * @return null + * @return array */ - function update_data() + public function update_data() { } /** * Wrapper for running queries to generate user feedback on updates */ - function sql_query($sql) + protected function sql_query($sql) { if (defined('DEBUG_EXTRA')) { diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 9f94273c63..9187e09869 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,17 +22,17 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { - var $db; - var $db_tools; - var $table_prefix; + protected $db; + protected $db_tools; + protected $table_prefix; - var $phpbb_root_path; - var $php_ext; + protected $phpbb_root_path; + protected $php_ext; - var $migrations_table; - var $migration_state; + protected $migrations_table; + protected $migration_state; - var $migrations; + protected $migrations; /** * Constructor of the database migrator @@ -45,7 +45,7 @@ class phpbb_db_migrator * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + public function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { $this->db = $db; $this->db_tools = $db_tools; @@ -64,7 +64,7 @@ class phpbb_db_migrator * * @return null */ - function load_migration_state() + public function load_migration_state() { $sql = "SELECT * FROM " . $this->migrations_table; @@ -85,7 +85,7 @@ class phpbb_db_migrator * @param array $class_names An array of migration class names * @return null */ - function set_migrations($class_names) + public function set_migrations($class_names) { $this->migrations = $class_names; } @@ -98,7 +98,7 @@ class phpbb_db_migrator * * @return null */ - function update() + public function update() { foreach ($this->migrations as $name) { @@ -124,7 +124,7 @@ class phpbb_db_migrator * @param string The class name of the migration * @return bool Whether any update step was successfully run */ - function try_apply($name) + protected function try_apply($name) { if (!class_exists($name)) { @@ -182,7 +182,7 @@ class phpbb_db_migrator return true; } - function process_data_step($migration) + protected function process_data_step($migration) { $continue = false; $steps = $migration->update_data(); @@ -190,6 +190,7 @@ class phpbb_db_migrator foreach ($steps as $step) { $continue = $this->run_step($step); + if (!$continue) { return false; @@ -199,12 +200,99 @@ class phpbb_db_migrator return $continue; } - function run_step($step) + protected function run_step($step) { + try + { + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $parameters = $callable_and_parameters[1]; + + call_user_func_array($callable, $parameters); + + return false; + } + catch (phpbb_db_migration_exception $e) + { + echo $e;die(); + } + } + public function get_callable_from_step($step) + { + $type = $step[0]; + $parameters = $step[1]; + + $parts = explode('.', $type); + + $class = $parts[0]; + $method = false; + + if (isset($parts[1])) + { + $method = $parts[1]; + } + + switch ($class) + { + case 'if': + if (!isset($parameters[0])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step); + } + + if (!isset($parameters[1])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step); + } + + $condition = $parameters[0]; + $step = $parameters[1]; + + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $sub_parameters = $callable_and_parameters[1]; + return array( + function ($condition) use ($callable, $sub_parameters) { + return call_user_func_array($callable, $sub_parameters); + }, + array($condition) + ); + break; + case 'custom': + if (!is_callable($parameters[0])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); + } + + return array($parameters[0], array()); + break; + + default: + if (!$method) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step); + } + + if (!isset($this->tools[$class])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step); + } + + if (!method_exists(get_class($this->tools[$class]), $method)) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); + } + + return array( + array($this->tools[$class], $method), + $parameters + ); + break; + } } - function insert_migration($name, $state) + protected function insert_migration($name, $state) { $migration_row = $state; $migration_row['migration_name'] = $name; @@ -222,7 +310,7 @@ class phpbb_db_migrator * @param string $name The class name of the migration * @return bool Whether the migration cannot be fulfilled */ - function unfulfillable($name) + public function unfulfillable($name) { if (isset($this->migration_state[$name])) { @@ -253,7 +341,7 @@ class phpbb_db_migrator * * @return bool Whether the migrations have been applied */ - function finished() + public function finished() { foreach ($this->migrations as $name) { @@ -279,7 +367,7 @@ class phpbb_db_migrator return true; } - function apply_schema_changes($schema_changes) + protected function apply_schema_changes($schema_changes) { $this->db_tools->perform_schema_changes($schema_changes); } -- cgit v1.2.1 From 6c44dadecbf50d6550f98dd1e1694519f39be680 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:26 -0600 Subject: [feature/migrations] Move migrator to service container Version numbers 3.1 updates Restore database_update.php file to what it was in develop Get first forum to place global announcements in PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 10 + phpBB/includes/db/migration.php | 20 +- phpBB/includes/db/migration/data/3_0_1.php | 3 + phpBB/includes/db/migration/data/3_0_10.php | 3 + phpBB/includes/db/migration/data/3_0_10_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_10_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_10_rc3.php | 3 + phpBB/includes/db/migration/data/3_0_11.php | 3 + phpBB/includes/db/migration/data/3_0_11_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_11_rc2 | 31 --- phpBB/includes/db/migration/data/3_0_11_rc2.php | 34 +++ phpBB/includes/db/migration/data/3_0_12_rc1.php | 8 +- phpBB/includes/db/migration/data/3_0_1_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_2.php | 3 + phpBB/includes/db/migration/data/3_0_2_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_2_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_3.php | 5 +- phpBB/includes/db/migration/data/3_0_3_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_4.php | 2 + phpBB/includes/db/migration/data/3_0_4_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_5.php | 3 + .../includes/db/migration/data/3_0_5_rc1part2.php | 3 + phpBB/includes/db/migration/data/3_0_6.php | 3 + phpBB/includes/db/migration/data/3_0_6_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_6_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_6_rc3.php | 2 + phpBB/includes/db/migration/data/3_0_6_rc4.php | 3 + phpBB/includes/db/migration/data/3_0_7.php | 3 + phpBB/includes/db/migration/data/3_0_7_pl1.php | 3 + phpBB/includes/db/migration/data/3_0_7_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 2 + phpBB/includes/db/migration/data/3_0_8.php | 3 + phpBB/includes/db/migration/data/3_0_8_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_9.php | 3 + phpBB/includes/db/migration/data/3_0_9_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_9_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_9_rc3.php | 3 + phpBB/includes/db/migration/data/3_0_9_rc4.php | 3 + phpBB/includes/db/migration/data/3_1_0_dev.php | 283 +++++++++++++++++++++ phpBB/includes/db/migration/data/extensions.php | 48 ++++ .../includes/db/migration/data/style_update_p1.php | 99 +++++++ .../includes/db/migration/data/style_update_p2.php | 83 ++++++ phpBB/includes/db/migration/data/timezone.php | 158 ++++++++++++ phpBB/includes/db/migration/tools/base.php | 47 ---- phpBB/includes/db/migration/tools/config.php | 26 +- phpBB/includes/db/migration/tools/module.php | 38 ++- phpBB/includes/db/migration/tools/permission.php | 26 +- phpBB/includes/db/migrator.php | 35 +-- phpBB/includes/update_helpers.php | 112 -------- 49 files changed, 906 insertions(+), 242 deletions(-) delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2 create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_1_0_dev.php create mode 100644 phpBB/includes/db/migration/data/extensions.php create mode 100644 phpBB/includes/db/migration/data/style_update_p1.php create mode 100644 phpBB/includes/db/migration/data/style_update_p2.php create mode 100644 phpBB/includes/db/migration/data/timezone.php delete mode 100644 phpBB/includes/db/migration/tools/base.php delete mode 100644 phpBB/includes/update_helpers.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 2bb016cebd..5329d871c8 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -345,6 +345,16 @@ class phpbb_db_tools } } + /** + * Setter for {@link $return_statements return_statements}. + * + * @param bool $return_statements True if SQL should not be executed but returned as strings + */ + public function set_return_statements($return_statements) + { + $this->return_statements = $return_statements; + } + /** * Gets a list of tables in the database. * diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index 4e83d2570c..1acef2d429 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -26,6 +26,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration { + protected $config; protected $db; protected $db_tools; protected $table_prefix; @@ -38,20 +39,17 @@ class phpbb_db_migration /** * Migration constructor * - * @param dbal $db Connected database abstraction instance - * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools - * @param string $table_prefix The prefix for all table names - * @param string $phpbb_root_path - * @param string $php_ext + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) + public function phpbb_db_migration(\Symfony\Component\DependencyInjection\ContainerInterface $container) { - $this->db = $db; - $this->db_tools = $db_tools; - $this->table_prefix = $table_prefix; + $this->config = $this->container->get('config'); + $this->db = $this->container->get('dbal.conn'); + $this->db_tools = $this->container->get('dbal.tools'); + $this->table_prefix = $this->container->getParameters('core.table_prefix'); - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->phpbb_root_path = $this->container->getParameters('core.root_path'); + $this->php_ext = $this->container->getParameters('core.php_ext'); $this->errors = array(); } diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index 294db3d946..a2332c9b59 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.1')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 6d39969d48..07410c5ba1 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.10')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index 06105c5b0d..daac50a631 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration { return array( array('config.add', array('email_max_chunk_size', 50)), + + array('config.update', array('version', '3.0.10-rc1')), ); } } diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index 04161caf28..234e4c5fc7 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.10-rc2')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index 539f0b8fec..075ce35e3e 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.10-rc3')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index 3404272ef9..0bc9b6c4a5 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.11')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index f44226df02..1509120f68 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -24,6 +24,8 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration return array( array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), array('custom', array(array(&$this, 'delete_orphan_private_messages'))), + + array('config.update', array('version', '3.0.11-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2 b/phpBB/includes/db/migration/data/3_0_11_rc2 deleted file mode 100644 index 6add980c73..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc2 +++ /dev/null @@ -1,31 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php new file mode 100644 index 0000000000..f2bed54085 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -0,0 +1,34 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.11-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 734a57ecee..e5ff8c5814 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -7,6 +7,9 @@ * */ +/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/ + +/* class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { function depends_on() @@ -16,11 +19,14 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration function update_schema() { - /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 */ return array(); } function update_data() { + return array( + array('config.update', array('version', '3.0.12-rc1')), + ); } } +*/ \ No newline at end of file diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index 1a696e0003..a3b4810d21 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -44,6 +44,8 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration return array( array('custom', array(array(&$this, 'fix_unset_last_view_time'))), array('custom', array(array(&$this, 'reset_smiley_size'))), + + array('config.update', array('version', '3.0.1-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index a5f94e644b..3469d8d178 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.2')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index 1b4d3bc2b8..d3c2200f14 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -7,7 +7,7 @@ * */ -class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration +class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration { function depends_on() { @@ -25,6 +25,8 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration array('config.add', array('referer_validation', '1')), array('config.add', array('check_attachment_content', '1')), array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')), + + array('config.update', array('version', '3.0.2-rc1')), ); } } diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index 9ddeb60a14..67fd1faec6 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -48,5 +48,8 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.2-rc2')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index f989eea025..dff375f438 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -11,7 +11,7 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration { function depends_on() { - return array('phpbb_db_migration_data_3_0_2_rc2'); + return array('phpbb_db_migration_data_3_0_3_rc1'); } function update_schema() @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.3')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 737eab4bd3..d5c110eb7d 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -39,6 +39,8 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration array('config.add', array('dbms_version', '')), array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + + array('config.update', array('version', '3.0.3-rc1')), )); } diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index cd34fda9ab..4965ac38d0 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'rename_log_delete_topic'))), + + array('config.update', array('version', '3.0.4')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index 342f1fa910..2964dcebc9 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -59,6 +59,8 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'update_custom_profile_fields'))), + + array('config.update', array('version', '3.0.4-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 5671832a82..2f80970781 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.5')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 6be8ea9845..1fab0f8873 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -30,5 +30,8 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.5-rc1')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index c2cb59e62a..26176b9437 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.6')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index eefdc1692d..a868d70684 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -155,6 +155,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration )), array('custom', array(array(&$this, 'add_newly_registered_group'))), array('custom', array(array(&$this, 'set_user_options_default'))), + + array('config.update', array('version', '3.0.6-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index 07b31a53b9..4092a5fa61 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.6-rc2')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index c19a792bad..ec22d1da77 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'update_cp_fields'))), + + array('config.update', array('version', '3.0.6-rc3')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index c48b1ca394..e748c7a4ff 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.6-rc4')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index 05781b7b49..f27b56f778 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.7')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index cee7a91a2e..5543d6437a 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.7-pl1')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index b2d49cce63..71584382e8 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -38,6 +38,8 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), array('custom', array(array(&$this, 'delete_text_templates'))), + + array('config.update', array('version', '3.0.7-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index 8a751328bf..e043f35705 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'update_email_hash'))), + + array('config.update', array('version', '3.0.7-rc2')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index a714a3d2f6..a5defc8278 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.8')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index 73838d9d29..3f51806fd9 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -37,6 +37,8 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration array('config.add', array('load_unreads_search', 1)), array('config.update_if_equals', array(600, 'queue_interval', 60)), array('config.update_if_equals', array(50, 'email_package_size', 20)), + + array('config.update', array('version', '3.0.8-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index 4b2c08a256..eb359e2697 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.9')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index 98d3a26481..256426849c 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -59,6 +59,8 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration array('config.add', array('ip_login_limit_use_forwarded', 0)), array('custom', array(array(&$this, 'update_file_extension_group_names'))), array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + + array('config.update', array('version', '3.0.9-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index 589047670a..e3c4716665 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.9-rc2')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index 06061cbcb6..3cdecb96ae 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.9-rc3')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index 04b3ae4b39..c2a92e618a 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.9-rc4')), + ); } } diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php new file mode 100644 index 0000000000..987ab94646 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -0,0 +1,283 @@ + array( + GROUPS_TABLE => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + PROFILE_FIELDS_TABLE => array( + 'field_show_on_pm' => array('BOOL', 0), + ), + STYLES_TABLE => array( + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), + ), + REPORTS_TABLE => array( + 'reported_post_text' => array('MTEXT_UNI', ''), + 'reported_post_uid' => array('VCHAR:8', ''), + 'reported_post_bitfield' => array('VCHAR:255', ''), + ), + ), + 'change_columns' => array( + GROUPS_TABLE => array( + 'group_legend' => array('UINT', 0), + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + + array('config.add', array('fulltext_postgres_ts_name', 'simple')), + array('config.add', array('fulltext_postgres_min_word_len', 4)), + array('config.add', array('fulltext_postgres_max_word_len', 254)), + array('config.add', array('fulltext_sphinx_stopwords', 0)), + array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), + + array('config.add', array('load_jquery_cdn', 0)), + array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), + + array('config.add', array('use_system_cron', 0)), + + array('config.add', array('legend_sort_groupname', 0)), + array('config.add', array('teampage_forums', 1)), + array('config.add', array('teampage_memberships', 1)), + + array('config.add', array('load_cpf_pm', 0)), + + array('config.add', array('display_last_subject', 1)), + + array('config.add', array('assets_version', 1)), + + array('config.add', array('site_home_url', '')), + array('config.add', array('site_home_text', '')), + + array('module.add', array( + 'acp', + 'ACP_GROUPS', + array( + 'module_basename' => 'acp_groups', + 'modes' => array('position'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_ATTACHMENTS', + array( + 'module_basename' => 'acp_attachments', + 'modes' => array('manage'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_STYLE_MANAGEMENT', + array( + 'module_basename' => 'acp_styles', + 'modes' => array('install', 'cache'), + ), + )), + array('module.add', array( + 'acp', + 'UCP_PROFILE', + array( + 'module_basename' => 'ucp_profile', + 'modes' => array('autologin_keys'), + ), + )), + + array('module.remove', array( + 'acp', + 'ACP_CAT_STYLES', + array( + 'module_basename' => 'styles', + 'modes' => array('imageset', 'theme', 'template'), + ), + )), + + array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'add_group_teampage'))), + array('custom', array(array($this, 'update_group_legend'))), + array('custom', array(array($this, 'localise_global_announcements'))), + ); + } + + public function rename_module_basenames() + { + // rename all module basenames to full classname + $sql = 'SELECT module_id, module_basename, module_class + FROM ' . MODULES_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $module_id = (int) $row['module_id']; + unset($row['module_id']); + + if (!empty($row['module_basename']) && !empty($row['module_class'])) + { + // all the class names start with class name or with phpbb_ for auto loading + if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && + strpos($row['module_basename'], 'phpbb_') !== 0) + { + $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; + + $sql_update = $this->db->sql_build_array('UPDATE', $row); + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET ' . $sql_update . ' + WHERE module_id = ' . $module_id; + $this->sql_query($sql); + } + } + } + + $this->db->sql_freeresult($result); + } + + public function add_group_teampage() + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'ADMINISTRATORS'"; + $this->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + $this->sql_query($sql); + } + + public function update_group_legend() + { + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . ' + WHERE group_legend = 1 + ORDER BY group_name ASC'; + $result = $this->db->sql_query($sql); + + $next_legend = 1; + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_legend . ' + WHERE group_id = ' . (int) $row['group_id']; + $this->sql_query($sql); + + $next_legend++; + } + $this->db->sql_freeresult($result); + } + + public function localise_global_announcements() + { + // Localise Global Announcements + $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = 0 + AND topic_type = ' . POST_GLOBAL; + $result = $this->db->sql_query($sql); + + $global_announcements = $update_lastpost_data = array(); + $update_lastpost_data['forum_last_post_time'] = 0; + $update_forum_data = array( + 'forum_posts' => 0, + 'forum_topics' => 0, + 'forum_topics_real' => 0, + ); + + while ($row = $this->db->sql_fetchrow($result)) + { + $global_announcements[] = (int) $row['topic_id']; + + $update_forum_data['forum_posts'] += (int) $row['topic_posts']; + $update_forum_data['forum_topics_real']++; + if ($row['topic_approved']) + { + $update_forum_data['forum_topics']++; + } + + if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) + { + $update_lastpost_data = array( + 'forum_last_post_id' => (int) $row['topic_last_post_id'], + 'forum_last_post_subject' => $row['topic_last_post_subject'], + 'forum_last_post_time' => (int) $row['topic_last_post_time'], + 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], + 'forum_last_poster_name' => $row['topic_last_poster_name'], + 'forum_last_poster_colour' => $row['topic_last_poster_colour'], + ); + } + } + $this->db->sql_freeresult($result); + + if (!empty($global_announcements)) + { + // Update the post/topic-count for the forum and the last-post if needed + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST; + $result = $this->db->sql_query_limit($sql, 1); + $ga_forum_id = $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT forum_last_post_time + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $ga_forum_id; + $result = $this->db->sql_query($sql); + $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); + $this->db->sql_freeresult($result); + + $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; + $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; + $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; + if ($lastpost < $update_lastpost_data['forum_last_post_time']) + { + $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); + } + + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $sql_update . ' + WHERE forum_id = ' . $ga_forum_id; + $this->sql_query($sql); + + // Update some forum_ids + $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); + foreach ($table_ary as $table) + { + $sql = "UPDATE $table + SET forum_id = $ga_forum_id + WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); + $this->sql_query($sql); + } + unset($table_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php new file mode 100644 index 0000000000..85d5511ef0 --- /dev/null +++ b/phpBB/includes/db/migration/data/extensions.php @@ -0,0 +1,48 @@ + array( + EXT_TABLE => array( + 'COLUMNS' => array( + 'ext_name' => array('VCHAR', ''), + 'ext_active' => array('BOOL', 0), + 'ext_state' => array('TEXT', ''), + ), + 'KEYS' => array( + 'ext_name' => array('UNIQUE', 'ext_name'), + ), + ), + ), + ); + } + + public function update_data() + { + return array( + array('module.add', array( + 'acp', + 'ACP_GENERAL_TASKS', + array( + 'module_basename' => 'extensions', + 'modes' => array('main'), + ), + )), + ); + } +} diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php new file mode 100644 index 0000000000..d570caae04 --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -0,0 +1,99 @@ +isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) + { + $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); + if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) + { + // 3.1 style + $available_styles[] = $fileinfo->getFilename(); + } + } + } + + // Get all installed styles + if ($this->db_tools->sql_table_exists(STYLES_IMAGESET_TABLE)) + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + } + else + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id"; + } + $result = $this->db->sql_query($sql); + + $styles = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $styles[] = $row; + } + $this->db->sql_freeresult($result); + + // Decide which styles to keep, all others will be deleted + $valid_styles = array(); + foreach ($styles as $style_row) + { + if ( + // Delete styles with parent style (not supported yet) + $style_row['template_inherits_id'] == 0 && + // Check if components match + $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && + // Check if components are valid + in_array($style_row['template_path'], $available_styles) + ) + { + // Valid style. Keep it + $sql_ary = array( + 'style_path' => $style_row['template_path'], + 'bbcode_bitfield' => $style_row['bbcode_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + ); + $this->sql_query('UPDATE ' . STYLES_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE style_id = ' . $style_row['style_id'], $errored, $error_ary); + $valid_styles[] = (int) $style_row['style_id']; + } + } + } +} diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php new file mode 100644 index 0000000000..2c0991de59 --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -0,0 +1,83 @@ + array( + STYLES_TABLE => array( + 'imageset_id', + 'template_id', + 'theme_id', + ), + ), + + 'drop_tables' => array( + STYLES_IMAGESET_TABLE, + STYLES_IMAGESET_DATA_TABLE, + STYLES_TEMPLATE_TABLE, + STYLES_TEMPLATE_DATA_TABLE, + STYLES_THEME_TABLE, + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'styles_update'))), + ); + } + + public function styles_update() + { + // Remove old entries from styles table + if (!sizeof($valid_styles)) + { + // No valid styles: remove everything and add prosilver + $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + + $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; + $this->sql_query($sql); + + $sql = 'SELECT style_id + FROM ' . $table . " + WHERE style_name = 'prosilver'"; + $result = $this->sql_query($sql); + $default_style = $this->db->sql_fetchfield($result); + $this->db->sql_freeresult($result); + + set_config('default_style', $default_style); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $this->sql_query($sql); + } + else + { + // There are valid styles in styles table. Remove styles that are outdated + $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true), $errored, $error_ary); + + // Change default style + if (!in_array($config['default_style'], $valid_styles)) + { + set_config('default_style', $valid_styles[0]); + } + + // Reset styles for users + $this->sql_query('UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true), $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php new file mode 100644 index 0000000000..89fafbad28 --- /dev/null +++ b/phpBB/includes/db/migration/data/timezone.php @@ -0,0 +1,158 @@ + array( + USERS_TABLE => array( + 'user_timezone' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_timezones'))), + ); + } + + public function update_timezones() + { + // Update user timezones + $sql = 'SELECT user_dst, user_timezone + FROM ' . USERS_TABLE . ' + GROUP BY user_timezone, user_dst'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' + WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' + AND user_dst = " . (int) $row['user_dst']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + + // Update board default timezone + set_config('board_timezone', $this->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst'])); + + // After we have calculated the timezones we can delete user_dst column from user table. + $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); + } + + /** + * Determine the new timezone for a given phpBB 3.0 timezone and + * "Daylight Saving Time" option + * + * @param $timezone float Users timezone in 3.0 + * @param $dst int Users daylight saving time + * @return string Users new php Timezone which is used since 3.1 + */ + public function convert_phpbb30_timezone($timezone, $dst) + { + $offset = $timezone + $dst; + + switch ($timezone) + { + case '-12': + return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' + case '-11': + return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' + case '-10': + return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' + case '-9.5': + return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' + case '-9': + return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' + case '-8': + return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' + case '-7': + return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' + case '-6': + return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' + case '-5': + return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' + case '-4.5': + return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' + case '-4': + return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' + case '-3.5': + return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' + case '-3': + return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' + case '-2': + return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' + case '-1': + return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' + case '0': + return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' + case '1': + return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' + case '2': + return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' + case '3': + return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' + case '3.5': + return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' + case '4': + return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' + case '4.5': + return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' + case '5': + return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' + case '5.5': + return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' + case '5.75': + return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' + case '6': + return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' + case '6.5': + return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' + case '7': + return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' + case '8': + return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' + case '8.75': + return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' + case '9': + return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' + case '9.5': + return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' + case '10': + return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' + case '10.5': + return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' + case '11': + return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' + case '11.5': + return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' + case '12': + return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' + case '12.75': + return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' + case '13': + return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' + case '14': + return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' + default: + return 'UTC'; + } + } +} diff --git a/phpBB/includes/db/migration/tools/base.php b/phpBB/includes/db/migration/tools/base.php deleted file mode 100644 index 61116d8b55..0000000000 --- a/phpBB/includes/db/migration/tools/base.php +++ /dev/null @@ -1,47 +0,0 @@ -db = $db; - $this->cache = $cache; - $this->template = $template; - $this->user = $user; - $this->auth = $auth; - $this->config = $config; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tools/config.php index 965ba1d136..2d58c8093c 100644 --- a/phpBB/includes/db/migration/tools/config.php +++ b/phpBB/includes/db/migration/tools/config.php @@ -7,20 +7,14 @@ * */ -class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base +class phpbb_db_migration_tools_config { - /** - * Config Exists - * - * This function is to check to see if a config variable exists or if it does not. - * - * @param string $config_name The name of the config setting you wish to check for. - * - * @return bool true/false if config exists - */ - public function exists($config_name) + /** @var phpbb_config */ + protected $config = null; + + public function __construct(phpbb_config $config) { - return (bool) $this->config->offsetExists($config_name); + $this->config = $config; } /** @@ -34,7 +28,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function add($config_name, $config_value = '', $is_dynamic = false) { - if ($this->config_exists($config_name)) + if (isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); } @@ -54,7 +48,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function update($config_name, $config_value = '') { - if (!$this->config_exists($config_name)) + if (!isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); } @@ -75,7 +69,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function update_if_equals($compare, $config_name, $config_value = '') { - if (!$this->config_exists($config_name)) + if (!isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); } @@ -94,7 +88,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function remove($config_name) { - if (!$this->config_exists($config_name)) + if (!isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); } diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tools/module.php index df1912a022..e17197d73e 100644 --- a/phpBB/includes/db/migration/tools/module.php +++ b/phpBB/includes/db/migration/tools/module.php @@ -7,8 +7,32 @@ * */ -class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base +class phpbb_db_migration_tools_module { + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, $user, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->cache = $cache; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + /** * Module Exists * @@ -117,11 +141,15 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base if (!isset($data['module_langname'])) { + /** + * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for + * upgrades from a 3.0.x version to 3.1 + */ // The "automatic" way $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; $basename = str_replace(array('/', '\\'), '', $basename); $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; // The manual and automatic ways both failed... if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) @@ -196,7 +224,7 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base if (!class_exists('acp_modules')) { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); $this->user->add_lang('acp/modules'); } $acp_modules = new acp_modules(); @@ -302,7 +330,7 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base // Automatic method $basename = str_replace(array('/', '\\'), '', $module['module_basename']); $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) { @@ -396,7 +424,7 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base if (!class_exists('acp_modules')) { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); $this->user->add_lang('acp/modules'); } $acp_modules = new acp_modules(); diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tools/permission.php index 3fbe7c649c..7694bae0cb 100644 --- a/phpBB/includes/db/migration/tools/permission.php +++ b/phpBB/includes/db/migration/tools/permission.php @@ -9,6 +9,30 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base { + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var dbal */ + protected $db = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->cache = $cache; + $this->auth = $auth; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + /** * Permission Exists * @@ -69,7 +93,7 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base if (!class_exists('auth_admin')) { - include($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); } $auth_admin = new auth_admin(); diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 9187e09869..c9590fccf6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,6 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { + protected $container; protected $db; protected $db_tools; protected $table_prefix; @@ -37,24 +38,26 @@ class phpbb_db_migrator /** * Constructor of the database migrator * - * @param dbal $db Connected database abstraction instance - * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools - * @param string $table_prefix The prefix for all table names - * @param string $migrations_table The name of the db table storing - * information on applied migrations - * @param string $phpbb_root_path - * @param string $php_ext + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + public function phpbb_db_migrator(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) { - $this->db = $db; - $this->db_tools = $db_tools; - $this->table_prefix = $table_prefix; - $this->migrations_table = $migrations_table; - $this->migrations = array(); - - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->container = $container; + $this->db = $this->container->get('dbal.conn'); + $this->db_tools = $this->container->get('dbal.tools'); + $this->table_prefix = $this->container->getParameters('core.table_prefix'); + $this->migrations_table = $this->container->getParameters('tables.migrations'); + $this->migrations = $migrations; + + $this->phpbb_root_path = $this->container->getParameters('core.root_path'); + $this->php_ext = $this->container->getParameters('core.php_ext'); + + /** @todo replace with collection_pass when merged */ + $this->tools = array( + 'config' => new phpbb_db_migration_tools_config, + 'module' => new phpbb_db_migration_tools_module, + 'permission' => new phpbb_db_migration_tools_permission, + ); $this->load_migration_state(); } diff --git a/phpBB/includes/update_helpers.php b/phpBB/includes/update_helpers.php deleted file mode 100644 index 69d678b2f8..0000000000 --- a/phpBB/includes/update_helpers.php +++ /dev/null @@ -1,112 +0,0 @@ - Date: Mon, 12 Nov 2012 16:41:02 -0500 Subject: [feature/migrations] Update phpbb_db_migration class for PHP 5.3.3 PHPBB3-9737 --- phpBB/includes/db/migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index 1acef2d429..fb030ded44 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -24,7 +24,7 @@ if (!defined('IN_PHPBB')) * * @package db */ -class phpbb_db_migration +abstract class phpbb_db_migration { protected $config; protected $db; @@ -88,7 +88,7 @@ class phpbb_db_migration */ protected function sql_query($sql) { - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { echo "
\n{$sql}\n
"; } -- cgit v1.2.1 From 61debcf14ca14afbb503b2535ef392a75002e8ae Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 12 Nov 2012 16:46:19 -0500 Subject: [feature/migrations] Update phpbb_db_migrator class for PHP 5.3.3 PHPBB3-9737 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index c9590fccf6..216faf9866 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -40,7 +40,7 @@ class phpbb_db_migrator * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migrator(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) + public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) { $this->container = $container; $this->db = $this->container->get('dbal.conn'); -- cgit v1.2.1 From 826607a40509d40ba5a85e5b0bc72a54f77d41d6 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 12 Nov 2012 16:54:10 -0500 Subject: [feature/migrations] Add method and property visibility, use __construct() PHPBB3-9737 --- phpBB/includes/db/migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index fb030ded44..10f7b71551 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -41,7 +41,7 @@ abstract class phpbb_db_migration * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migration(\Symfony\Component\DependencyInjection\ContainerInterface $container) + public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container) { $this->config = $this->container->get('config'); $this->db = $this->container->get('dbal.conn'); -- cgit v1.2.1 From 5c91e2569cb3a400acd20bf06cc0e609dd63a778 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:09:14 -0600 Subject: [feature/migrations] Migrations now somewhat works PHPBB3-9737 --- phpBB/includes/db/driver/mysqli.php | 1 + phpBB/includes/db/migration.php | 122 - phpBB/includes/db/migration/data/3_0_11_rc1.php | 2 +- phpBB/includes/db/migration/data/3_0_12_rc1.php | 101 +- phpBB/includes/db/migration/data/3_0_3_rc1.php | 6 +- phpBB/includes/db/migration/data/3_0_4.php | 2 +- phpBB/includes/db/migration/data/3_0_4_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_5_rc1.php | 8 +- phpBB/includes/db/migration/data/3_0_6_rc1.php | 60 +- phpBB/includes/db/migration/data/3_0_7_rc2.php | 2 +- phpBB/includes/db/migration/data/3_0_8_rc1.php | 10 +- phpBB/includes/db/migration/data/3_0_9_rc1.php | 2 +- phpBB/includes/db/migration/data/3_1_0_dev.php | 100 +- phpBB/includes/db/migration/data/extensions.php | 3 +- .../includes/db/migration/data/style_update_p1.php | 62 +- .../includes/db/migration/data/style_update_p2.php | 43 +- phpBB/includes/db/migration/data/timezone.php | 5 +- phpBB/includes/db/migration/exception.php | 40 + phpBB/includes/db/migration/migration.php | 129 + phpBB/includes/db/migration/tool/config.php | 108 + phpBB/includes/db/migration/tool/interface.php | 18 + phpBB/includes/db/migration/tool/module.php | 471 +++ phpBB/includes/db/migration/tool/permission.php | 562 ++++ phpBB/includes/db/migration/tools/config.php | 100 - phpBB/includes/db/migration/tools/module.php | 447 --- phpBB/includes/db/migration/tools/permission.php | 504 ---- phpBB/includes/db/migration/tools/umil.php | 3037 -------------------- phpBB/includes/db/migrator.php | 113 +- phpBB/includes/functions.php | 3 +- 29 files changed, 1705 insertions(+), 4360 deletions(-) delete mode 100644 phpBB/includes/db/migration.php create mode 100644 phpBB/includes/db/migration/exception.php create mode 100644 phpBB/includes/db/migration/migration.php create mode 100644 phpBB/includes/db/migration/tool/config.php create mode 100644 phpBB/includes/db/migration/tool/interface.php create mode 100644 phpBB/includes/db/migration/tool/module.php create mode 100644 phpBB/includes/db/migration/tool/permission.php delete mode 100644 phpBB/includes/db/migration/tools/config.php delete mode 100644 phpBB/includes/db/migration/tools/module.php delete mode 100644 phpBB/includes/db/migration/tools/permission.php delete mode 100644 phpBB/includes/db/migration/tools/umil.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php index 7448bf1670..94921a22b7 100644 --- a/phpBB/includes/db/driver/mysqli.php +++ b/phpBB/includes/db/driver/mysqli.php @@ -24,6 +24,7 @@ if (!defined('IN_PHPBB')) class phpbb_db_driver_mysqli extends phpbb_db_driver { var $multi_insert = true; + var $connect_error = ''; /** diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php deleted file mode 100644 index 10f7b71551..0000000000 --- a/phpBB/includes/db/migration.php +++ /dev/null @@ -1,122 +0,0 @@ -config = $this->container->get('config'); - $this->db = $this->container->get('dbal.conn'); - $this->db_tools = $this->container->get('dbal.tools'); - $this->table_prefix = $this->container->getParameters('core.table_prefix'); - - $this->phpbb_root_path = $this->container->getParameters('core.root_path'); - $this->php_ext = $this->container->getParameters('core.php_ext'); - - $this->errors = array(); - } - - /** - * Defines other migrationsto be applied first (abstract method) - * - * @return array An array of migration class names - */ - public function depends_on() - { - return array(); - } - - /** - * Updates the database schema by providing a set of change instructions - * - * @return array - */ - public function update_schema() - { - return array(); - } - - /** - * Updates data by returning a list of instructions to be executed - * - * @return array - */ - public function update_data() - { - } - - /** - * Wrapper for running queries to generate user feedback on updates - */ - protected function sql_query($sql) - { - if (defined('DEBUG')) - { - echo "
\n{$sql}\n
"; - } - - $this->db->sql_return_on_error(true); - - if ($sql === 'begin') - { - $result = $this->db->sql_transaction('begin'); - } - else if ($sql === 'commit') - { - $result = $this->db->sql_transaction('commit'); - } - else - { - $result = $this->db->sql_query($sql); - if ($this->db->sql_error_triggered) - { - $this->errors[] = array( - 'sql' => $this->db->sql_error_sql, - 'code' => $this->db->sql_error_returned, - ); - } - } - - $this->db->sql_return_on_error(false); - - return $result; - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 1509120f68..daf106accf 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -80,7 +80,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration { $delete_pms[] = (int) $row['msg_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!empty($delete_pms)) { diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index e5ff8c5814..0d8702f19e 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -9,24 +9,115 @@ /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/ -/* class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { - function depends_on() + public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } - function update_schema() + public function update_schema() { return array(); } - function update_data() + public function update_data() { return array( + array('custom', array(array(&$this, 'update_module_auth'))), + array('custom', array(array(&$this, 'update_bots'))), + array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))), + array('config.update', array('version', '3.0.12-rc1')), ); } + + public function disable_bots_from_receiving_pms() + { + // Disable receiving pms for bots + $sql = 'SELECT user_id + FROM ' . BOTS_TABLE; + $result = $this->db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); + $this->sql_query($sql); + } + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_u_sig\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'signature\''; + $this->sql_query($sql); + } + + public function update_bots() + { + // Update bots + if (!function_exists('user_delete')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $bots_updates = array( + // Bot Deletions + 'NG-Search [Bot]' => false, + 'Nutch/CVS [Bot]' => false, + 'OmniExplorer [Bot]' => false, + 'Seekport [Bot]' => false, + 'Synoo [Bot]' => false, + 'WiseNut [Bot]' => false, + + // Bot Updates + // Bot name to bot user agent map + 'Baidu [Spider]' => 'Baiduspider', + 'Exabot [Bot]' => 'Exabot', + 'Voyager [Bot]' => 'voyager/', + 'W3C [Validator]' => 'W3C_Validator', + ); + + foreach ($bots_updates as $bot_name => $bot_agent) + { + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_type = ' . USER_IGNORE . " + AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; + $result = $this->db->sql_query($sql); + $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if ($bot_user_id) + { + if ($bot_agent === false) + { + $sql = 'DELETE FROM ' . BOTS_TABLE . " + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + + user_delete('remove', $bot_user_id); + } + else + { + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + } + } + } + } } -*/ \ No newline at end of file diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index d5c110eb7d..2320c4ac4b 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -36,12 +36,12 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration array('config.add', array('queue_trigger_posts', '3')), array('config.add', array('pm_max_recipients', '0')), array('custom', array(array(&$this, 'set_group_default_max_recipients'))), - array('config.add', array('dbms_version', '')), - array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('config.add', array('dbms_version', $this->db->sql_server_info(true))), + array('permission.add', array('u_masspm_group', true, 'u_masspm')), array('custom', array(array(&$this, 'correct_acp_email_permissions'))), array('config.update', array('version', '3.0.3-rc1')), - )); + ); } function correct_acp_email_permissions() diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index 4965ac38d0..1af4508331 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration function rename_log_delete_topic() { - if ($db->sql_layer == 'oracle') + if ($this->db->sql_layer == 'oracle') { // log_operation is CLOB - but we can change this later $sql = 'UPDATE ' . $this->table_prefix . "log diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index 2964dcebc9..e9bb0e01f5 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -69,7 +69,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration // Update the Custom Profile Fields based on previous settings to the new format $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide FROM ' . PROFILE_FIELDS_TABLE; - $result = $this->sql_query($sql); + $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -101,5 +101,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); } + + $this->db->sql_freeresult($result); } } diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php index 9205f0d5f8..cbf28c0be6 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php @@ -32,7 +32,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration return array( array('config.add', array('captcha_gd_wave', 0)), array('config.add', array('captcha_gd_3d_noise', 1)), - array('config.add', array('captcha_gd_refresh', 1)), + array('config.add', array('captcha_gd_fonts', 1)), array('config.add', array('confirm_refresh', 1)), array('config.add', array('max_num_search_keywords', 10)), array('config.remove', array('search_indexing_state')), @@ -47,7 +47,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $sql = 'SELECT user_id, user_password FROM ' . $this->table_prefix . 'users WHERE user_pass_convert = 1'; - $result = $this->sql_query($sql); + $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -60,7 +60,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } function update_ichiro_bot() @@ -99,7 +99,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration WHERE auth_option = '" . $db->sql_escape($option) . "' ORDER BY auth_option_id DESC"; // sql_query_limit not possible here, due to bug in postgresql layer - $result = $this->sql_query($sql); + $result = $this->db->sql_query($sql); // Skip first row, this is our original auth option we want to preserve $row = $this->db->sql_fetchrow($result); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index a868d70684..35adcf52be 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -35,7 +35,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration $this->table_prefix . 'reports' => array( 'pm_id' => array('UINT', 0), ), - $this->table_prefix . 'fields' => array( + $this->table_prefix . 'profile_fields' => array( 'field_show_on_vt' => array('BOOL', 0), ), $this->table_prefix . 'forums' => array( @@ -89,19 +89,19 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration array('config.add', array('allow_avatar', 0)), array('if', array( ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - array('config.add', array('allow_avatar', 1)), + array('config.update', array('allow_avatar', 1)), )), array('config.add', array('allow_avatar_remote_upload', 0)), array('if', array( ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - array('config.add', array('allow_avatar_remote_upload', 1)), + array('config.update', array('allow_avatar_remote_upload', 1)), )), array('module.add', array( 'acp', 'ACP_BOARD_CONFIGURATION', array( - 'module_basename' => 'board', + 'module_basename' => 'acp_board', 'modes' => array('feed'), ), )), @@ -109,7 +109,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'acp', 'ACP_CAT_USERS', array( - 'module_basename' => 'users', + 'module_basename' => 'acp_users', 'modes' => array('warnings'), ), )), @@ -117,7 +117,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'acp', 'ACP_SERVER_CONFIGURATION', array( - 'module_basename' => 'send_statistics', + 'module_basename' => 'acp_send_statistics', 'modes' => array('send_statistics'), ), )), @@ -125,7 +125,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'acp', 'ACP_FORUM_BASED_PERMISSIONS', array( - 'module_basename' => 'permissions', + 'module_basename' => 'acp_permissions', 'modes' => array('setting_forum_copy'), ), )), @@ -133,24 +133,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'mcp', 'MCP_REPORTS', array( - 'module_basename' => 'pm_reports', - 'modes' => array('pm_reports'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'pm_reports', - 'modes' => array('pm_reports_closed'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'pm_reports', - 'modes' => array('pm_report_details'), + 'module_basename' => 'mcp_pm_reports', + 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), ), )), array('custom', array(array(&$this, 'add_newly_registered_group'))), @@ -209,17 +193,14 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration $this->sql_query($sql); $u_role = $this->db->sql_nextid(); - if (!$errored) - { - // Now add the correct data to the roles... - // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - $this->sql_query($sql); + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); - // Add user role to group - $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - $this->sql_query($sql); - } + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); } // Insert new forum role @@ -246,11 +227,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration $this->sql_query($sql); $f_role = $this->db->sql_nextid(); - if (!$errored) - { - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - $this->sql_query($sql); - } + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); } // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) @@ -294,7 +272,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration } // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); $auth_admin = new auth_admin(); $auth_admin->acl_clear_prefetch(); } diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index e043f35705..e2c6acce1e 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration $this->sql_query($sql); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if ($i < $limit) { diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index 3f51806fd9..b58b0966a5 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration 'acp', 'ACP_MESSAGES', array( - 'module_basename' => 'board', + 'module_basename' => 'acp_board', 'modes' => array('post'), ), )), @@ -60,9 +60,9 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration // On an already updated board, they can also already be in language/.../acp/attachments.php // in the board root. $lang_files = array( - "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", ); foreach ($lang_files as $lang_file) @@ -140,7 +140,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration if (!function_exists('user_add')) { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } $user_row = array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index 256426849c..ea49cdbba9 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -44,7 +44,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ), ), 'change_columns' => array( - $this->table_prefix . 'bbcode' => array( + $this->table_prefix . 'bbcodes' => array( 'bbcode_id' => array('USINT', 0), ), ), diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 987ab94646..6eb5a6ddee 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -7,7 +7,7 @@ * */ -class phpbb_db_migration_data_extensions extends phpbb_db_migration +class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { public function depends_on() { @@ -78,6 +78,8 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration array('config.add', array('site_home_url', '')), array('config.add', array('site_home_text', '')), + array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), + array('module.add', array( 'acp', 'ACP_GROUPS', @@ -103,7 +105,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration ), )), array('module.add', array( - 'acp', + 'ucp', 'UCP_PROFILE', array( 'module_basename' => 'ucp_profile', @@ -113,20 +115,104 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration array('module.remove', array( 'acp', - 'ACP_CAT_STYLES', - array( - 'module_basename' => 'styles', - 'modes' => array('imageset', 'theme', 'template'), - ), + false, + 'ACP_TEMPLATES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_THEMES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_IMAGESETS', )), array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'rename_styles_module'))), array('custom', array(array($this, 'add_group_teampage'))), array('custom', array(array($this, 'update_group_legend'))), array('custom', array(array($this, 'localise_global_announcements'))), + array('custom', array(array($this, 'update_ucp_pm_basename'))), + array('custom', array(array($this, 'update_ucp_profile_auth'))), + array('custom', array(array($this, 'move_customise_modules'))), + + array('config.update', array('version', '3.1.0-dev')), ); } + public function move_customise_modules() + { + // Move language management to new location in the Customise tab + // First get language module id + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_basename = 'acp_language'"; + $result = $this->db->sql_query($sql); + $language_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + // Next get language management module id of the one just created + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = 'ACP_LANGUAGE'"; + $result = $this->db->sql_query($sql); + $language_management_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + } + // acp_modules calls adm_back_link, which is undefined at this point + if (!function_exists('adm_back_link')) + { + include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); + } + $module_manager = new acp_modules(); + $module_manager->module_class = 'acp'; + $module_manager->move_module($language_module_id, $language_management_module_id); + } + + public function update_ucp_pm_basename() + { + $sql = 'SELECT module_id, module_basename + FROM ' . MODULES_TABLE . " + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM'"; + $result = $this->db->sql_query_limit($sql, 1); + + if ($row = $this->db->sql_fetchrow($result)) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; + + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_ucp_profile_auth() + { + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'profile_info'"; + $this->sql_query($sql); + } + + public function rename_styles_module() + { + // Rename styles module to Customise + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_langname = 'ACP_CAT_CUSTOMISE' + WHERE module_langname = 'ACP_CAT_STYLES'"; + $this->sql_query($sql); + } + public function rename_module_basenames() { // rename all module basenames to full classname diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index 85d5511ef0..d28e0ebabb 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -39,10 +39,11 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration 'acp', 'ACP_GENERAL_TASKS', array( - 'module_basename' => 'extensions', + 'module_basename' => 'acp_extensions', 'modes' => array('main'), ), )), + array('permission.add', array('a_extensions', true, 'a_styles')), ); } } diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index d570caae04..1c46e4147b 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -31,7 +31,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration // Get list of valid 3.1 styles $available_styles = array('prosilver'); - $iterator = new DirectoryIterator($phpbb_root_path . 'styles'); + $iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); $skip_dirs = array('.', '..', 'prosilver'); foreach ($iterator as $fileinfo) { @@ -91,9 +91,67 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration 'style_parent_id' => 0, 'style_parent_tree' => '', ); - $this->sql_query('UPDATE ' . STYLES_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE style_id = ' . $style_row['style_id'], $errored, $error_ary); + $this->sql_query('UPDATE ' . STYLES_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE style_id = ' . $style_row['style_id']); $valid_styles[] = (int) $style_row['style_id']; } } + + // Remove old entries from styles table + if (!sizeof($valid_styles)) + { + // No valid styles: remove everything and add prosilver + $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + + $sql_ary = array( + 'style_name' => 'prosilver', + 'style_copyright' => '© phpBB Group', + 'style_active' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', + + // Will be removed in the next step + 'imageset_id' => 0, + 'template_id' => 0, + 'theme_id' => 0, + ); + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->sql_query($sql); + + $sql = 'SELECT style_id + FROM ' . $table . " + WHERE style_name = 'prosilver'"; + $result = $this->sql_query($sql); + $default_style = $this->db->sql_fetchfield($result); + $this->db->sql_freeresult($result); + + set_config('default_style', $default_style); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $this->sql_query($sql); + } + else + { + // There are valid styles in styles table. Remove styles that are outdated + $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' + WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); + + // Change default style + if (!in_array($this->config['default_style'], $valid_styles)) + { + $this->sql_query('UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $valid_styles[0] . "' + WHERE config_name = 'default_style'"); + } + + // Reset styles for users + $this->sql_query('UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); + } } } diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index 2c0991de59..db4b7f1753 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -37,47 +37,6 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration public function update_data() { - return array( - array('custom', array(array($this, 'styles_update'))), - ); - } - - public function styles_update() - { - // Remove old entries from styles table - if (!sizeof($valid_styles)) - { - // No valid styles: remove everything and add prosilver - $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); - - $sql = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; - $this->sql_query($sql); - - $sql = 'SELECT style_id - FROM ' . $table . " - WHERE style_name = 'prosilver'"; - $result = $this->sql_query($sql); - $default_style = $this->db->sql_fetchfield($result); - $this->db->sql_freeresult($result); - - set_config('default_style', $default_style); - - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; - $this->sql_query($sql); - } - else - { - // There are valid styles in styles table. Remove styles that are outdated - $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true), $errored, $error_ary); - - // Change default style - if (!in_array($config['default_style'], $valid_styles)) - { - set_config('default_style', $valid_styles[0]); - } - - // Reset styles for users - $this->sql_query('UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true), $errored, $error_ary); - } + return array(); } } diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 89fafbad28..7734ed4b76 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -51,7 +51,10 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration $this->db->sql_freeresult($result); // Update board default timezone - set_config('board_timezone', $this->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst'])); + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' + WHERE config_name = 'board_timezone'"; + $this->sql_query($sql); // After we have calculated the timezones we can delete user_dst column from user table. $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php new file mode 100644 index 0000000000..19fb39ab23 --- /dev/null +++ b/phpBB/includes/db/migration/exception.php @@ -0,0 +1,40 @@ +parameters = $parameters; + } + + public function __toString() + { + return $this->message . ': ' . var_export($this->parameters, true); + } +} diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php new file mode 100644 index 0000000000..c2c6da855b --- /dev/null +++ b/phpBB/includes/db/migration/migration.php @@ -0,0 +1,129 @@ +config = $config; + $this->db = $db; + $this->db_tools = $db_tools; + $this->table_prefix = $table_prefix; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->errors = array(); + } + + /** + * Defines other migrationsto be applied first (abstract method) + * + * @return array An array of migration class names + */ + public function depends_on() + { + return array(); + } + + /** + * Updates the database schema by providing a set of change instructions + * + * @return array + */ + public function update_schema() + { + return array(); + } + + /** + * Updates data by returning a list of instructions to be executed + * + * @return array + */ + public function update_data() + { + } + + /** + * Wrapper for running queries to generate user feedback on updates + */ + protected function sql_query($sql) + { + $this->queries[] = $sql; + + $this->db->sql_return_on_error(true); + + if ($sql === 'begin') + { + $result = $this->db->sql_transaction('begin'); + } + else if ($sql === 'commit') + { + $result = $this->db->sql_transaction('commit'); + } + else + { + $result = $this->db->sql_query($sql); + if ($this->db->sql_error_triggered) + { + $this->errors[] = array( + 'sql' => $this->db->sql_error_sql, + 'code' => $this->db->sql_error_returned, + ); + } + } + + $this->db->sql_return_on_error(false); + + return $result; + } + + /** + * Get the list of queries run + * + * @return array + */ + public function get_queries() + { + return $this->queries; + } +} diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php new file mode 100644 index 0000000000..35fa3ce566 --- /dev/null +++ b/phpBB/includes/db/migration/tool/config.php @@ -0,0 +1,108 @@ +config = $config; + } + + /** + * {@inheritdoc} + */ + public function get_name() + { + return 'config'; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + */ + public function add($config_name, $config_value = '', $is_dynamic = false) + { + if (isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); + } + + $this->config->set($config_name, $config_value, !$is_dynamic); + + return false; + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update($config_name, $config_value = '') + { + if (!isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set($config_name, $config_value); + + return false; + } + + /** + * Config Update If Equals + * + * This function allows you to update a config setting if the first argument equal to the current config value + * + * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update_if_equals($compare, $config_name, $config_value = '') + { + if (!isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set_atomic($config_name, $compare, $config_value); + + return false; + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + */ + public function remove($config_name) + { + if (!isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->delete($config_name); + + return false; + } +} diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php new file mode 100644 index 0000000000..1815f5e8a2 --- /dev/null +++ b/phpBB/includes/db/migration/tool/interface.php @@ -0,0 +1,18 @@ +db = $db; + $this->cache = $cache; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->modules_table = $modules_table; + } + + /** + * {@inheritdoc} + */ + public function get_name() + { + return 'module'; + } + + /** + * Module Exists + * + * Check if a module exists + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + * + * @return bool true/false if module exists + */ + public function exists($class, $parent, $module) + { + // the main root directory should return true + if (!$module) + { + return true; + } + + $class = $this->db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function add($class, $parent = 0, $data = array(), $include_path = false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + /** + * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for + * upgrades from a 3.0.x version to 3.1 + */ + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/$basename.{$this->php_ext}"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $info_file); + } + + $classname = "{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->exists($class, false, $parent)) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + if ($this->exists($class, $parent, $data['module_langname'])) + { + throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + throw new phpbb_db_migration_exception('MODULE_ERROR', $result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id + FROM ' . $this->modules_table . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . $this->modules_table . " + SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->modules_table . " + SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id + FROM ' . $this->modules_table . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . $this->modules_table . " + SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->modules_table . ' + SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $this->cache->destroy("_modules_$class"); + + return false; + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function remove($class, $parent = 0, $module = '', $include_path = false) + { + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/$basename.{$this->php_ext}"; + + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); + } + + $classname = "{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $this->remove($class, $parent, $info['title']) . '
'; + } + } + return false; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->exists($class, $parent, $module)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname + FROM ' . $this->modules_table . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); + } + } + + $this->cache->destroy("_modules_$class"); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php new file mode 100644 index 0000000000..ebe404bc62 --- /dev/null +++ b/phpBB/includes/db/migration/tool/permission.php @@ -0,0 +1,562 @@ +db = $db; + $this->cache = $cache; + $this->auth = $auth; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * {@inheritdoc} + */ + public function get_name() + { + return 'permission'; + } + + /** + * Permission Exists + * + * Check if a permission (auth) setting exists + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return bool true if it exists, false if not + */ + public function exists($auth_option, $global = true) + { + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function add($auth_option, $global = true, $copy_from = false) + { + if ($this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + // The permission has been added, now we can copy it if needed + if ($copy_from && isset($auth_admin->acl_options['id'][$copy_from])) + { + $old_id = $auth_admin->acl_options['id'][$copy_from]; + $new_id = $auth_admin->acl_options['id'][$auth_option]; + + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); + + foreach ($tables as $table) + { + $sql = 'SELECT * + FROM ' . $table . ' + WHERE auth_option_id = ' . $old_id; + $result = $this->db->sql_query($sql); + + $sql_ary = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $row['auth_option_id'] = $new_id; + $sql_ary[] = $row; + } + $this->db->sql_freeresult($result); + + if (sizeof($sql_ary)) + { + $this->db->sql_multi_insert($table, $sql_ary); + } + } + + $auth_admin->acl_clear_prefetch(); + } + + return false; + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function remove($auth_option, $global = true) + { + if (!$this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $this->cache->destroy('_acl_options'); + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + public function role_add($role_name, $role_type = '', $role_description = '') + { + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = '" . $this->db->sql_escape($role_type) . "'"; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return false; + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + public function role_update($old_role_name, $new_role_name = '') + { + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . " + SET role_name = '" . $this->db->sql_escape($new_role_name) . "' + WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; + $this->db->sql_query($sql); + + return false; + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + public function role_remove($role_name) + { + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'SELECT auth_option_id, auth_setting + FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name + FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->set($role_name, $auth_option, 'role', $has_permission); + } + + $sql = 'SELECT auth_option_id, auth_setting + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + public function permission_unset($name, $auth_option = array(), $type = 'role') + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name + FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } +} diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tools/config.php deleted file mode 100644 index 2d58c8093c..0000000000 --- a/phpBB/includes/db/migration/tools/config.php +++ /dev/null @@ -1,100 +0,0 @@ -config = $config; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - */ - public function add($config_name, $config_value = '', $is_dynamic = false) - { - if (isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); - } - - $this->config->set($config_name, $config_value, $is_dynamic); - - return false; - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - */ - public function update($config_name, $config_value = '') - { - if (!isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); - } - - $this->config->set($config_name, $config_value); - - return false; - } - - /** - * Config Update If Equals - * - * This function allows you to update a config setting if the first argument equal to the current config value - * - * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - */ - public function update_if_equals($compare, $config_name, $config_value = '') - { - if (!isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); - } - - $this->config->set_atomic($config_name, $compare, $config_value); - - return false; - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - */ - public function remove($config_name) - { - if (!isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); - } - - $this->config->delete($config_name); - - return false; - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tools/module.php deleted file mode 100644 index e17197d73e..0000000000 --- a/phpBB/includes/db/migration/tools/module.php +++ /dev/null @@ -1,447 +0,0 @@ -db = $db; - $this->cache = $cache; - $this->user = $user; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * Module Exists - * - * Check if a module exists - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - * - * @return bool true/false if module exists - */ - public function exists($class, $parent, $module) - { - // the main root directory should return true - if (!$module) - { - return true; - } - - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return false; - } - - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_class = '$class' - $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Module Add - * - * Add a new module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - public function add($class, $parent = 0, $data = array(), $include_path = false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - // allow sending the name as a string in $data to create a category - if (!is_array($data)) - { - $data = array('module_langname' => $data); - } - - if (!isset($data['module_langname'])) - { - /** - * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for - * upgrades from a 3.0.x version to 3.1 - */ - // The "automatic" way - $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; - $basename = str_replace(array('/', '\\'), '', $basename); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; - - // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - throw new phpbb_db_migration_exception('MODULE_ADD', $class, $info_file); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module = $info->module(); - unset($info); - - $result = ''; - foreach ($module['modes'] as $mode => $module_info) - { - if (!isset($data['modes']) || in_array($mode, $data['modes'])) - { - $new_module = array( - 'module_basename' => $basename, - 'module_langname' => $module_info['title'], - 'module_mode' => $mode, - 'module_auth' => $module_info['auth'], - 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, - 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, - 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, - ); - - // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); - } - } - - return $result; - } - - // The "manual" way - add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); - } - - $parent = $data['parent_id'] = $row['module_id']; - } - else if (!$this->exists($class, false, $parent)) - { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); - } - - if ($this->exists($class, $parent, $data['module_langname'])) - { - throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); - } - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - $this->user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - - $module_data = array( - 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, - 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, - 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', - 'module_class' => $class, - 'parent_id' => (int) $parent, - 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', - 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', - 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', - ); - $result = $acp_modules->update_module_data($module_data, true); - - // update_module_data can either return a string or an empty array... - if (is_string($result)) - { - // Error - throw new phpbb_db_migration_exception('MODULE_ERROR', $result); - } - else - { - // Success - - // Move the module if requested above/below an existing one - if (isset($data['before']) && $data['before']) - { - $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; - $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_left - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - else if (isset($data['after']) && $data['after']) - { - $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; - $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_right - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - } - - // Clear the Modules Cache - $this->cache->destroy("_modules_$class"); - - return false; - } - - /** - * Module Remove - * - * Remove a module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - public function remove($class, $parent = 0, $module = '', $include_path = false) - { - // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto - if (is_array($module)) - { - if (isset($module['module_langname'])) - { - // Manual Method - return $this->remove($class, $parent, $module['module_langname'], $include_path); - } - - // Failed. - if (!isset($module['module_basename'])) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); - } - - // Automatic method - $basename = str_replace(array('/', '\\'), '', $module['module_basename']); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; - - if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module_info = $info->module(); - unset($info); - - foreach ($module_info['modes'] as $mode => $info) - { - if (!isset($module['modes']) || in_array($mode, $module['modes'])) - { - $this->remove($class, $parent, $info['title']) . '
'; - } - } - return false; - } - else - { - $class = $this->db->sql_escape($class); - - if (!$this->exists($class, $parent, $module)) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); - } - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $module_ids = array(); - if (!is_numeric($module)) - { - $module = $this->db->sql_escape($module); - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $module_ids[] = (int) $row['module_id']; - } - $this->db->sql_freeresult($result); - - $module_name = $module; - } - else - { - $module = (int) $module; - $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " - WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $module_name = $row['module_langname']; - $module_ids[] = $module; - } - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - $this->user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - $acp_modules->module_class = $class; - - foreach ($module_ids as $module_id) - { - $result = $acp_modules->delete_module($module_id); - if (!empty($result)) - { - throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); - } - } - - $cache->destroy("_modules_$class"); - - return false; - } - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tools/permission.php deleted file mode 100644 index 7694bae0cb..0000000000 --- a/phpBB/includes/db/migration/tools/permission.php +++ /dev/null @@ -1,504 +0,0 @@ -db = $db; - $this->cache = $cache; - $this->auth = $auth; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * Permission Exists - * - * Check if a permission (auth) setting exists - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return bool true if it exists, false if not - */ - public function exists($auth_option, $global = true) - { - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" - . $type_sql; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Permission Add - * - * Add a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - public function add($auth_option, $global = true) - { - if ($this->exists($auth_option, $global)) - { - throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); - } - - // We've added permissions, so set to true to notify the user. - $this->permissions_added = true; - - if (!class_exists('auth_admin')) - { - include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); - } - $auth_admin = new auth_admin(); - - // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. - if ($this->exists($auth_option, !$global)) - { - $sql_ary = array( - 'is_global' => 1, - 'is_local' => 1, - ); - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; - $this->db->sql_query($sql); - } - else - { - if ($global) - { - $auth_admin->acl_add_option(array('global' => array($auth_option))); - } - else - { - $auth_admin->acl_add_option(array('local' => array($auth_option))); - } - } - - return false; - } - - /** - * Permission Remove - * - * Remove a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - public function remove($auth_option, $global = true) - { - if (!$this->exists($auth_option, $global)) - { - throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); - } - - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . - $type_sql; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $id = $row['auth_option_id']; - - // If it is a local and global permission, do not remove the row! :P - if ($row['is_global'] && $row['is_local']) - { - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' - WHERE auth_option_id = ' . $id; - $this->db->sql_query($sql); - } - else - { - // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); - } - - // Purge the auth cache - $this->cache->destroy('_acl_options'); - $this->auth->acl_clear_prefetch(); - - return false; - } - - /** - * Add a new permission role - * - * @param string $role_name The new role name - * @param sting $role_type The type (u_, m_, a_) - */ - public function role_add($role_name, $role_type = '', $role_description = '') - { - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if ($role_id) - { - throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); - } - - $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' - WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; - $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); - $role_order = (!$role_order) ? 1 : $role_order + 1; - - $sql_ary = array( - 'role_name' => $role_name, - 'role_description' => $role_description, - 'role_type' => $role_type, - 'role_order' => $role_order, - ); - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->db->sql_query($sql); - - return false; - } - - /** - * Update the name on a permission role - * - * @param string $old_role_name The old role name - * @param string $new_role_name The new role name - */ - public function role_update($old_role_name, $new_role_name = '') - { - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); - } - - $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' - SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - - return false; - } - - /** - * Remove a permission role - * - * @param string $role_name The role name to remove - */ - public function role_remove($role_name) - { - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $this->auth->acl_clear_prefetch(); - - return false; - } - - /** - * Permission Set - * - * Allows you to set permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission - */ - public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) - { - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $new_auth = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $new_auth[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($new_auth)) - { - return false; - } - - $current_auth = array(); - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); - } - - // If the group has a role set for them we will add the requested permissions to that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0 - AND forum_id = 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->set($role_name, $auth_option, 'role', $has_permission); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - } - - $sql_ary = array(); - switch ($type) - { - case 'role' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'role_id' => $role_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); - break; - - case 'group' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'group_id' => $group_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); - break; - } - - $this->auth->acl_clear_prefetch(); - - return false; - } - - /** - * Permission Unset - * - * Allows you to unset (remove) permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - */ - public function permission_unset($name, $auth_option = array(), $type = 'role') - { - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $to_remove = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $to_remove[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($to_remove)) - { - return false; - } - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' - WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); - } - - // If the group has a role set for them we will remove the requested permissions from that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_unset($role_name, $auth_option, 'role'); - } - - $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - } - - $this->auth->acl_clear_prefetch(); - - return false; - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/umil.php b/phpBB/includes/db/migration/tools/umil.php deleted file mode 100644 index ce7b8ff3be..0000000000 --- a/phpBB/includes/db/migration/tools/umil.php +++ /dev/null @@ -1,3037 +0,0 @@ -config_add(array( -* array('config_name', 'config_value'), -* array('config_name1', 'config_value1'), -* array('config_name2', 'config_value2', true), -* array('config_name3', 'config_value3', true), -* ); -*/ - -/** -* UMIL - Unified MOD Installation Library class -* -* Cache Functions -* cache_purge($type = '', $style_id = 0) -* -* Config Functions: -* config_exists($config_name, $return_result = false) -* config_add($config_name, $config_value = '', $is_dynamic = false) -* config_update($config_name, $config_value, $is_dynamic = false) -* config_remove($config_name) -* -* Module Functions -* module_exists($class, $parent, $module) -* module_add($class, $parent = 0, $data = array()) -* module_remove($class, $parent = 0, $module = '') -* -* Permissions/Auth Functions -* permission_exists($auth_option, $global = true) -* permission_add($auth_option, $global = true) -* permission_remove($auth_option, $global = true) -* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) -* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) -* -* Table Functions -* table_exists($table_name) -* table_add($table_name, $table_data = array()) -* table_remove($table_name) -* -* Table Column Functions -* table_column_exists($table_name, $column_name) -* table_column_add($table_name, $column_name = '', $column_data = array()) -* table_column_update($table_name, $column_name = '', $column_data = array()) -* table_column_remove($table_name, $column_name = '') -* -* Table Key/Index Functions -* table_index_exists($table_name, $index_name) -* table_index_add($table_name, $index_name = '', $column = array()) -* table_index_remove($table_name, $index_name = '') -* -* Table Row Functions (note that these actions are not reversed automatically during uninstallation) -* table_row_insert($table_name, $data = array()) -* table_row_remove($table_name, $data = array()) -* table_row_update($table_name, $data = array(), $new_data = array()) -* -* Version Check Function -* version_check($url, $path, $file) -*/ -class umil -{ - /** - * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) - * - * @var string - */ - var $command = ''; - - /** - * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. - * - * @var string - */ - var $result = ''; - - /** - * Auto run $this->display_results after running a command - */ - var $auto_display_results = false; - - /** - * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff - */ - var $stand_alone = false; - - /** - * Were any new permissions added (used in umil_frontend)? - */ - var $permissions_added = false; - - /** - * Database Object - */ - var $db = false; - - /** - * Database Tools Object - */ - var $db_tools = false; - - /** - * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... - */ - var $table_prefix = false; - - /** - * Constructor - */ - function umil($stand_alone = false, $db = false) - { - // Setup $this->db - if ($db !== false) - { - if (!is_object($db) || !method_exists($db, 'sql_query')) - { - trigger_error('Invalid $db Object'); - } - - $this->db = $db; - } - else - { - global $db; - $this->db = $db; - } - - // Setup $this->db_tools - if (!class_exists('phpbb_db_tools')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } - $this->db_tools = new phpbb_db_tools($this->db); - - $this->stand_alone = $stand_alone; - - if (!$stand_alone) - { - global $config, $user, $phpbb_root_path, $phpEx; - - /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. - if (method_exists('user', 'set_custom_lang_path')) - { - $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); - $user->add_lang('umil'); - $user->set_custom_lang_path($phpbb_root_path . 'language/'); - } - else - {*/ - // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. - if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) - { - $path = $user->data['user_lang']; - } - else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) - { - $path = basename($config['default_lang']); - } - else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) - { - $path = 'en'; - } - else - { - trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); - } - - $user->add_lang('./../../umil/language/' . $path . '/umil'); - //} - - $user->add_lang(array('acp/common', 'acp/permissions')); - - // Check to see if a newer version is available. - $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); - if (is_array($info) && isset($info[0]) && isset($info[1])) - { - if (version_compare(UMIL_VERSION, $info[0], '<')) - { - global $template; - - // Make sure user->setup() has been called - if (empty($user->lang)) - { - $user->setup(); - } - - page_header('', false); - - $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; - $template->assign_vars(array( - 'S_BOARD_DISABLED' => true, - 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), - )); - } - } - } - } - - /** - * umil_start - * - * A function which runs (almost) every time a function here is ran - */ - function umil_start() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - $this->command = call_user_func_array(array($this, 'get_output_text'), $args); - - $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; - $this->db->sql_return_on_error(true); - - //$this->db->sql_transaction('begin'); - } - - /** - * umil_end - * - * A function which runs (almost) every time a function here is ran - */ - function umil_end() - { - global $user; - - // Set up the result. This will get the arguments sent to the function. - $args = func_get_args(); - $result = call_user_func_array(array($this, 'get_output_text'), $args); - $this->result = ($result) ? $result : $this->result; - - if ($this->db->sql_error_triggered) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; - } - else - { - $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; - } - - //$this->db->sql_transaction('rollback'); - } - else - { - //$this->db->sql_transaction('commit'); - } - - $this->db->sql_return_on_error(false); - - // Auto output if requested. - if ($this->auto_display_results && method_exists($this, 'display_results')) - { - $this->display_results(); - } - - return '' . $this->command . '
' . $this->result; - } - - /** - * Get text for output - * - * Takes the given arguments and prepares them for the UI - * - * First argument sent is used as the language key - * Further arguments (if send) are used on the language key through vsprintf() - * - * @return string Returns the prepared string for output - */ - function get_output_text() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - if (sizeof($args)) - { - $lang_key = array_shift($args); - - if (sizeof($args)) - { - $lang_args = array(); - foreach ($args as $arg) - { - $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; - } - - return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); - } - else - { - return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); - } - } - - return ''; - } - - /** - * Run Actions - * - * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. - * - * @param string $action The action. install|update|uninstall - * @param array $versions The array of versions and the actions for each - * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version - * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. - */ - function run_actions($action, $versions, $version_config_name, $version_select = '') - { - // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers - uksort($versions, 'version_compare'); - - // Find the current version to install - $current_version = '0.0.0'; - foreach ($versions as $version => $actions) - { - $current_version = $version; - } - - $db_version = ''; - if ($this->config_exists($version_config_name)) - { - global $config; - $db_version = $config[$version_config_name]; - } - - // Set the action to install from update if nothing is currently installed - if ($action == 'update' && !$db_version) - { - $action = 'install'; - } - - if ($action == 'install' || $action == 'update') - { - $version_installed = $db_version; - foreach ($versions as $version => $version_actions) - { - // If we are updating - if ($db_version && version_compare($version, $db_version, '<=')) - { - continue; - } - - if ($version_select && version_compare($version, $version_select, '>')) - { - break; - } - - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), $params); - } - } - } - - $version_installed = $version; - } - - // update the version number or add it - if ($this->config_exists($version_config_name)) - { - $this->config_update($version_config_name, $version_installed); - } - else - { - $this->config_add($version_config_name, $version_installed); - } - } - else if ($action == 'uninstall' && $db_version) - { - // reverse version list - $versions = array_reverse($versions); - - foreach ($versions as $version => $version_actions) - { - // Uninstalling and this listed version is newer than installed - if (version_compare($version, $db_version, '>')) - { - continue; - } - - // Version selection stuff - if ($version_select && version_compare($version, $version_select, '<=')) - { - // update the version number - $this->config_update($version_config_name, $version); - break; - } - - $cache_purge = false; - $version_actions = array_reverse($version_actions); - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). - if ($method == 'cache_purge') - { - $cache_purge = $params; - continue; - } - - // A few things are not possible for uninstallations update actions and table_row actions - if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) - { - continue; - } - - // reverse function call - $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); - $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); - - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); - } - } - } - - if ($cache_purge !== false) - { - $this->cache_purge($cache_purge); - } - } - - if (!$version_select) - { - // Unset the version number - $this->config_remove($version_config_name); - } - } - } - - /** - * Call custom function helper - */ - function _call_custom_function($functions, $action, $version) - { - if (!is_array($functions)) - { - $functions = array($functions); - } - - $return = ''; - - foreach ($functions as $function) - { - if (function_exists($function)) - { - // Must reset before calling the function - $this->umil_start(); - - $returned = call_user_func($function, $action, $version); - if (is_string($returned)) - { - $this->command = $this->get_output_text($returned); - } - else if (is_array($returned) && isset($returned['command'])) - { - if (is_array($returned['command'])) - { - $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); - } - else - { - $this->command = $this->get_output_text($returned['command']); - } - - if (isset($returned['result'])) - { - $this->result = $this->get_output_text($returned['result']); - } - } - else - { - $this->command = $this->get_output_text('UNKNOWN'); - } - - $return .= $this->umil_end() . '
'; - } - } - - return $return; - } - - /** - * Multicall Helper - * - * @param mixed $function Function name to call - * @param mixed $params The parameters array - * - * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) - */ - function multicall($function, $params) - { - if (is_array($params) && !empty($params)) - { - foreach ($params as $param) - { - if (!is_array($param)) - { - call_user_func(array($this, $function), $param); - } - else - { - call_user_func_array(array($this, $function), $param); - } - } - return true; - } - - return false; - } - - /** - * Cache Purge - * - * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. - * - * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. - * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) - */ - function cache_purge($type = '', $style_id = 0) - { - global $auth, $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $type)) - { - return; - } - - $style_id = (int) $style_id; - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'auth' : - $this->umil_start('AUTH_CACHE_PURGE'); - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - break; - - case 'imageset' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT imageset_id - FROM ' . STYLES_IMAGESET_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('imageset', $row['imageset_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_IMAGESET_TABLE . " - WHERE imageset_id = $style_id"; - $result = $this->db->sql_query($sql); - $imageset_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$imageset_row) - { - $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); - - // The following is from includes/acp/acp_styles.php (edited) - $sql_ary = array(); - - $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); - - $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' - WHERE imageset_id = ' . $style_id; - $result = $this->db->sql_query($sql); - - foreach ($cfg_data_imageset as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => '', - ); - } - } - - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) - { - $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => (string) $row['lang_dir'], - ); - } - } - } - } - $this->db->sql_freeresult($result); - - $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); - - $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); - - return $this->umil_end(); - } - break; - //case 'imageset' : - - case 'template' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT template_id - FROM ' . STYLES_TEMPLATE_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('template', $row['template_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - $template_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$template_row) - { - $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); - - // The following is from includes/acp/acp_styles.php - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) - { - $filelist = array('' => array()); - - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { -// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) -// { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); - } -// } - } - $this->db->sql_freeresult($result); - - $includes = array(); - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) - { - return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); - } - $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); - fclose($fp); - - if (preg_match_all('##is', $template_data, $matches)) - { - foreach ($matches[1] as $match) - { - $includes[trim($match)][] = $file; - } - } - } - } - - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - // Skip index. - if (strpos($file, 'index.') === 0) - { - continue; - } - - // We could do this using extended inserts ... but that could be one - // heck of a lot of data ... - $sql_ary = array( - 'template_id' => (int) $style_id, - 'template_filename' => "$pathfile$file", - 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', - 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - ); - - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE template_id = $style_id - AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; - $this->db->sql_query($sql); - } - } - unset($filelist); - } - - // Purge the forum's cache as well. - $cache->purge(); - - return $this->umil_end(); - } - break; - //case 'template' : - - case 'theme' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT theme_id - FROM ' . STYLES_THEME_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('theme', $row['theme_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $style_id"; - $result = $this->db->sql_query($sql); - $theme_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$theme_row) - { - $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); - - // The following is from includes/acp/acp_styles.php - if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) - { - $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) - { - continue; - } - - $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); - $stylesheet = str_replace($match, $content, $stylesheet); - } - } - - // adjust paths - $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); - - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => $db_theme_data, - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $this->db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - } - - return $this->umil_end(); - } - break; - //case 'theme' : - - default: - $this->umil_start('CACHE_PURGE'); - $cache->purge(); - - return $this->umil_end(); - break; - } - } - - /** - * Config Exists - * - * This function is to check to see if a config variable exists or if it does not. - * - * @param string $config_name The name of the config setting you wish to check for. - * @param bool $return_result - return the config value/default if true : default false. - * - * @return bool true/false if config exists - */ - function config_exists($config_name, $return_result = false) - { - global $config, $cache; - - $sql = 'SELECT * - FROM ' . CONFIG_TABLE . " - WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - if (!isset($config[$config_name])) - { - $config[$config_name] = $row['config_value']; - - if (!$row['is_dynamic']) - { - $cache->destroy('config'); - } - } - - return ($return_result) ? $row : true; - } - - // this should never happen, but if it does, we need to remove the config from the array - if (isset($config[$config_name])) - { - unset($config[$config_name]); - $cache->destroy('config'); - } - - return false; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_add($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_ADD', $config_name); - - if ($this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_update($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_UPDATE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - * - * @return result - */ - function config_remove($config_name) - { - global $cache, $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_REMOVE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $this->db->sql_query($sql); - - unset($config[$config_name]); - $cache->destroy('config'); - - return $this->umil_end(); - } - - /** - * Module Exists - * - * Check if a module exists - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - */ - function module_exists($class, $parent, $module) - { - // the main root directory should return true - if (!$module) - { - return true; - } - - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return false; - } - - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_class = '$class' - $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Module Add - * - * Add a new module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_add($class, $parent = 0, $data = array(), $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Prevent stupid things like trying to add a module with no name or any data on it - if (empty($data)) - { - $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - // allow sending the name as a string in $data to create a category - if (!is_array($data)) - { - $data = array('module_langname' => $data); - } - - if (!isset($data['module_langname'])) - { - // The "automatic" way - $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; - $basename = str_replace(array('/', '\\'), '', $basename); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_ADD', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module = $info->module(); - unset($info); - - $result = ''; - foreach ($module['modes'] as $mode => $module_info) - { - if (!isset($data['modes']) || in_array($mode, $data['modes'])) - { - $new_module = array( - 'module_basename' => $basename, - 'module_langname' => $module_info['title'], - 'module_mode' => $mode, - 'module_auth' => $module_info['auth'], - 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, - 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, - 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, - ); - - // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); - } - } - - return $result; - } - - // The "manual" way - $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - $parent = $data['parent_id'] = $row['module_id']; - } - else if (!$this->module_exists($class, false, $parent)) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - if ($this->module_exists($class, $parent, $data['module_langname'])) - { - return $this->umil_end('MODULE_ALREADY_EXIST'); - } - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - - $module_data = array( - 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, - 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, - 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', - 'module_class' => $class, - 'parent_id' => (int) $parent, - 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', - 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', - 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', - ); - $result = $acp_modules->update_module_data($module_data, true); - - // update_module_data can either return a string or an empty array... - if (is_string($result)) - { - // Error - $this->result = $this->get_output_text($result); - } - else - { - // Success - - // Move the module if requested above/below an existing one - if (isset($data['before']) && $data['before']) - { - $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; - $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_left - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - else if (isset($data['after']) && $data['after']) - { - $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; - $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_right - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - } - - // Clear the Modules Cache - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - - /** - * Module Remove - * - * Remove a module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_remove($class, $parent = 0, $module = '', $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto - if (is_array($module)) - { - if (isset($module['module_langname'])) - { - // Manual Method - return $this->module_remove($class, $parent, $module['module_langname'], $include_path); - } - - // Failed. - if (!isset($module['module_basename'])) - { - $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Automatic method - $basename = str_replace(array('/', '\\'), '', $module['module_basename']); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_REMOVE', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module_info = $info->module(); - unset($info); - - $result = ''; - foreach ($module_info['modes'] as $mode => $info) - { - if (!isset($module['modes']) || in_array($mode, $module['modes'])) - { - $result .= $this->module_remove($class, $parent, $info['title']) . '
'; - } - } - return $result; - } - else - { - $class = $this->db->sql_escape($class); - - if (!$this->module_exists($class, $parent, $module)) - { - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); - return $this->umil_end('MODULE_NOT_EXIST'); - } - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $module_ids = array(); - if (!is_numeric($module)) - { - $module = $this->db->sql_escape($module); - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $module_ids[] = (int) $row['module_id']; - } - $this->db->sql_freeresult($result); - - $module_name = $module; - } - else - { - $module = (int) $module; - $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " - WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $module_name = $row['module_langname']; - $module_ids[] = $module; - } - - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - $acp_modules->module_class = $class; - - foreach ($module_ids as $module_id) - { - $result = $acp_modules->delete_module($module_id); - if (!empty($result)) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = implode('
', $result); - } - else - { - $this->result .= '
' . implode('
', $result); - } - } - } - - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - } - - /** - * Permission Exists - * - * Check if a permission (auth) setting exists - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return bool true if it exists, false if not - */ - function permission_exists($auth_option, $global = true) - { - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" - . $type_sql; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Permission Add - * - * Add a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_add($auth_option, $global = true) - { - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_ADD', $auth_option); - - if ($this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); - } - - // We've added permissions, so set to true to notify the user. - $this->permissions_added = true; - - if (!class_exists('auth_admin')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - } - $auth_admin = new auth_admin(); - - // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. - if ($this->permission_exists($auth_option, !$global)) - { - $sql_ary = array( - 'is_global' => 1, - 'is_local' => 1, - ); - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; - $this->db->sql_query($sql); - } - else - { - if ($global) - { - $auth_admin->acl_add_option(array('global' => array($auth_option))); - } - else - { - $auth_admin->acl_add_option(array('local' => array($auth_option))); - } - } - - return $this->umil_end(); - } - - /** - * Permission Remove - * - * Remove a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_remove($auth_option, $global = true) - { - global $auth, $cache; - - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_REMOVE', $auth_option); - - if (!$this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); - } - - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . - $type_sql; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $id = $row['auth_option_id']; - - // If it is a local and global permission, do not remove the row! :P - if ($row['is_global'] && $row['is_local']) - { - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' - WHERE auth_option_id = ' . $id; - $this->db->sql_query($sql); - } - else - { - // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); - } - - // Purge the auth cache - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Add a new permission role - * - * @param string $role_name The new role name - * @param sting $role_type The type (u_, m_, a_) - */ - function permission_role_add($role_name, $role_type = '', $role_description = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_ADD', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if ($role_id) - { - return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); - } - - $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' - WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; - $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); - $role_order = (!$role_order) ? 1 : $role_order + 1; - - $sql_ary = array( - 'role_name' => $role_name, - 'role_description' => $role_description, - 'role_type' => $role_type, - 'role_order' => $role_order, - ); - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Update the name on a permission role - * - * @param string $old_role_name The old role name - * @param string $new_role_name The new role name - */ - function permission_role_update($old_role_name, $new_role_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); - } - - $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' - SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Remove a permission role - * - * @param string $role_name The role name to remove - */ - function permission_role_remove($role_name) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $role_name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Set - * - * Allows you to set permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission - */ - function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $new_auth = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $new_auth[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($new_auth)) - { - return false; - } - - $current_auth = array(); - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_SET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_SET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will add the requested permissions to that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0 - AND forum_id = 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_set($role_name, $auth_option, 'role', $has_permission); - } - - $this->umil_start('PERMISSION_SET_GROUP', $name); - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - } - - $sql_ary = array(); - switch ($type) - { - case 'role' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'role_id' => $role_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); - break; - - case 'group' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'group_id' => $group_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Unset - * - * Allows you to unset (remove) permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - */ - function permission_unset($name, $auth_option = array(), $type = 'role') - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $to_remove = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $to_remove[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($to_remove)) - { - return false; - } - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_UNSET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will remove the requested permissions from that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_unset($role_name, $auth_option, 'role'); - } - - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - - $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Table Exists - * - * Check if a table exists in the DB or not - * - * @param string $table_name The table name to check for - * - * @return bool true if the table exists, false if not - */ - function table_exists($table_name) - { - $this->get_table_name($table_name); - - // Use sql_table_exists if available - if (method_exists($this->db_tools, 'sql_table_exists')) - { - $roe = $this->db->return_on_error; - $result = $this->db_tools->sql_table_exists($table_name); - - // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before - if ($roe) - { - $this->db->sql_return_on_error(true); - } - - return $result; - } - - if (!function_exists('get_tables')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/functions_install.' . $phpEx); - } - - $tables = get_tables($this->db); - - if (in_array($table_name, $tables)) - { - return true; - } - else - { - return false; - } - } - - /** - * Table Add - * - * This only supports input from the array format of db_tools or create_schema_files. - */ - function table_add($table_name, $table_data = array()) - { - global $dbms, $user; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error - */ - if (empty($table_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ADD', $table_name); - - if ($this->table_exists($table_name)) - { - return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); - } - - if (!is_array($table_data)) - { - return $this->umil_end('NO_TABLE_DATA'); - } - - if (!function_exists('get_available_dbms')) - { - global $phpbb_root_path, $phpEx; - include("{$phpbb_root_path}includes/functions_install.$phpEx"); - } - - /* - * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore - if (method_exists($this->db_tools, 'sql_create_table')) - { - // Added in 3.0.5 - $this->db_tools->sql_create_table($table_name, $table_data); - } - else - {*/ - $available_dbms = get_available_dbms($dbms); - - $sql_query = $this->create_table_sql($table_name, $table_data); - $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); - - foreach ($sql_query as $sql) - { - $this->db->sql_query($sql); - } - //} - - return $this->umil_end(); - } - - /** - * Table Remove - * - * Delete/Drop a DB table - */ - function table_remove($table_name) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_REMOVE', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - if (method_exists($this->db_tools, 'sql_table_drop')) - { - // Added in 3.0.5 - $this->db_tools->sql_table_drop($table_name); - } - else - { - $this->db->sql_query('DROP TABLE ' . $table_name); - } - - return $this->umil_end(); - } - - /** - * Table Column Exists - * - * Check to see if a column exists in a table - */ - function table_column_exists($table_name, $column_name) - { - $this->get_table_name($table_name); - - return $this->db_tools->sql_column_exists($table_name, $column_name); - } - - /** - * Table Column Add - * - * Add a new column to a table. - */ - function table_column_add($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error - */ - if (empty($column_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); - - if ($this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); - } - - $this->db_tools->sql_column_add($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Update - * - * Alter/Update a column in a table. You can not change a column name with this. - */ - function table_column_update($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_change($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Remove - * - * Remove a column from a table - */ - function table_column_remove($table_name, $column_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_remove($table_name, $column_name); - - return $this->umil_end(); - } - - /** - * Table Index Exists - * - * Check if a table key/index exists on a table (can not check primary or unique) - */ - function table_index_exists($table_name, $index_name) - { - $this->get_table_name($table_name); - - $indexes = $this->db_tools->sql_list_index($table_name); - - if (in_array($index_name, $indexes)) - { - return true; - } - - return false; - } - - /** - * Table Index Add - * - * Add a new key/index to a table - */ - function table_index_add($table_name, $index_name = '', $column = array()) - { - global $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - // Let them skip the column field and just use the index name in that case as the column as well - if (empty($column)) - { - $column = array($index_name); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); - - if ($this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); - } - - if (!is_array($column)) - { - $column = array($column); - } - - // remove index length if we are before 3.0.8 - // the feature (required for some types when using MySQL4) - // was added in that release (ticket PHPBB3-8944) - if (version_compare($config['version'], '3.0.7-pl1', '<=')) - { - $column = preg_replace('#:.*$#', '', $column); - } - - $this->db_tools->sql_create_index($table_name, $index_name, $column); - - return $this->umil_end(); - } - - /** - * Table Index Remove - * - * Remove a key/index from a table - */ - function table_index_remove($table_name, $index_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); - - if (!$this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); - } - - $this->db_tools->sql_index_drop($table_name, $index_name); - - return $this->umil_end(); - } - - // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility - function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } - - /** - * Table Insert - * - * Insert data into a table - */ - function table_row_insert($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $this->db->sql_multi_insert($table_name, $data); - - return $this->umil_end(); - } - - /** - * Table Row Update - * - * Update a row in a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - * - * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). - */ - function table_row_update($table_name, $data = array(), $new_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'UPDATE ' . $table_name . ' - SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' - WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Table Row Remove - * - * Remove a row from a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - */ - function table_row_remove($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Version Checker - * - * Format the file like the following: - * http://www.phpbb.com/updatecheck/30x.txt - * - * @param string $url The url to access (ex: www.phpbb.com) - * @param string $path The path to access (ex: /updatecheck) - * @param string $file The name of the file to access (ex: 30x.txt) - * - * @return array|string Error Message if there was any error, or an array (each line in the file as a value) - */ - function version_check($url, $path, $file, $timeout = 10, $port = 80) - { - if (!function_exists('get_remote_file')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } - - $errstr = $errno = ''; - - $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); - - if ($info === false) - { - return $errstr . ' [ ' . $errno . ' ]'; - } - - $info = str_replace("\r\n", "\n", $info); - $info = explode("\n", $info); - - return $info; - } - - /** - * Create table SQL - * - * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array - * - * @param string $table_name The name of the table - * @param array $table_data The table data (formatted in the array format used by create_schema_files) - * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) - * - * @return The sql query to run for the submitted dbms to insert the table - */ - function create_table_sql($table_name, $table_data, $dbms = '') - { - // To allow testing - $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; - - // A list of types being unsigned for better reference in some db's - $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); - $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); - - $sql = ''; - - // Create Table statement - $generator = $textimage = false; - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'firebird': - case 'oracle': - case 'sqlite': - case 'postgres': - $sql .= "CREATE TABLE {$table_name} (\n"; - break; - - case 'mssql': - $sql .= "CREATE TABLE [{$table_name}] (\n"; - break; - } - - // Table specific so we don't get overlap - $modded_array = array(); - - // Write columns one by one... - foreach ($table_data['COLUMNS'] as $column_name => $column_data) - { - // Get type - if (strpos($column_data[0], ':') !== false) - { - list($orig_column_type, $column_length) = explode(':', $column_data[0]); - if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); - } - else - { - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) - { - case 'div': - $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; - $column_length = ceil($column_length); - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - break; - } - } - - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) - { - case 'mult': - $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; - if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) - { - $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; - $modded_array[$column_name] = $column_type; - } - else - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - } - break; - } - } - } - $orig_column_type .= ':'; - } - else - { - $orig_column_type = $column_data[0]; - $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; - if ($column_type == 'text' || $column_type == 'blob') - { - $modded_array[$column_name] = $column_type; - } - } - - // Adjust default value if db-dependant specified - if (is_array($column_data[1])) - { - $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= "\t{$column_name} {$column_type} "; - - // For hexadecimal values do not use single quotes - if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') - { - $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; - } - $sql .= 'NOT NULL'; - - if (isset($column_data[2])) - { - if ($column_data[2] == 'auto_increment') - { - $sql .= ' auto_increment'; - } - else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') - { - $sql .= ' COLLATE utf8_unicode_ci'; - } - } - - $sql .= ",\n"; - break; - - case 'sqlite': - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; - $generator = $column_name; - } - else - { - $sql .= "\t{$column_name} {$column_type} "; - } - - $sql .= 'NOT NULL '; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; - $sql .= ",\n"; - break; - - case 'firebird': - $sql .= "\t{$column_name} {$column_type} "; - - if (!is_null($column_data[1])) - { - $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; - } - - $sql .= 'NOT NULL'; - - // This is a UNICODE column and thus should be given it's fair share - if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) - { - $sql .= ' COLLATE UNICODE'; - } - - $sql .= ",\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'mssql': - if ($column_type == '[text]') - { - $textimage = true; - } - - $sql .= "\t[{$column_name}] {$column_type} "; - - if (!is_null($column_data[1])) - { - // For hexadecimal values do not use single quotes - if (strpos($column_data[1], '0x') === 0) - { - $sql .= 'DEFAULT (' . $column_data[1] . ') '; - } - else - { - $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; - } - } - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= 'IDENTITY (1, 1) '; - } - - $sql .= 'NOT NULL'; - $sql .= " ,\n"; - break; - - case 'oracle': - $sql .= "\t{$column_name} {$column_type} "; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - - // In Oracle empty strings ('') are treated as NULL. - // Therefore in oracle we allow NULL's for all DEFAULT '' entries - $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'postgres': - $sql .= "\t{$column_name} {$column_type} "; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; - - // Make sure the sequence will be created before creating the table - $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; - } - else - { - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - $sql .= "NOT NULL"; - - // Unsigned? Then add a CHECK contraint - if (in_array($orig_column_type, $unsigned_types)) - { - $sql .= " CHECK ({$column_name} >= 0)"; - } - - $sql .= ",\n"; - } - break; - } - } - - switch ($dbms) - { - case 'firebird': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);;\n\n"; - break; - - case 'mssql': - $sql = substr($sql, 0, -2); - $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; - $sql .= "GO\n\n"; - break; - } - - // Write primary key - if (isset($table_data['PRIMARY_KEY'])) - { - if (!is_array($table_data['PRIMARY_KEY'])) - { - $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'postgres': - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - - case 'firebird': - $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; - break; - - case 'sqlite': - if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) - { - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - } - break; - - case 'mssql': - $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; - $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; - $sql .= "\t(\n"; - $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; - $sql .= "\t) ON [PRIMARY] \n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - } - } - - switch ($dbms) - { - case 'oracle': - // UNIQUE contrains to be added? - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - if ($key_data[0] == 'UNIQUE') - { - $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; - } - } - } - - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n)\n/\n\n"; - break; - - case 'postgres': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'sqlite': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - } - - // Write Keys - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; - foreach ($key_data[1] as $key => $col_name) - { - if (isset($modded_array[$col_name])) - { - switch ($modded_array[$col_name]) - { - case 'text': - case 'blob': - $key_data[1][$key] = $col_name . '(255)'; - break; - } - } - } - $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; - break; - - case 'firebird': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; - break; - - case 'mssql': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - if ($key_data[0] == 'UNIQUE') - { - continue; - } - - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; - $sql .= "/\n"; - break; - - case 'sqlite': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - - case 'postgres': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - } - } - } - - switch ($dbms) - { - case 'mysql_40': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'mysql_41': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; - break; - - // Create Generator - case 'firebird': - if ($generator !== false) - { - $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; - $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; - - $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; - $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; - $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; - } - break; - - case 'oracle': - if ($generator !== false) - { - $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; - - $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; - $sql .= "BEFORE INSERT ON {$table_name}\n"; - $sql .= "FOR EACH ROW WHEN (\n"; - $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; - $sql .= ")\nBEGIN\n"; - $sql .= "\tSELECT {$table_name}_seq.nextval\n"; - $sql .= "\tINTO :new.{$generator}\n"; - $sql .= "\tFROM dual;\nEND;\n/\n\n"; - } - break; - } - - return $sql; - } - - /** - * Get the real table name - * By A_Jelly_Doughnut - * - * @param string $table_name The table name to get the real table name from - */ - function get_table_name(&$table_name) - { - // Use the global table prefix if a custom one is not specified - if ($this->table_prefix === false) - { - global $table_prefix; - } - else - { - $table_prefix = $this->table_prefix; - } - - static $constants = NULL; - - if (is_null($constants)) - { - $constants = get_defined_constants(); - } - - /** - * only do the replace if the table prefix is not already present - * this is required since UMIL supports specifying a table via phpbb_foo - * (where a replace would be needed) - * or by FOO_TABLE (where a replace is already done at constant-define time) - */ - if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) - { - $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); - } - } -} - -?> \ No newline at end of file diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 216faf9866..2fd795b659 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { - protected $container; + protected $config; protected $db; protected $db_tools; protected $table_prefix; @@ -33,31 +33,31 @@ class phpbb_db_migrator protected $migrations_table; protected $migration_state; - protected $migrations; + protected $migrations = array(); + + /** @var string Name of the last migration run */ + public $last_run_migration = false; /** * Constructor of the database migrator - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) + public function __construct($config, phpbb_db_driver $db, $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { - $this->container = $container; - $this->db = $this->container->get('dbal.conn'); - $this->db_tools = $this->container->get('dbal.tools'); - $this->table_prefix = $this->container->getParameters('core.table_prefix'); - $this->migrations_table = $this->container->getParameters('tables.migrations'); - $this->migrations = $migrations; - - $this->phpbb_root_path = $this->container->getParameters('core.root_path'); - $this->php_ext = $this->container->getParameters('core.php_ext'); - - /** @todo replace with collection_pass when merged */ - $this->tools = array( - 'config' => new phpbb_db_migration_tools_config, - 'module' => new phpbb_db_migration_tools_module, - 'permission' => new phpbb_db_migration_tools_permission, - ); + $this->config = $config; + $this->db = $db; + $this->db_tools = $db_tools; + + $this->migrations_table = $migrations_table; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->table_prefix = $table_prefix; + + foreach ($tools as $tool) + { + $this->tools[$tool->get_name()] = $tool; + } $this->load_migration_state(); } @@ -93,13 +93,44 @@ class phpbb_db_migrator $this->migrations = $class_names; } + /** + * Load migration data files from a directory + * + * @param string $path + * @return array Array of migrations with names + */ + public function load_migrations($path) + { + $handle = opendir($path); + while (($file = readdir($handle)) !== false) + { + if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) + { + $name = 'phpbb_db_migration_data_' . substr($file, 0, -(strlen($this->php_ext) + 1)); + + if (!in_array($name, $this->migrations)) + { + $this->migrations[] = $name; + } + } + } + + foreach ($this->migrations as $name) + { + if ($this->unfulfillable($name)) + { + throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + } + } + + return $this->migrations; + } + /** * Runs a single update step from the next migration to be applied. * * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. - * - * @return null */ public function update() { @@ -134,7 +165,8 @@ class phpbb_db_migrator return false; } - $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = $this->get_migration($name); + $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -157,6 +189,11 @@ class phpbb_db_migrator } } + $this->last_run_migration = array( + 'name' => $name, + 'class' => $migration, + ); + if (!isset($this->migration_state[$name])) { $state['migration_start_time'] = time(); @@ -187,20 +224,20 @@ class phpbb_db_migrator protected function process_data_step($migration) { - $continue = false; + //$continue = false; $steps = $migration->update_data(); foreach ($steps as $step) { $continue = $this->run_step($step); - if (!$continue) + /*if ($continue === false) { return false; - } + }*/ } - return $continue; + //return $continue; } protected function run_step($step) @@ -211,13 +248,12 @@ class phpbb_db_migrator $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; - call_user_func_array($callable, $parameters); - - return false; + return call_user_func_array($callable, $parameters); } catch (phpbb_db_migration_exception $e) { - echo $e;die(); + echo $e; + die(); } } @@ -325,7 +361,7 @@ class phpbb_db_migrator return true; } - $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = $this->get_migration($name); $depends = $migration->depends_on(); foreach ($depends as $depend) @@ -374,4 +410,15 @@ class phpbb_db_migrator { $this->db_tools->perform_schema_changes($schema_changes); } + + /** + * Helper to get a migration + * + * @param string $name Name of the migration + * @return phpbb_db_migration + */ + protected function get_migration($name) + { + return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); + } } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d0ef2759d5..057bdba0e3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2868,6 +2868,7 @@ function send_status_line($code, $message) else { $version = phpbb_request_http_version(); + header("$version $code $message", true, $code); } } @@ -5582,7 +5583,7 @@ function phpbb_convert_30_dbms_to_31($dbms) /* $reflection = new \ReflectionClass($dbms); - + if ($reflection->isSubclassOf('phpbb_db_driver')) { return $dbms; -- cgit v1.2.1 From aceadfd77b620677a838c61085c88db4d28e4a8a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:19:56 -0600 Subject: [feature/migrations] Remove migration data (separate PR) PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 28 -- phpBB/includes/db/migration/data/3_0_10.php | 28 -- phpBB/includes/db/migration/data/3_0_10_rc1.php | 30 -- phpBB/includes/db/migration/data/3_0_10_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_10_rc3.php | 28 -- phpBB/includes/db/migration/data/3_0_11.php | 28 -- phpBB/includes/db/migration/data/3_0_11_rc1.php | 98 ------ phpBB/includes/db/migration/data/3_0_11_rc2.php | 34 -- phpBB/includes/db/migration/data/3_0_12_rc1.php | 123 ------- phpBB/includes/db/migration/data/3_0_1_rc1.php | 79 ----- phpBB/includes/db/migration/data/3_0_2.php | 28 -- phpBB/includes/db/migration/data/3_0_2_rc1.php | 32 -- phpBB/includes/db/migration/data/3_0_2_rc2.php | 55 --- phpBB/includes/db/migration/data/3_0_3.php | 28 -- phpBB/includes/db/migration/data/3_0_3_rc1.php | 63 ---- phpBB/includes/db/migration/data/3_0_4.php | 49 --- phpBB/includes/db/migration/data/3_0_4_rc1.php | 107 ------ phpBB/includes/db/migration/data/3_0_5.php | 28 -- phpBB/includes/db/migration/data/3_0_5_rc1.php | 119 ------- .../includes/db/migration/data/3_0_5_rc1part2.php | 37 --- phpBB/includes/db/migration/data/3_0_6.php | 28 -- phpBB/includes/db/migration/data/3_0_6_rc1.php | 279 ---------------- phpBB/includes/db/migration/data/3_0_6_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_6_rc3.php | 40 --- phpBB/includes/db/migration/data/3_0_6_rc4.php | 28 -- phpBB/includes/db/migration/data/3_0_7.php | 28 -- phpBB/includes/db/migration/data/3_0_7_pl1.php | 28 -- phpBB/includes/db/migration/data/3_0_7_rc1.php | 53 --- phpBB/includes/db/migration/data/3_0_7_rc2.php | 72 ---- phpBB/includes/db/migration/data/3_0_8.php | 28 -- phpBB/includes/db/migration/data/3_0_8_rc1.php | 225 ------------- phpBB/includes/db/migration/data/3_0_9.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc1.php | 110 ------ phpBB/includes/db/migration/data/3_0_9_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc3.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc4.php | 28 -- phpBB/includes/db/migration/data/3_1_0_dev.php | 369 --------------------- phpBB/includes/db/migration/data/extensions.php | 49 --- .../includes/db/migration/data/style_update_p1.php | 157 --------- .../includes/db/migration/data/style_update_p2.php | 42 --- phpBB/includes/db/migration/data/timezone.php | 161 --------- 41 files changed, 2887 deletions(-) delete mode 100644 phpBB/includes/db/migration/data/3_0_1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_12_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_1_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_3_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_4.php delete mode 100644 phpBB/includes/db/migration/data/3_0_4_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1part2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc4.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_pl1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_8.php delete mode 100644 phpBB/includes/db/migration/data/3_0_8_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc4.php delete mode 100644 phpBB/includes/db/migration/data/3_1_0_dev.php delete mode 100644 phpBB/includes/db/migration/data/extensions.php delete mode 100644 phpBB/includes/db/migration/data/style_update_p1.php delete mode 100644 phpBB/includes/db/migration/data/style_update_p2.php delete mode 100644 phpBB/includes/db/migration/data/timezone.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php deleted file mode 100644 index a2332c9b59..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ /dev/null @@ -1,28 +0,0 @@ -sql_query($sql); - - $deactivated_style_ids = array(); - while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) - { - $deactivated_style_ids[] = (int) $style_id; - } - $this->db->sql_freeresult($result); - - if (!empty($deactivated_style_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->config['default_style'] .' - WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); - $this->sql_query($sql); - } - } - - function delete_orphan_private_messages() - { - // Delete orphan private messages - $batch_size = 500; - - $sql_array = array( - 'SELECT' => 'p.msg_id', - 'FROM' => array( - PRIVMSGS_TABLE => 'p', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), - 'ON' => 'p.msg_id = t.msg_id', - ), - ), - 'WHERE' => 't.user_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - - $result = $this->db->sql_query_limit($sql, $batch_size); - - $delete_pms = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql); - - return true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php deleted file mode 100644 index f2bed54085..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ /dev/null @@ -1,34 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.update', array('version', '3.0.11-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php deleted file mode 100644 index 0d8702f19e..0000000000 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ /dev/null @@ -1,123 +0,0 @@ -db->sql_query($sql); - - $bot_user_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $bot_user_ids[] = (int) $row['user_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($bot_user_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_allow_pm = 0 - WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); - $this->sql_query($sql); - } - } - - public function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'acl_u_sig\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'signature\''; - $this->sql_query($sql); - } - - public function update_bots() - { - // Update bots - if (!function_exists('user_delete')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - - $bots_updates = array( - // Bot Deletions - 'NG-Search [Bot]' => false, - 'Nutch/CVS [Bot]' => false, - 'OmniExplorer [Bot]' => false, - 'Seekport [Bot]' => false, - 'Synoo [Bot]' => false, - 'WiseNut [Bot]' => false, - - // Bot Updates - // Bot name to bot user agent map - 'Baidu [Spider]' => 'Baiduspider', - 'Exabot [Bot]' => 'Exabot', - 'Voyager [Bot]' => 'voyager/', - 'W3C [Validator]' => 'W3C_Validator', - ); - - foreach ($bots_updates as $bot_name => $bot_agent) - { - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . ' - WHERE user_type = ' . USER_IGNORE . " - AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; - $result = $this->db->sql_query($sql); - $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if ($bot_user_id) - { - if ($bot_agent === false) - { - $sql = 'DELETE FROM ' . BOTS_TABLE . " - WHERE user_id = $bot_user_id"; - $this->sql_query($sql); - - user_delete('remove', $bot_user_id); - } - else - { - $sql = 'UPDATE ' . BOTS_TABLE . " - SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' - WHERE user_id = $bot_user_id"; - $this->sql_query($sql); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php deleted file mode 100644 index a3b4810d21..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ /dev/null @@ -1,79 +0,0 @@ - array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list' => array('BOOL', 1), - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('UINT', 0), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'groups' => array('group_legend'), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('session_forum_id'), - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name' => array('group_legend', 'group_name'), - ), - ), - ); - } - - function update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - - array('config.update', array('version', '3.0.1-rc1')), - ); - } - - function fix_unset_last_view_time() - { - $sql = 'UPDATE ' . $this->table_prefix . "topics - SET topic_last_view_time = topic_last_post_time - WHERE topic_last_view_time = 0"; - $this->sql_query($sql); - } - - function reset_smiley_size() - { - // Update smiley sizes - $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); - - foreach ($smileys as $smiley) - { - if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) - { - list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); - - $sql = 'UPDATE ' . SMILIES_TABLE . ' - SET smiley_width = ' . $width . ', smiley_height = ' . $height . " - WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; - - $this->sql_query($sql); - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php deleted file mode 100644 index 3469d8d178..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - $this->table_prefix . 'drafts' => array( - 'draft_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'forums' => array( - 'forum_last_post_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'posts' => array( - 'post_subject' => array('STEXT_UNI', '', 'true_sort'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'topics' => array( - 'topic_title' => array('STEXT_UNI', '', 'true_sort'), - 'topic_last_post_subject' => array('STEXT_UNI', ''), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid' => array('session_forum_id'), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.update', array('version', '3.0.2-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php deleted file mode 100644 index dff375f438..0000000000 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('enable_queue_trigger', '0')), - array('config.add', array('queue_trigger_posts', '3')), - array('config.add', array('pm_max_recipients', '0')), - array('custom', array(array(&$this, 'set_group_default_max_recipients'))), - array('config.add', array('dbms_version', $this->db->sql_server_info(true))), - array('permission.add', array('u_masspm_group', true, 'u_masspm')), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - - array('config.update', array('version', '3.0.3-rc1')), - ); - } - - function correct_acp_email_permissions() - { - $sql = 'UPDATE ' . $this->table_prefix . 'modules - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - $this->sql_query($sql); - } - - function set_group_default_max_recipients() - { - // Set maximum number of recipients for the registered users, bots, guests group - $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 - WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php deleted file mode 100644 index 1af4508331..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ /dev/null @@ -1,49 +0,0 @@ -db->sql_layer == 'oracle') - { - // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation = 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php deleted file mode 100644 index e9bb0e01f5..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ /dev/null @@ -1,107 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile' => array('BOOL', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'styles' => array( - 'style_id' => array('UINT', NULL, 'auto_increment'), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_imageset' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_theme' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template_data' => array( - 'template_id' => array('UINT', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_style' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('custom', array(array(&$this, 'update_custom_profile_fields'))), - - array('config.update', array('version', '3.0.4-rc1')), - ); - } - - function update_custom_profile_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide - FROM ' . PROFILE_FIELDS_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'field_required' => 0, - 'field_show_on_reg' => 0, - 'field_hide' => 0, - 'field_show_profile'=> 0, - ); - - if ($row['field_required']) - { - $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_show_on_reg']) - { - $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_hide']) - { - // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module - $sql_ary['field_hide'] = 1; - } - else - { - // equivelant to "none", which is the "Display in user control panel" option - $sql_ary['field_show_profile'] = 1; - } - - $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); - } - - $this->db->sql_freeresult($result); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php deleted file mode 100644 index 2f80970781..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - ), - ); - } - - function update_data() - { - $search_indexing_state = $this->config['search_indexing_state']; - - return array( - array('config.add', array('captcha_gd_wave', 0)), - array('config.add', array('captcha_gd_3d_noise', 1)), - array('config.add', array('captcha_gd_fonts', 1)), - array('config.add', array('confirm_refresh', 1)), - array('config.add', array('max_num_search_keywords', 10)), - array('config.remove', array('search_indexing_state')), - array('config.add', array('search_indexing_state', $search_indexing_state, true)), - array('custom', array(array(&$this, 'hash_old_passwords'))), - array('custom', array(array(&$this, 'update_ichiro_bot'))), - ); - } - - function hash_old_passwords() - { - $sql = 'SELECT user_id, user_password - FROM ' . $this->table_prefix . 'users - WHERE user_pass_convert = 1'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (strlen($row['user_password']) == 32) - { - $sql_ary = array( - 'user_password' => phpbb_hash($row['user_password']), - ); - - $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); - } - } - $this->db->sql_freeresult($result); - } - - function update_ichiro_bot() - { - // Adjust bot entry - $sql = 'UPDATE ' . $this->table_prefix . "bots - SET bot_agent = 'ichiro/' - WHERE bot_agent = 'ichiro/2'"; - $this->sql_query($sql); - } - - function remove_duplicate_auth_options() - { - // Before we are able to add a unique key to auth_option, we need to remove duplicate entries - $sql = 'SELECT auth_option - FROM ' . $this->table_prefix . 'acl_options - GROUP BY auth_option - HAVING COUNT(*) >= 2'; - $result = $this->db->sql_query($sql); - - $auth_options = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $auth_options[] = $row['auth_option']; - } - $this->db->sql_freeresult($result); - - // Remove specific auth options - if (!empty($auth_options)) - { - foreach ($auth_options as $option) - { - // Select auth_option_ids... the largest id will be preserved - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $db->sql_escape($option) . "' - ORDER BY auth_option_id DESC"; - // sql_query_limit not possible here, due to bug in postgresql layer - $result = $this->db->sql_query($sql); - - // Skip first row, this is our original auth option we want to preserve - $row = $this->db->sql_fetchrow($result); - - while ($row = $this->db->sql_fetchrow($result)) - { - // Ok, remove this auth option... - $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - } - $this->db->sql_freeresult($result); - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php deleted file mode 100644 index 1fab0f8873..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ /dev/null @@ -1,37 +0,0 @@ - array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.update', array('version', '3.0.5-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php deleted file mode 100644 index 26176b9437..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - $this->table_prefix . 'confirm' => array( - 'attempts' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_new' => array('BOOL', 1), - 'user_reminded' => array('TINT:4', 0), - 'user_reminded_time' => array('TIMESTAMP', 0), - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported' => array('BOOL', 0), - ), - $this->table_prefix . 'reports' => array( - 'pm_id' => array('UINT', 0), - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_vt' => array('BOOL', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_options' => array('UINT:20', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_options' => array('UINT:11', 230271), - ), - ), - 'add_index' => array( - $this->table_prefix . 'reports' => array( - 'post_id' => array('post_id'), - 'pm_id' => array('pm_id'), - ), - $this->table_prefix . 'posts' => array( - 'post_username' => array('post_username:255'), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('if', array( - ($this->config['captcha_gd']), - array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), - )), - - array('config.add', array('feed_enable', 0)), - array('config.add', array('feed_limit', 10)), - array('config.add', array('feed_overall_forums', 1)), - array('config.add', array('feed_overall_forums_limit', 15)), - array('config.add', array('feed_overall_topics', 0)), - array('config.add', array('feed_overall_topics_limit', 15)), - array('config.add', array('feed_forum', 1)), - array('config.add', array('feed_topic', 1)), - array('config.add', array('feed_item_statistics', 1)), - - array('config.add', array('smilies_per_page', 50)), - array('config.add', array('allow_pm_report', 1)), - array('config.add', array('min_post_chars', 1)), - array('config.add', array('allow_quick_reply', 1)), - array('config.add', array('new_member_post_limit', 0)), - array('config.add', array('new_member_group_default', 0)), - array('config.add', array('delete_time', $this->config['edit_time'])), - - array('config.add', array('allow_avatar', 0)), - array('if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - array('config.update', array('allow_avatar', 1)), - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - array('config.update', array('allow_avatar_remote_upload', 1)), - )), - - array('module.add', array( - 'acp', - 'ACP_BOARD_CONFIGURATION', - array( - 'module_basename' => 'acp_board', - 'modes' => array('feed'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_CAT_USERS', - array( - 'module_basename' => 'acp_users', - 'modes' => array('warnings'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_SERVER_CONFIGURATION', - array( - 'module_basename' => 'acp_send_statistics', - 'modes' => array('send_statistics'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_FORUM_BASED_PERMISSIONS', - array( - 'module_basename' => 'acp_permissions', - 'modes' => array('setting_forum_copy'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'mcp_pm_reports', - 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - - array('config.update', array('version', '3.0.6-rc1')), - ); - } - - function set_user_options_default() - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - $this->sql_query($sql); - } - - function add_newly_registered_group() - { - // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'NEWLY_REGISTERED'"; - $result = $this->db->sql_query($sql); - $group_id = (int) $this->db->sql_fetchfield('group_id'); - $this->db->sql_freeresult($result); - - if (!$group_id) - { - $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; - $this->sql_query($sql); - - $group_id = $this->db->sql_nextid(); - } - - // Insert new user role... at the end of the chain - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_USER_NEW_MEMBER' - AND role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $u_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$u_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; - $this->sql_query($sql); - $u_role = $this->db->sql_nextid(); - - // Now add the correct data to the roles... - // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - $this->sql_query($sql); - - // Add user role to group - $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - $this->sql_query($sql); - } - - // Insert new forum role - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' - AND role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $f_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$f_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; - $this->sql_query($sql); - $f_role = $this->db->sql_nextid(); - - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - $this->sql_query($sql); - } - - // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) - $sql = 'SELECT 1 - FROM ' . USERS_TABLE . ' - WHERE user_new = 0'; - $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; - $this->sql_query($sql); - } - - // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... - // Check if the role is already assigned... - $sql = 'SELECT forum_id - FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id = ' . $f_role; - $result = $this->db->sql_query($sql); - $is_options = (int) $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - // Not assigned at all... :/ - if (!$is_options) - { - // Get postable forums - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type != ' . FORUM_LINK; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); - } - $this->db->sql_freeresult($result); - } - - // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php deleted file mode 100644 index 4092a5fa61..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php deleted file mode 100644 index e748c7a4ff..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - $this->table_prefix . 'log' => array('log_time'), - ), - 'add_index' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id' => array('topic_id'), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('feed_overall', 1)), - array('config.add', array('feed_http_auth', 0)), - array('config.add', array('feed_limit_post', $this->config['feed_limit'])), - array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), - array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), - array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), - array('custom', array(array(&$this, 'delete_text_templates'))), - - array('config.update', array('version', '3.0.7-rc1')), - ); - } - - function delete_text_templates() - { - // Delete all text-templates from the template_data - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php deleted file mode 100644 index e2c6acce1e..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ /dev/null @@ -1,72 +0,0 @@ - ' . USER_IGNORE . " - AND user_email <> ''"; - $result = $this->db->sql_query_limit($sql, $limit, $start); - - $i = 0; - while ($row = $this->db->sql_fetchrow($result)) - { - $i++; - - // Snapshot of the phpbb_email_hash() function - // We cannot call it directly because the auto updater updates the DB first. :/ - $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); - - if ($user_email_hash != $row['user_email_hash']) - { - $sql_ary = array( - 'user_email_hash' => $user_email_hash, - ); - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_id = ' . (int) $row['user_id']; - $this->sql_query($sql); - } - } - $this->db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return false; - } - - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php deleted file mode 100644 index a5defc8278..0000000000 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ /dev/null @@ -1,28 +0,0 @@ - 'acp_board', - 'modes' => array('post'), - ), - )), - array('config.add', array('load_unreads_search', 1)), - array('config.update_if_equals', array(600, 'queue_interval', 60)), - array('config.update_if_equals', array(50, 'email_package_size', 20)), - - array('config.update', array('version', '3.0.8-rc1')), - ); - } - - function update_file_extension_group_names() - { - // Update file extension group names to use language strings. - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - $extension_groups_updated = array(); - while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) - { - $lang_dir = basename($lang_dir); - - // The language strings we need are either in language/.../acp/attachments.php - // in the update package if we're updating to 3.0.8-RC1 or later, - // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. - // On an already updated board, they can also already be in language/.../acp/attachments.php - // in the board root. - $lang_files = array( - "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", - "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", - ); - - foreach ($lang_files as $lang_file) - { - if (!file_exists($lang_file)) - { - continue; - } - - $lang = array(); - include($lang_file); - - foreach($lang as $lang_key => $lang_val) - { - if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) - { - continue; - } - - $sql_ary = array( - 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; - $this->sql_query($sql); - - $extension_groups_updated[$lang_key] = true; - } - } - } - $this->db->sql_freeresult($result); - } - - function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'avatar\''; - $this->sql_query($sql); - } - - function update_bots() - { - $bot_name = 'Bing [Bot]'; - $bot_name_clean = utf8_clean_string($bot_name); - - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; - $result = $this->db->sql_query($sql); - $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if (!$bing_already_added) - { - $bot_agent = 'bingbot/'; - $bot_ip = ''; - $sql = 'SELECT group_id, group_colour - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'BOTS'"; - $result = $this->db->sql_query($sql); - $group_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$group_row) - { - // default fallback, should never get here - $group_row['group_id'] = 6; - $group_row['group_colour'] = '9E8DA7'; - } - - if (!function_exists('user_add')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - - $user_row = array( - 'user_type' => USER_IGNORE, - 'group_id' => $group_row['group_id'], - 'username' => $bot_name, - 'user_regdate' => time(), - 'user_password' => '', - 'user_colour' => $group_row['group_colour'], - 'user_email' => '', - 'user_lang' => $this->config['default_lang'], - 'user_style' => $this->config['default_style'], - 'user_timezone' => 0, - 'user_dateformat' => $this->config['default_dateformat'], - 'user_allow_massemail' => 0, - ); - - $user_id = user_add($user_row); - - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'bot_active' => 1, - 'bot_name' => (string) $bot_name, - 'user_id' => (int) $user_id, - 'bot_agent' => (string) $bot_agent, - 'bot_ip' => (string) $bot_ip, - )); - - $this->sql_query($sql); - } - } - - function delete_orphan_shadow_topics() - { - // Delete shadow topics pointing to not existing topics - $batch_size = 500; - - // Set of affected forums we have to resync - $sync_forum_ids = array(); - - $sql_array = array( - 'SELECT' => 't1.topic_id, t1.forum_id', - 'FROM' => array( - TOPICS_TABLE => 't1', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(TOPICS_TABLE => 't2'), - 'ON' => 't1.topic_moved_id = t2.topic_id', - ), - ), - 'WHERE' => 't1.topic_moved_id <> 0 - AND t2.topic_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - $result = $this->db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['topic_id']; - - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); - $this->db->sql_query($sql); - - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); - - return true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php deleted file mode 100644 index eb359e2697..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - $this->table_prefix . 'login_attempts' => array( - 'COLUMNS' => array( - // this column was removed from the database updater - // after 3.0.9-RC3 was released. It might still exist - // in 3.0.9-RCX installations and has to be dropped in - // 3.0.12 after the db_tools class is capable of properly - // removing a primary key. - // 'attempt_id' => array('UINT', NULL, 'auto_increment'), - 'attempt_ip' => array('VCHAR:40', ''), - 'attempt_browser' => array('VCHAR:150', ''), - 'attempt_forwarded_for' => array('VCHAR:255', ''), - 'attempt_time' => array('TIMESTAMP', 0), - 'user_id' => array('UINT', 0), - 'username' => array('VCHAR_UNI:255', 0), - 'username_clean' => array('VCHAR_CI', 0), - ), - //'PRIMARY_KEY' => 'attempt_id', - 'KEYS' => array( - 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), - 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), - 'att_time' => array('INDEX', array('attempt_time')), - 'user_id' => array('INDEX', 'user_id'), - ), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'bbcodes' => array( - 'bbcode_id' => array('USINT', 0), - ), - ), - ); - } - - function update_data() - { - return array( - array('config.add', array('ip_login_limit_max', 50)), - array('config.add', array('ip_login_limit_time', 21600)), - array('config.add', array('ip_login_limit_use_forwarded', 0)), - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), - - array('config.update', array('version', '3.0.9-rc1')), - ); - } - - function update_file_extension_group_names() - { - // Update file extension group names to use language strings, again. - $sql = 'SELECT group_id, group_name - FROM ' . EXTENSION_GROUPS_TABLE . ' - WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - function fix_firebird_qa_captcha() - { - // Recover from potentially broken Q&A CAPTCHA table on firebird - // Q&A CAPTCHA was uninstallable, so it's safe to remove these - // without data loss - if ($this->db_tools->sql_layer == 'firebird') - { - $tables = array( - $this->table_prefix . 'captcha_questions', - $this->table_prefix . 'captcha_answers', - $this->table_prefix . 'qa_confirm', - ); - foreach ($tables as $table) - { - if ($this->db_tools->sql_table_exists($table)) - { - $this->db_tools->sql_table_drop($table); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php deleted file mode 100644 index e3c4716665..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ - array( - GROUPS_TABLE => array( - 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), - ), - PROFILE_FIELDS_TABLE => array( - 'field_show_on_pm' => array('BOOL', 0), - ), - STYLES_TABLE => array( - 'style_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'style_parent_id' => array('UINT:4', 0), - 'style_parent_tree' => array('TEXT', ''), - ), - REPORTS_TABLE => array( - 'reported_post_text' => array('MTEXT_UNI', ''), - 'reported_post_uid' => array('VCHAR:8', ''), - 'reported_post_bitfield' => array('VCHAR:255', ''), - ), - ), - 'change_columns' => array( - GROUPS_TABLE => array( - 'group_legend' => array('UINT', 0), - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), - - array('config.add', array('fulltext_postgres_ts_name', 'simple')), - array('config.add', array('fulltext_postgres_min_word_len', 4)), - array('config.add', array('fulltext_postgres_max_word_len', 254)), - array('config.add', array('fulltext_sphinx_stopwords', 0)), - array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), - - array('config.add', array('load_jquery_cdn', 0)), - array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), - - array('config.add', array('use_system_cron', 0)), - - array('config.add', array('legend_sort_groupname', 0)), - array('config.add', array('teampage_forums', 1)), - array('config.add', array('teampage_memberships', 1)), - - array('config.add', array('load_cpf_pm', 0)), - - array('config.add', array('display_last_subject', 1)), - - array('config.add', array('assets_version', 1)), - - array('config.add', array('site_home_url', '')), - array('config.add', array('site_home_text', '')), - - array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), - - array('module.add', array( - 'acp', - 'ACP_GROUPS', - array( - 'module_basename' => 'acp_groups', - 'modes' => array('position'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_ATTACHMENTS', - array( - 'module_basename' => 'acp_attachments', - 'modes' => array('manage'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_STYLE_MANAGEMENT', - array( - 'module_basename' => 'acp_styles', - 'modes' => array('install', 'cache'), - ), - )), - array('module.add', array( - 'ucp', - 'UCP_PROFILE', - array( - 'module_basename' => 'ucp_profile', - 'modes' => array('autologin_keys'), - ), - )), - - array('module.remove', array( - 'acp', - false, - 'ACP_TEMPLATES', - )), - array('module.remove', array( - 'acp', - false, - 'ACP_THEMES', - )), - array('module.remove', array( - 'acp', - false, - 'ACP_IMAGESETS', - )), - - array('custom', array(array($this, 'rename_module_basenames'))), - array('custom', array(array($this, 'rename_styles_module'))), - array('custom', array(array($this, 'add_group_teampage'))), - array('custom', array(array($this, 'update_group_legend'))), - array('custom', array(array($this, 'localise_global_announcements'))), - array('custom', array(array($this, 'update_ucp_pm_basename'))), - array('custom', array(array($this, 'update_ucp_profile_auth'))), - array('custom', array(array($this, 'move_customise_modules'))), - - array('config.update', array('version', '3.1.0-dev')), - ); - } - - public function move_customise_modules() - { - // Move language management to new location in the Customise tab - // First get language module id - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_basename = 'acp_language'"; - $result = $this->db->sql_query($sql); - $language_module_id = $this->db->sql_fetchfield('module_id'); - $this->db->sql_freeresult($result); - // Next get language management module id of the one just created - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = 'ACP_LANGUAGE'"; - $result = $this->db->sql_query($sql); - $language_management_module_id = $this->db->sql_fetchfield('module_id'); - $this->db->sql_freeresult($result); - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - } - // acp_modules calls adm_back_link, which is undefined at this point - if (!function_exists('adm_back_link')) - { - include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); - } - $module_manager = new acp_modules(); - $module_manager->module_class = 'acp'; - $module_manager->move_module($language_module_id, $language_management_module_id); - } - - public function update_ucp_pm_basename() - { - $sql = 'SELECT module_id, module_basename - FROM ' . MODULES_TABLE . " - WHERE module_basename <> 'ucp_pm' AND - module_langname='UCP_PM'"; - $result = $this->db->sql_query_limit($sql, 1); - - if ($row = $this->db->sql_fetchrow($result)) - { - // This update is still not applied. Applying it - - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_basename = 'ucp_pm' - WHERE module_id = " . (int) $row['module_id']; - - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - public function update_ucp_profile_auth() - { - // Update the auth setting for the module - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_auth = 'acl_u_chgprofileinfo' - WHERE module_class = 'ucp' - AND module_basename = 'ucp_profile' - AND module_mode = 'profile_info'"; - $this->sql_query($sql); - } - - public function rename_styles_module() - { - // Rename styles module to Customise - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_langname = 'ACP_CAT_CUSTOMISE' - WHERE module_langname = 'ACP_CAT_STYLES'"; - $this->sql_query($sql); - } - - public function rename_module_basenames() - { - // rename all module basenames to full classname - $sql = 'SELECT module_id, module_basename, module_class - FROM ' . MODULES_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $module_id = (int) $row['module_id']; - unset($row['module_id']); - - if (!empty($row['module_basename']) && !empty($row['module_class'])) - { - // all the class names start with class name or with phpbb_ for auto loading - if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && - strpos($row['module_basename'], 'phpbb_') !== 0) - { - $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; - - $sql_update = $this->db->sql_build_array('UPDATE', $row); - - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET ' . $sql_update . ' - WHERE module_id = ' . $module_id; - $this->sql_query($sql); - } - } - } - - $this->db->sql_freeresult($result); - } - - public function add_group_teampage() - { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 1 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'ADMINISTRATORS'"; - $this->sql_query($sql); - - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 2 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'GLOBAL_MODERATORS'"; - $this->sql_query($sql); - } - - public function update_group_legend() - { - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . ' - WHERE group_legend = 1 - ORDER BY group_name ASC'; - $result = $this->db->sql_query($sql); - - $next_legend = 1; - while ($row = $this->db->sql_fetchrow($result)) - { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_legend = ' . $next_legend . ' - WHERE group_id = ' . (int) $row['group_id']; - $this->sql_query($sql); - - $next_legend++; - } - $this->db->sql_freeresult($result); - } - - public function localise_global_announcements() - { - // Localise Global Announcements - $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = 0 - AND topic_type = ' . POST_GLOBAL; - $result = $this->db->sql_query($sql); - - $global_announcements = $update_lastpost_data = array(); - $update_lastpost_data['forum_last_post_time'] = 0; - $update_forum_data = array( - 'forum_posts' => 0, - 'forum_topics' => 0, - 'forum_topics_real' => 0, - ); - - while ($row = $this->db->sql_fetchrow($result)) - { - $global_announcements[] = (int) $row['topic_id']; - - $update_forum_data['forum_posts'] += (int) $row['topic_posts']; - $update_forum_data['forum_topics_real']++; - if ($row['topic_approved']) - { - $update_forum_data['forum_topics']++; - } - - if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) - { - $update_lastpost_data = array( - 'forum_last_post_id' => (int) $row['topic_last_post_id'], - 'forum_last_post_subject' => $row['topic_last_post_subject'], - 'forum_last_post_time' => (int) $row['topic_last_post_time'], - 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], - 'forum_last_poster_name' => $row['topic_last_poster_name'], - 'forum_last_poster_colour' => $row['topic_last_poster_colour'], - ); - } - } - $this->db->sql_freeresult($result); - - if (!empty($global_announcements)) - { - // Update the post/topic-count for the forum and the last-post if needed - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type = ' . FORUM_POST; - $result = $this->db->sql_query_limit($sql, 1); - $ga_forum_id = $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - $sql = 'SELECT forum_last_post_time - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $ga_forum_id; - $result = $this->db->sql_query($sql); - $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); - $this->db->sql_freeresult($result); - - $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; - $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; - $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; - if ($lastpost < $update_lastpost_data['forum_last_post_time']) - { - $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); - } - - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET ' . $sql_update . ' - WHERE forum_id = ' . $ga_forum_id; - $this->sql_query($sql); - - // Update some forum_ids - $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); - foreach ($table_ary as $table) - { - $sql = "UPDATE $table - SET forum_id = $ga_forum_id - WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); - $this->sql_query($sql); - } - unset($table_ary); - } - } -} diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php deleted file mode 100644 index d28e0ebabb..0000000000 --- a/phpBB/includes/db/migration/data/extensions.php +++ /dev/null @@ -1,49 +0,0 @@ - array( - EXT_TABLE => array( - 'COLUMNS' => array( - 'ext_name' => array('VCHAR', ''), - 'ext_active' => array('BOOL', 0), - 'ext_state' => array('TEXT', ''), - ), - 'KEYS' => array( - 'ext_name' => array('UNIQUE', 'ext_name'), - ), - ), - ), - ); - } - - public function update_data() - { - return array( - array('module.add', array( - 'acp', - 'ACP_GENERAL_TASKS', - array( - 'module_basename' => 'acp_extensions', - 'modes' => array('main'), - ), - )), - array('permission.add', array('a_extensions', true, 'a_styles')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php deleted file mode 100644 index 1c46e4147b..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ /dev/null @@ -1,157 +0,0 @@ -phpbb_root_path . 'styles'); - $skip_dirs = array('.', '..', 'prosilver'); - foreach ($iterator as $fileinfo) - { - if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) - { - $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); - if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) - { - // 3.1 style - $available_styles[] = $fileinfo->getFilename(); - } - } - } - - // Get all installed styles - if ($this->db_tools->sql_table_exists(STYLES_IMAGESET_TABLE)) - { - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i - WHERE t.template_id = s.template_id - AND c.theme_id = s.theme_id - AND i.imageset_id = s.imageset_id"; - } - else - { - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c - WHERE t.template_id = s.template_id - AND c.theme_id = s.theme_id"; - } - $result = $this->db->sql_query($sql); - - $styles = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $styles[] = $row; - } - $this->db->sql_freeresult($result); - - // Decide which styles to keep, all others will be deleted - $valid_styles = array(); - foreach ($styles as $style_row) - { - if ( - // Delete styles with parent style (not supported yet) - $style_row['template_inherits_id'] == 0 && - // Check if components match - $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && - // Check if components are valid - in_array($style_row['template_path'], $available_styles) - ) - { - // Valid style. Keep it - $sql_ary = array( - 'style_path' => $style_row['template_path'], - 'bbcode_bitfield' => $style_row['bbcode_bitfield'], - 'style_parent_id' => 0, - 'style_parent_tree' => '', - ); - $this->sql_query('UPDATE ' . STYLES_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE style_id = ' . $style_row['style_id']); - $valid_styles[] = (int) $style_row['style_id']; - } - } - - // Remove old entries from styles table - if (!sizeof($valid_styles)) - { - // No valid styles: remove everything and add prosilver - $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); - - $sql_ary = array( - 'style_name' => 'prosilver', - 'style_copyright' => '© phpBB Group', - 'style_active' => 1, - 'style_path' => 'prosilver', - 'bbcode_bitfield' => 'kNg=', - 'style_parent_id' => 0, - 'style_parent_tree' => '', - - // Will be removed in the next step - 'imageset_id' => 0, - 'template_id' => 0, - 'theme_id' => 0, - ); - - $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->sql_query($sql); - - $sql = 'SELECT style_id - FROM ' . $table . " - WHERE style_name = 'prosilver'"; - $result = $this->sql_query($sql); - $default_style = $this->db->sql_fetchfield($result); - $this->db->sql_freeresult($result); - - set_config('default_style', $default_style); - - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; - $this->sql_query($sql); - } - else - { - // There are valid styles in styles table. Remove styles that are outdated - $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' - WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); - - // Change default style - if (!in_array($this->config['default_style'], $valid_styles)) - { - $this->sql_query('UPDATE ' . CONFIG_TABLE . " - SET config_value = '" . $valid_styles[0] . "' - WHERE config_name = 'default_style'"); - } - - // Reset styles for users - $this->sql_query('UPDATE ' . USERS_TABLE . ' - SET user_style = 0 - WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); - } - } -} diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php deleted file mode 100644 index db4b7f1753..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ /dev/null @@ -1,42 +0,0 @@ - array( - STYLES_TABLE => array( - 'imageset_id', - 'template_id', - 'theme_id', - ), - ), - - 'drop_tables' => array( - STYLES_IMAGESET_TABLE, - STYLES_IMAGESET_DATA_TABLE, - STYLES_TEMPLATE_TABLE, - STYLES_TEMPLATE_DATA_TABLE, - STYLES_THEME_TABLE, - ), - ); - } - - public function update_data() - { - return array(); - } -} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php deleted file mode 100644 index 7734ed4b76..0000000000 --- a/phpBB/includes/db/migration/data/timezone.php +++ /dev/null @@ -1,161 +0,0 @@ - array( - USERS_TABLE => array( - 'user_timezone' => array('VCHAR:100', ''), - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array($this, 'update_timezones'))), - ); - } - - public function update_timezones() - { - // Update user timezones - $sql = 'SELECT user_dst, user_timezone - FROM ' . USERS_TABLE . ' - GROUP BY user_timezone, user_dst'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' - WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' - AND user_dst = " . (int) $row['user_dst']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - - // Update board default timezone - $sql = 'UPDATE ' . CONFIG_TABLE . " - SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' - WHERE config_name = 'board_timezone'"; - $this->sql_query($sql); - - // After we have calculated the timezones we can delete user_dst column from user table. - $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); - } - - /** - * Determine the new timezone for a given phpBB 3.0 timezone and - * "Daylight Saving Time" option - * - * @param $timezone float Users timezone in 3.0 - * @param $dst int Users daylight saving time - * @return string Users new php Timezone which is used since 3.1 - */ - public function convert_phpbb30_timezone($timezone, $dst) - { - $offset = $timezone + $dst; - - switch ($timezone) - { - case '-12': - return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' - case '-11': - return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' - case '-10': - return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' - case '-9.5': - return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' - case '-9': - return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' - case '-8': - return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' - case '-7': - return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' - case '-6': - return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' - case '-5': - return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' - case '-4.5': - return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' - case '-4': - return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' - case '-3.5': - return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' - case '-3': - return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' - case '-2': - return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' - case '-1': - return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' - case '0': - return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' - case '1': - return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' - case '2': - return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' - case '3': - return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' - case '3.5': - return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' - case '4': - return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' - case '4.5': - return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' - case '5': - return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' - case '5.5': - return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' - case '5.75': - return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' - case '6': - return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' - case '6.5': - return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' - case '7': - return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' - case '8': - return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' - case '8.75': - return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' - case '9': - return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' - case '9.5': - return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' - case '10': - return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' - case '10.5': - return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' - case '11': - return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' - case '11.5': - return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' - case '12': - return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' - case '12.75': - return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' - case '13': - return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' - case '14': - return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' - default: - return 'UTC'; - } - } -} -- cgit v1.2.1 From e9bcea5d82fd086ebcf7634ab386623f34ea8d03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:22:44 -0600 Subject: [feature/migrations] Restore update_helpers.php file This should be removed by the data branch PHPBB3-9737 --- phpBB/includes/update_helpers.php | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 phpBB/includes/update_helpers.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/update_helpers.php b/phpBB/includes/update_helpers.php new file mode 100644 index 0000000000..69d678b2f8 --- /dev/null +++ b/phpBB/includes/update_helpers.php @@ -0,0 +1,112 @@ + Date: Wed, 9 Jan 2013 14:27:01 -0600 Subject: [feature/migrations] Fixing returns of callables and handling data state Lots of comments and some other miscellaneous fixes. PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 1 + phpBB/includes/db/driver/mysqli.php | 1 - phpBB/includes/db/migration/exception.php | 10 ++ phpBB/includes/db/migration/migration.php | 35 ++++- phpBB/includes/db/migration/tool/config.php | 40 +++--- phpBB/includes/db/migration/tool/interface.php | 5 + phpBB/includes/db/migration/tool/module.php | 177 ++++++++++++------------ phpBB/includes/db/migration/tool/permission.php | 106 +++++++------- phpBB/includes/db/migrator.php | 158 ++++++++++++++++----- 9 files changed, 329 insertions(+), 204 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 5329d871c8..1d6823d37a 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -349,6 +349,7 @@ class phpbb_db_tools * Setter for {@link $return_statements return_statements}. * * @param bool $return_statements True if SQL should not be executed but returned as strings + * @return null */ public function set_return_statements($return_statements) { diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php index 94921a22b7..7448bf1670 100644 --- a/phpBB/includes/db/driver/mysqli.php +++ b/phpBB/includes/db/driver/mysqli.php @@ -24,7 +24,6 @@ if (!defined('IN_PHPBB')) class phpbb_db_driver_mysqli extends phpbb_db_driver { var $multi_insert = true; - var $connect_error = ''; /** diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index 19fb39ab23..bd46a4e064 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -22,8 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration_exception extends \Exception { + /** @var array Extra parameters sent to exception to aid in debugging */ protected $parameters; + /** + * Throw an exception. + * + * First argument is the error message. + * Additional arguments will be output with the error message. + */ public function __construct() { $parameters = func_get_args(); @@ -33,6 +40,9 @@ class phpbb_db_migration_exception extends \Exception $this->parameters = $parameters; } + /** + * Output the error as a string + */ public function __toString() { return $this->message . ': ' . var_export($this->parameters, true); diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index c2c6da855b..5f1f0443db 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -26,22 +26,41 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_db_migration { + /** @var phpbb_config */ protected $config; + + /** @var phpbb_db_driver */ protected $db; + + /** @var phpbb_db_tools */ protected $db_tools; + + /** @var string */ protected $table_prefix; + /** @var string */ protected $phpbb_root_path; + + /** @var string */ protected $php_ext; + /** @var array Errors, if any occured */ protected $errors; - private $queries = array(); + /** @var array List of queries executed through $this->sql_query() */ + protected $queries = array(); /** - * Migration constructor + * Constructor + * + * @param phpbb_config $config + * @param phpbb_db_driver $db + * @param phpbb_db_tools $db_tools + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $table_prefix */ - public function __construct($config, phpbb_db_driver $db, $db_tools, $phpbb_root_path, $php_ext, $table_prefix) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $phpbb_root_path, $php_ext, $table_prefix) { $this->config = $config; $this->db = $db; @@ -55,7 +74,7 @@ abstract class phpbb_db_migration } /** - * Defines other migrationsto be applied first (abstract method) + * Defines other migrations to be applied first (abstract method) * * @return array An array of migration class names */ @@ -67,7 +86,7 @@ abstract class phpbb_db_migration /** * Updates the database schema by providing a set of change instructions * - * @return array + * @return array Array of schema changes (compatible with db_tools->perform_schema_changes()) */ public function update_schema() { @@ -77,14 +96,18 @@ abstract class phpbb_db_migration /** * Updates data by returning a list of instructions to be executed * - * @return array + * @return array Array of data update instructions */ public function update_data() { + return array(); } /** * Wrapper for running queries to generate user feedback on updates + * + * @param string $sql SQL query to run on the database + * @return mixed Query result from db->sql_query() */ protected function sql_query($sql) { diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index 35fa3ce566..e7239436d2 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -7,11 +7,21 @@ * */ +/** +* Migration config tool +* +* @package db +*/ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interface { /** @var phpbb_config */ - protected $config = null; + protected $config; + /** + * Constructor + * + * @param phpbb_config $config + */ public function __construct(phpbb_config $config) { $this->config = $config; @@ -26,13 +36,12 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } /** - * Config Add - * - * This function allows you to add a config setting. + * Add a config setting. * * @param string $config_name The name of the config setting you would like to add * @param mixed $config_value The value of the config setting * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * @return null */ public function add($config_name, $config_value = '', $is_dynamic = false) { @@ -42,17 +51,14 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->set($config_name, $config_value, !$is_dynamic); - - return false; } /** - * Config Update - * - * This function allows you to update an existing config setting. + * Update an existing config setting. * * @param string $config_name The name of the config setting you would like to update * @param mixed $config_value The value of the config setting + * @return null */ public function update($config_name, $config_value = '') { @@ -62,18 +68,15 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->set($config_name, $config_value); - - return false; } /** - * Config Update If Equals - * - * This function allows you to update a config setting if the first argument equal to the current config value + * Update a config setting if the first argument equal to the current config value * * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not * @param string $config_name The name of the config setting you would like to update * @param mixed $config_value The value of the config setting + * @return null */ public function update_if_equals($compare, $config_name, $config_value = '') { @@ -83,16 +86,13 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->set_atomic($config_name, $compare, $config_value); - - return false; } /** - * Config Remove - * - * This function allows you to remove an existing config setting. + * Remove an existing config setting. * * @param string $config_name The name of the config setting you would like to remove + * @return null */ public function remove($config_name) { @@ -102,7 +102,5 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->delete($config_name); - - return false; } } diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php index 1815f5e8a2..5d10246ba1 100644 --- a/phpBB/includes/db/migration/tool/interface.php +++ b/phpBB/includes/db/migration/tool/interface.php @@ -7,6 +7,11 @@ * */ +/** +* Migration tool interface +* +* @package db +*/ interface phpbb_db_migration_tool_interface { /** diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index a503f08c01..f1b527bf21 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -7,27 +7,42 @@ * */ +/** +* Migration module management tool +* +* @package db +*/ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interface { /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var dbal */ - protected $db = null; + protected $db; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** @var string */ - protected $modules_table = null; + protected $modules_table; - public function __construct(phpbb_db_driver $db, $cache, $user, $phpbb_root_path, $php_ext, $modules_table) + /** + * Constructor + * + * @param phpbb_db_driver $db + * @param mixed $cache + * @param phpbb_user $user + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $modules_table + */ + public function __construct(phpbb_db_driver $db, phpbb_cache_service $cache, phpbb_user $user, $phpbb_root_path, $php_ext, $modules_table) { $this->db = $db; $this->cache = $cache; @@ -53,7 +68,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * @param string $class The module class(acp|mcp|ucp) * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - * * @return bool true/false if module exists */ public function exists($class, $parent, $module) @@ -64,31 +78,28 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac return true; } - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - $parent_sql = ''; if ($parent !== false) { // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; + $parent = $parent ?: 0; if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; + AND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - if (!$row) + if (!$module_id) { return false; } - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + $parent_sql = 'AND parent_id = ' . (int) $module_id; } else { @@ -98,14 +109,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $sql = 'SELECT module_id FROM ' . $this->modules_table . " - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '" . $this->db->sql_escape($module) . "'"); $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - if ($row) + if ($module_id) { return true; } @@ -123,29 +134,30 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * @param array $data an array of the data on the new module. This can be setup in two different ways. * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @return null */ public function add($class, $parent = 0, $data = array(), $include_path = false) { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; + // Allows '' to be sent as 0 + $parent = $parent ?: 0; // allow sending the name as a string in $data to create a category if (!is_array($data)) @@ -155,18 +167,16 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!isset($data['module_langname'])) { - /** - * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for - * upgrades from a 3.0.x version to 3.1 - */ // The "automatic" way $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; $basename = str_replace(array('/', '\\'), '', $basename); $class = str_replace(array('/', '\\'), '', $class); + + $include_path = ($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path; $info_file = "$class/info/$basename.{$this->php_ext}"; // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + if (!file_exists($include_path . $info_file)) { throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $info_file); } @@ -175,7 +185,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!class_exists($classname)) { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + include($include_path . $info_file); } $info = new $classname; @@ -206,26 +216,25 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } // The "manual" way - add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); + $module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']); + add_log('admin', 'LOG_MODULE_ADD', $module_log_name); if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; + AND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - if (!$row) + if (!$module_id) { throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); } - $parent = $data['parent_id'] = $row['module_id']; + $parent = $data['parent_id'] = $module_id; } else if (!$this->exists($class, false, $parent)) { @@ -270,46 +279,46 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (isset($data['before']) && $data['before']) { $sql = 'SELECT left_id - FROM ' . $this->modules_table . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + FROM ' . $this->modules_table . " + WHERE module_class = '" . $this->db->sql_escape($class) . "' + AND parent_id = " . (int) $parent . " + AND module_langname = '" . $this->db->sql_escape($data['before']) . "'"; $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); + $to_left = (int) $this->db->sql_fetchfield('left_id'); $sql = 'UPDATE ' . $this->modules_table . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND left_id >= $to_left AND left_id < {$module_data['left_id']}"; $this->db->sql_query($sql); $sql = 'UPDATE ' . $this->modules_table . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND module_id = {$module_data['module_id']}"; $this->db->sql_query($sql); } else if (isset($data['after']) && $data['after']) { $sql = 'SELECT right_id - FROM ' . $this->modules_table . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + FROM ' . $this->modules_table . " + WHERE module_class = '" . $this->db->sql_escape($class) . "' + AND parent_id = " . (int) $parent . " + AND module_langname = '" . $this->db->sql_escape($data['after']) . "'"; $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); + $to_right = (int) $this->db->sql_fetchfield('right_id'); $sql = 'UPDATE ' . $this->modules_table . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND left_id >= $to_right AND left_id < {$module_data['left_id']}"; $this->db->sql_query($sql); $sql = 'UPDATE ' . $this->modules_table . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND module_id = {$module_data['module_id']}"; $this->db->sql_query($sql); } @@ -317,8 +326,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac // Clear the Modules Cache $this->cache->destroy("_modules_$class"); - - return false; } /** @@ -330,6 +337,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @return null */ public function remove($class, $parent = 0, $module = '', $include_path = false) { @@ -351,9 +359,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac // Automatic method $basename = str_replace(array('/', '\\'), '', $module['module_basename']); $class = str_replace(array('/', '\\'), '', $class); + + $include_path = ($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path; $info_file = "$class/info/$basename.{$this->php_ext}"; - if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + if (!file_exists($include_path . $info_file)) { throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); } @@ -362,7 +372,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!class_exists($classname)) { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + include($include_path . $info_file); } $info = new $classname; @@ -376,12 +386,9 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $this->remove($class, $parent, $info['title']) . '
'; } } - return false; } else { - $class = $this->db->sql_escape($class); - if (!$this->exists($class, $parent, $module)) { throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); @@ -391,20 +398,20 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if ($parent !== false) { // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; + $parent = ($parent) ?: 0; if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; + AND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + $parent_sql = 'AND parent_id = ' . (int) $module_id; } else { @@ -415,16 +422,15 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $module_ids = array(); if (!is_numeric($module)) { - $module = $this->db->sql_escape($module); $sql = 'SELECT module_id FROM ' . $this->modules_table . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; + WHERE module_langname = '" . $this->db->sql_escape($module) . "' + AND module_class = '" . $this->db->sql_escape($class) . "' + $parent_sql"; $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) + while ($module_id = $this->db->sql_fetchfield('module_id')) { - $module_ids[] = (int) $row['module_id']; + $module_ids[] = (int) $module_id; } $this->db->sql_freeresult($result); @@ -436,13 +442,12 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $sql = 'SELECT module_langname FROM ' . $this->modules_table . " WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; + AND module_class = '" . $this->db->sql_escape($class) . "' + $parent_sql"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_name = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - $module_name = $row['module_langname']; $module_ids[] = $module; } @@ -464,8 +469,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } $this->cache->destroy("_modules_$class"); - - return false; } } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index ebe404bc62..97fdbc0df9 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -7,24 +7,38 @@ * */ +/** +* Migration permission management tool +* +* @package db +*/ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_interface { /** @var phpbb_auth */ - protected $auth = null; + protected $auth; /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var dbal */ - protected $db = null; + protected $db; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; - public function __construct(phpbb_db_driver $db, $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) + /** + * Constructor + * + * @param phpbb_db_driver $db + * @param mixed $cache + * @param phpbb_auth $auth + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(phpbb_db_driver $db, phpbb_cache_service $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) { $this->db = $db; $this->cache = $cache; @@ -48,7 +62,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, False for a local permission setting - * * @return bool true if it exists, false if not */ public function exists($auth_option, $global = true) @@ -86,8 +99,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result + * @return null */ public function add($auth_option, $global = true, $copy_from = false) { @@ -152,7 +164,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } $this->db->sql_freeresult($result); - if (sizeof($sql_ary)) + if (!empty($sql_ary)) { $this->db->sql_multi_insert($table, $sql_ary); } @@ -160,8 +172,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $auth_admin->acl_clear_prefetch(); } - - return false; } /** @@ -171,8 +181,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result + * @return null */ public function remove($auth_option, $global = true) { @@ -197,7 +206,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $id = $row['auth_option_id']; + $id = (int) $row['auth_option_id']; // If it is a local and global permission, do not remove the row! :P if ($row['is_global'] && $row['is_local']) @@ -210,17 +219,17 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte else { // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE, ACL_OPTIONS_TABLE); + foreach ($tables as $table) + { + $this->db->sql_query('DELETE FROM ' . $table . ' + WHERE auth_option_id = ' . $id); + } } // Purge the auth cache $this->cache->destroy('_acl_options'); $this->auth->acl_clear_prefetch(); - - return false; } /** @@ -228,6 +237,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $role_name The new role name * @param sting $role_type The type (u_, m_, a_) + * @return null */ public function role_add($role_name, $role_type = '', $role_description = '') { @@ -235,18 +245,18 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if ($role_id) { throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); } - $sql = 'SELECT MAX(role_order) AS max + $sql = 'SELECT MAX(role_order) AS max_role_order FROM ' . ACL_ROLES_TABLE . " WHERE role_type = '" . $this->db->sql_escape($role_type) . "'"; $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); + $role_order = (int) $this->db->sql_fetchfield('max_role_order'); $role_order = (!$role_order) ? 1 : $role_order + 1; $sql_ary = array( @@ -258,8 +268,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); - - return false; } /** @@ -267,6 +275,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $old_role_name The old role name * @param string $new_role_name The new role name + * @return null */ public function role_update($old_role_name, $new_role_name = '') { @@ -274,7 +283,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { @@ -285,14 +294,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte SET role_name = '" . $this->db->sql_escape($new_role_name) . "' WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; $this->db->sql_query($sql); - - return false; } /** * Remove a permission role * * @param string $role_name The role name to remove + * @return null */ public function role_remove($role_name) { @@ -300,7 +308,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { @@ -316,8 +324,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_query($sql); $this->auth->acl_clear_prefetch(); - - return false; } /** @@ -329,6 +335,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param string|array $auth_option The auth_option or array of auth_options you would like to set * @param string $type The type (role|group) * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + * @return null */ public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) { @@ -344,13 +351,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $new_auth[] = $row['auth_option_id']; + $new_auth[] = (int) $row['auth_option_id']; } $this->db->sql_freeresult($result); - if (!sizeof($new_auth)) + if (empty($new_auth)) { - return false; + return; } $current_auth = array(); @@ -364,7 +371,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { @@ -387,7 +394,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); + $group_id = (int) $this->db->sql_fetchfield('group_id'); if (!$group_id) { @@ -401,7 +408,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte AND auth_role_id <> 0 AND forum_id = 0'; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); + $role_id = (int) $this->db->sql_fetchfield('auth_role_id'); if ($role_id) { $sql = 'SELECT role_name @@ -437,7 +444,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte 'role_id' => $role_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission, - ); + ); } } @@ -453,7 +460,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte 'group_id' => $group_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission, - ); + ); } } @@ -462,8 +469,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } $this->auth->acl_clear_prefetch(); - - return false; } /** @@ -474,6 +479,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param string $name The name of the role/group * @param string|array $auth_option The auth_option or array of auth_options you would like to set * @param string $type The type (role|group) + * @return null */ public function permission_unset($name, $auth_option = array(), $type = 'role') { @@ -489,13 +495,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $to_remove[] = $row['auth_option_id']; + $to_remove[] = (int) $row['auth_option_id']; } $this->db->sql_freeresult($result); - if (!sizeof($to_remove)) + if (empty($to_remove)) { - return false; + return; } $type = (string) $type; // Prevent PHP bug. @@ -507,11 +513,11 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); } $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' @@ -524,7 +530,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); + $group_id = (int) $this->db->sql_fetchfield('group_id'); if (!$group_id) { @@ -537,7 +543,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte WHERE group_id = ' . $group_id . ' AND auth_role_id <> 0'; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); + $role_id = (int) $this->db->sql_fetchfield('auth_role_id'); if ($role_id) { $sql = 'SELECT role_name @@ -556,7 +562,5 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } $this->auth->acl_clear_prefetch(); - - return false; } } diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2fd795b659..2ba1eba427 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,26 +22,40 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { + /** @var phpbb_config */ protected $config; + + /** @var phpbb_db_driver */ protected $db; + + /** @var phpbb_db_tools */ protected $db_tools; + + /** @var string */ protected $table_prefix; + /** @var string */ protected $phpbb_root_path; + + /** @var string */ protected $php_ext; + /** @var string */ protected $migrations_table; + + /** @var array State of all migrations (SELECT * FROM migrations table) */ protected $migration_state; + /** @var array Array of all migrations available to be run */ protected $migrations = array(); - /** @var string Name of the last migration run */ + /** @var array 'name' and 'class' of the last migration run */ public $last_run_migration = false; /** * Constructor of the database migrator */ - public function __construct($config, phpbb_db_driver $db, $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; @@ -96,17 +110,42 @@ class phpbb_db_migrator /** * Load migration data files from a directory * - * @param string $path + * This does not loop through sub-directories. + * Migration data files loaded with this function MUST contain + * ONLY ONE class in them (or an exception will be thrown). + * + * @param string $path Path to migration data files + * @param bool $check_fulfillable If TRUE (default), we will check + * if all of the migrations are fulfillable after loading them. + * If FALSE, we will not check. You SHOULD check at least once + * to prevent errors (if including multiple directories, check + * with the last call to prevent throwing errors unnecessarily). * @return array Array of migrations with names */ - public function load_migrations($path) + public function load_migrations($path, $check_fulfillable = true) { $handle = opendir($path); while (($file = readdir($handle)) !== false) { if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) { - $name = 'phpbb_db_migration_data_' . substr($file, 0, -(strlen($this->php_ext) + 1)); + // We try to find what class existed by comparing the classes declared before and after including the file. + $declared_classes = get_declared_classes(); + + include ($path . $file); + + $added_classes = array_diff(get_declared_classes(), $declared_classes); + + if ( + // The phpbb_db_migrations class may not have been loaded until now, so make sure to ignore it. + !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && + sizeof($added_classes) != 1 + ) + { + throw new phpbb_db_migration_exception('MIGRATION DATA FILE INVALID', $path . $file); + } + + $name = array_pop($added_classes); if (!in_array($name, $this->migrations)) { @@ -115,11 +154,14 @@ class phpbb_db_migrator } } - foreach ($this->migrations as $name) + if ($check_fulfillable) { - if ($this->unfulfillable($name)) + foreach ($this->migrations as $name) { - throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + if ($this->unfulfillable($name)) + { + throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + } } } @@ -131,6 +173,8 @@ class phpbb_db_migrator * * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. + * + * @return null */ public function update() { @@ -207,9 +251,11 @@ class phpbb_db_migrator } else { - $this->process_data_step($migration); - $state['migration_data_done'] = true; - $state['migration_end_time'] = time(); + $state = $this->process_data_step($migration); + + $state['migration_data_state'] = $state; + $state['migration_data_done'] = ($state === true); + $state['migration_end_time'] = ($state === true) ? time() : 0; } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -222,41 +268,74 @@ class phpbb_db_migrator return true; } + /** + * Apply schema changes from a migration + * + * Just calls db_tools->perform_schema_changes + * + * @param array $schema_changes from migration + */ + protected function apply_schema_changes($schema_changes) + { + $this->db_tools->perform_schema_changes($schema_changes); + } + + /** + * Process the data step of the migration + * + * @param phpbb_db_migration $migration + * @return mixed migration status or bool true if everything completed successfully + */ protected function process_data_step($migration) { - //$continue = false; $steps = $migration->update_data(); foreach ($steps as $step) { - $continue = $this->run_step($step); - - /*if ($continue === false) + try { - return false; - }*/ + // Result will be null or true if everything completed correctly + $result = $this->run_step($step); + if ($result !== null && $result !== true) + { + return $result; + } + } + catch (phpbb_db_migration_exception $e) + { + // We should try rolling back here + + echo $e; + die(); + } } - //return $continue; + return true; } + /** + * Run a single step + * + * An exception should be thrown if an error occurs + * + * @param mixed $step + * @return null + */ protected function run_step($step) { - try - { - $callable_and_parameters = $this->get_callable_from_step($step); - $callable = $callable_and_parameters[0]; - $parameters = $callable_and_parameters[1]; + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $parameters = $callable_and_parameters[1]; - return call_user_func_array($callable, $parameters); - } - catch (phpbb_db_migration_exception $e) - { - echo $e; - die(); - } + return call_user_func_array($callable, $parameters); } + /** + * Get a callable statement from a data step + * + * @param mixed $step Data step from migration + * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters + */ public function get_callable_from_step($step) { $type = $step[0]; @@ -291,6 +370,7 @@ class phpbb_db_migrator $callable_and_parameters = $this->get_callable_from_step($step); $callable = $callable_and_parameters[0]; $sub_parameters = $callable_and_parameters[1]; + return array( function ($condition) use ($callable, $sub_parameters) { return call_user_func_array($callable, $sub_parameters); @@ -325,12 +405,19 @@ class phpbb_db_migrator return array( array($this->tools[$class], $method), - $parameters + $parameters, ); break; } } + /** + * Insert migration row into the database + * + * @param string $name Name of the migration + * @param array $state + * @return null + */ protected function insert_migration($name, $state) { $migration_row = $state; @@ -346,8 +433,8 @@ class phpbb_db_migrator /** * Checks if a migration's dependencies can even theoretically be satisfied. * - * @param string $name The class name of the migration - * @return bool Whether the migration cannot be fulfilled + * @param string $name The class name of the migration + * @return bool Whether the migration cannot be fulfilled */ public function unfulfillable($name) { @@ -406,11 +493,6 @@ class phpbb_db_migrator return true; } - protected function apply_schema_changes($schema_changes) - { - $this->db_tools->perform_schema_changes($schema_changes); - } - /** * Helper to get a migration * -- cgit v1.2.1 From edf693e3bd4352ab75c62311b34f12fc98e7ef63 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 15:28:08 -0600 Subject: [feature/migrations] Store state properly and send past result to callable Fix return on module add PHPBB3-9737 --- phpBB/includes/db/migration/tool/module.php | 4 +-- phpBB/includes/db/migrator.php | 56 +++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index f1b527bf21..70a246849a 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -208,11 +208,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac ); // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); + $this->add($class, $parent, $new_module); } } - return $result; + return; } // The "manual" way diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2ba1eba427..7aa4cfa719 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -251,11 +251,11 @@ class phpbb_db_migrator } else { - $state = $this->process_data_step($migration); + $result = $this->process_data_step($migration, $state['migration_data_state']); - $state['migration_data_state'] = $state; - $state['migration_data_done'] = ($state === true); - $state['migration_end_time'] = ($state === true) ? time() : 0; + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -284,27 +284,50 @@ class phpbb_db_migrator * Process the data step of the migration * * @param phpbb_db_migration $migration - * @return mixed migration status or bool true if everything completed successfully + * @param bool|string $state Current state of the migration + * @return bool|string migration state. True if completed, serialized array if not finished */ - protected function process_data_step($migration) + protected function process_data_step($migration, $state) { + $state = ($state) ? unserialize($state) : false; + $steps = $migration->update_data(); foreach ($steps as $step) { + $last_result = false; + if ($state) + { + // Continue until we reach the step that matches the last step called + if ($state['step'] != $step) + { + continue; + } + + // We send the result from last time to the callable function + $last_result = $state['result']; + + // Set state to false since we reached the point we were at + $state = false; + } + try { // Result will be null or true if everything completed correctly - $result = $this->run_step($step); + $result = $this->run_step($step, $last_result); if ($result !== null && $result !== true) { - return $result; + return serialize(array( + 'result' => $result, + 'step' => $step, + )); } } catch (phpbb_db_migration_exception $e) { // We should try rolling back here + var_dump($step); echo $e; die(); } @@ -318,12 +341,13 @@ class phpbb_db_migrator * * An exception should be thrown if an error occurs * - * @param mixed $step + * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return null */ - protected function run_step($step) + protected function run_step($step, $last_result = false) { - $callable_and_parameters = $this->get_callable_from_step($step); + $callable_and_parameters = $this->get_callable_from_step($step, $last_result); $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; @@ -334,9 +358,10 @@ class phpbb_db_migrator * Get a callable statement from a data step * * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - public function get_callable_from_step($step) + public function get_callable_from_step($step, $last_result = false) { $type = $step[0]; $parameters = $step[1]; @@ -375,7 +400,7 @@ class phpbb_db_migrator function ($condition) use ($callable, $sub_parameters) { return call_user_func_array($callable, $sub_parameters); }, - array($condition) + array($condition), ); break; case 'custom': @@ -384,7 +409,10 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); } - return array($parameters[0], array()); + return array( + $parameters[0], + array($last_result), + ); break; default: -- cgit v1.2.1 From f56e400cd36b6d17ffde90a91e6e221cb83d2dbd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 15:41:04 -0600 Subject: [feature/migrations] Comments PHPBB3-9737 --- phpBB/includes/db/migration/tool/permission.php | 12 +++++------ phpBB/includes/db/migrator.php | 28 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 97fdbc0df9..7b45b24361 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -366,7 +366,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte switch ($type) { - case 'role' : + case 'role': $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; @@ -389,7 +389,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_freeresult($result); break; - case 'group' : + case 'group': $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; @@ -435,7 +435,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $sql_ary = array(); switch ($type) { - case 'role' : + case 'role': foreach ($new_auth as $auth_option_id) { if (!isset($current_auth[$auth_option_id])) @@ -451,7 +451,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); break; - case 'group' : + case 'group': foreach ($new_auth as $auth_option_id) { if (!isset($current_auth[$auth_option_id])) @@ -508,7 +508,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte switch ($type) { - case 'role' : + case 'role': $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; @@ -525,7 +525,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_query($sql); break; - case 'group' : + case 'group': $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 7aa4cfa719..5d8dc12f58 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -43,13 +43,27 @@ class phpbb_db_migrator /** @var string */ protected $migrations_table; - /** @var array State of all migrations (SELECT * FROM migrations table) */ - protected $migration_state; + /** + * State of all migrations + * + * (SELECT * FROM migrations table) + * + * @var array + */ + protected $migration_state = array(); - /** @var array Array of all migrations available to be run */ + /** + * Array of all migrations available to be run + * + * @var array + */ protected $migrations = array(); - /** @var array 'name' and 'class' of the last migration run */ + /** + * 'name' and 'class' of the last migration run + * + * @var array + */ public $last_run_migration = false; /** @@ -83,11 +97,12 @@ class phpbb_db_migrator */ public function load_migration_state() { + $this->migration_state = array(); + $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); - $this->migration_state = array(); while ($migration = $this->db->sql_fetchrow($result)) { $this->migration_state[$migration['migration_name']] = $migration; @@ -137,8 +152,9 @@ class phpbb_db_migrator $added_classes = array_diff(get_declared_classes(), $declared_classes); if ( - // The phpbb_db_migrations class may not have been loaded until now, so make sure to ignore it. + // If two classes have been added and phpbb_db_migration is one of them, we've only added one real migration !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && + // Otherwise there should only be one class added sizeof($added_classes) != 1 ) { -- cgit v1.2.1 From 445667a62e80c42b5406c981d1116ef99a23df3b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:31:56 -0600 Subject: [feature/migrations] Fix if method (and create a test for it) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 5d8dc12f58..1042b767e8 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -364,6 +364,12 @@ class phpbb_db_migrator protected function run_step($step, $last_result = false) { $callable_and_parameters = $this->get_callable_from_step($step, $last_result); + + if ($callable_and_parameters === false) + { + return; + } + $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; @@ -377,7 +383,7 @@ class phpbb_db_migrator * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - public function get_callable_from_step($step, $last_result = false) + protected function get_callable_from_step($step, $last_result = false) { $type = $step[0]; $parameters = $step[1]; @@ -406,6 +412,12 @@ class phpbb_db_migrator } $condition = $parameters[0]; + + if (!$condition) + { + return false; + } + $step = $parameters[1]; $callable_and_parameters = $this->get_callable_from_step($step); @@ -413,10 +425,8 @@ class phpbb_db_migrator $sub_parameters = $callable_and_parameters[1]; return array( - function ($condition) use ($callable, $sub_parameters) { - return call_user_func_array($callable, $sub_parameters); - }, - array($condition), + $callable, + $sub_parameters, ); break; case 'custom': -- cgit v1.2.1 From 5f9e1f1e89f8df5420fd82b5256a461de0f98604 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:56:26 -0600 Subject: [feature/migrations] Make sure the path sent to load_migrations is a directory Prevent a lot++ of errors PHPBB3-9737 --- phpBB/includes/db/migrator.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 1042b767e8..359c34bf5d 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -139,6 +139,11 @@ class phpbb_db_migrator */ public function load_migrations($path, $check_fulfillable = true) { + if (!is_dir($path)) + { + throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); + } + $handle = opendir($path); while (($file = readdir($handle)) !== false) { -- cgit v1.2.1 From 3d4c00619f1c96df7a4c6f8bc1c03eb21abf49d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:24:32 -0600 Subject: [feature/migrations] Reverse data functionality If data step fails, attempt to roll back any previous calls from the migration that failed. Fix some failing tests PHPBB3-9737 --- phpBB/includes/db/migration/tool/config.php | 42 +++++++++++++++++++ phpBB/includes/db/migration/tool/interface.php | 10 +++++ phpBB/includes/db/migration/tool/module.php | 31 ++++++++++++++ phpBB/includes/db/migration/tool/permission.php | 55 +++++++++++++++++++++++++ phpBB/includes/db/migrator.php | 37 ++++++++++++----- 5 files changed, 164 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index e7239436d2..6ae419d5e7 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -103,4 +103,46 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac $this->config->delete($config_name); } + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse() + { + $arguments = func_get_args(); + $original_call = array_shift($arguments); + + $call = false; + switch ($original_call) + { + case 'add': + $call = 'remove'; + break; + + case 'remove': + $call = 'add'; + break; + + case 'update_if_equals': + $call = 'update_if_equals'; + + // Set to the original value if the current value is what we compared to originally + $arguments = array( + $arguments[2], + $arguments[1], + $arguments[0], + ); + break; + } + + if ($call) + { + return call_user_func_array(array(&$this, $call), $arguments); + } + } } diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php index 5d10246ba1..ced53b2023 100644 --- a/phpBB/includes/db/migration/tool/interface.php +++ b/phpBB/includes/db/migration/tool/interface.php @@ -20,4 +20,14 @@ interface phpbb_db_migration_tool_interface * @return string short name */ public function get_name(); + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse(); } diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 70a246849a..561faac552 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -471,4 +471,35 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $this->cache->destroy("_modules_$class"); } } + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse() + { + $arguments = func_get_args(); + $original_call = array_shift($arguments); + + $call = false; + switch ($original_call) + { + case 'add': + $call = 'remove'; + break; + + case 'remove': + $call = 'add'; + break; + } + + if ($call) + { + return call_user_func_array(array(&$this, $call), $arguments); + } + } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 7b45b24361..a25fdb345e 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -563,4 +563,59 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->auth->acl_clear_prefetch(); } + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse() + { + $arguments = func_get_args(); + $original_call = array_shift($arguments); + + $call = false; + switch ($original_call) + { + case 'add': + $call = 'remove'; + break; + + case 'remove': + $call = 'add'; + break; + + case 'permission_set': + $call = 'permission_unset'; + break; + + case 'permission_unset': + $call = 'permission_set'; + break; + + case 'role_add': + $call = 'role_remove'; + break; + + case 'role_remove': + $call = 'role_add'; + break; + + case 'role_update': + // Set to the original value if the current value is what we compared to originally + $arguments = array( + $arguments[1], + $arguments[0], + ); + break; + } + + if ($call) + { + return call_user_func_array(array(&$this, $call), $arguments); + } + } } diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 359c34bf5d..dc2c746559 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -347,6 +347,17 @@ class phpbb_db_migrator catch (phpbb_db_migration_exception $e) { // We should try rolling back here + foreach ($steps as $reverse_step) + { + // Reverse the step that was run + $result = $this->run_step($step, false, true); + + // If we've reached the current step we can break because we reversed everything that was run + if ($reverse_step === $step) + { + break; + } + } var_dump($step); echo $e; @@ -364,11 +375,12 @@ class phpbb_db_migrator * * @param mixed $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return null */ - protected function run_step($step, $last_result = false) + protected function run_step($step, $last_result = false, $reverse = false) { - $callable_and_parameters = $this->get_callable_from_step($step, $last_result); + $callable_and_parameters = $this->get_callable_from_step($step, $last_result, $reverse); if ($callable_and_parameters === false) { @@ -386,9 +398,10 @@ class phpbb_db_migrator * * @param mixed $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - protected function get_callable_from_step($step, $last_result = false) + protected function get_callable_from_step($step, $last_result = false, $reverse = false) { $type = $step[0]; $parameters = $step[1]; @@ -425,14 +438,7 @@ class phpbb_db_migrator $step = $parameters[1]; - $callable_and_parameters = $this->get_callable_from_step($step); - $callable = $callable_and_parameters[0]; - $sub_parameters = $callable_and_parameters[1]; - - return array( - $callable, - $sub_parameters, - ); + return $this->get_callable_from_step($step); break; case 'custom': if (!is_callable($parameters[0])) @@ -462,6 +468,15 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); } + // Attempt to reverse operations + if ($reverse) + { + return array( + array($this->tools[$class], 'reverse'), + array_unshift($parameters, $method), + ); + } + return array( array($this->tools[$class], $method), $parameters, -- cgit v1.2.1 From 595246f9bf17f1bef69c285ba8e78534cd91054a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:55:55 -0600 Subject: [feature/migrations] Some comments in db_tools PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 1d6823d37a..b13d4fe978 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -685,6 +685,8 @@ class phpbb_db_tools * Handle passed database update array. * Expected structure... * Key being one of the following + * drop_tables: Drop tables + * add_tables: Add tables * change_columns: Column changes (only type, not name) * add_columns: Add columns to a table * drop_keys: Dropping keys -- cgit v1.2.1 From 44c10f661ee548ae08fe81ba76f47f1c8134b96f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:59:15 -0600 Subject: [feature/migrations] Creating revert method to attempt reverting a migration This code is in progress PHPBB3-9737 --- phpBB/includes/db/migration/migration.php | 23 +++++++ phpBB/includes/db/migrator.php | 100 ++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index 5f1f0443db..61fbf04320 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -93,6 +93,16 @@ abstract class phpbb_db_migration return array(); } + /** + * Reverts the database schema by providing a set of change instructions + * + * @return array Array of schema changes (compatible with db_tools->perform_schema_changes()) + */ + public function revert_schema() + { + return array(); + } + /** * Updates data by returning a list of instructions to be executed * @@ -103,6 +113,19 @@ abstract class phpbb_db_migration return array(); } + /** + * Reverts data by returning a list of instructions to be executed + * + * @return array Array of data instructions that will be performed on revert + * NOTE: calls to tools (such as config.add) are automatically reverted when + * possible, so you should not attempt to revert those, this is mostly for + * otherwise unrevertable calls (custom functions for example) + */ + public function revert_data() + { + return array(); + } + /** * Wrapper for running queries to generate user feedback on updates * diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index dc2c746559..e8d3735974 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -289,6 +289,91 @@ class phpbb_db_migrator return true; } + /** + * Runs a single revert step from the last migration installed + * + * The revert step can either be a schema or a (partial) data revert. To + * check if revert() needs to be called again use the migration_installed() method. + * + * @param string $migration String migration name to revert (including any that depend on this migration) + * @return null + */ + public function revert($migration) + { + if (!isset($this->migration_state[$name])) + { + // Not installed + return; + } + + // Iterate through all installed migrations and make sure any dependencies are removed first + foreach ($this->migration_state as $name => $state) + { + $migration_class = $this->get_migration($name); + + if (in_array($migration, $migration_class->depends_on())) + { + $this->revert($name); + } + } + + $this->try_revert($migration); + } + + /** + * Attempts to apply a step of the given migration or one of its dependencies + * + * @param string The class name of the migration + * @return bool Whether any update step was successfully run + */ + protected function try_revert($name) + { + if (!class_exists($name)) + { + return false; + } + + $migration = $this->get_migration($name); + + $state = $this->migration_state[$name]; + + $this->last_run_migration = array( + 'name' => $name, + 'class' => $migration, + ); + + // Left off here + + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } + + if (!$state['migration_schema_done']) + { + $this->apply_schema_changes($migration->update_schema()); + $state['migration_schema_done'] = true; + } + else + { + $result = $this->process_data_step($migration, $state['migration_data_state']); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + + return true; + } + /** * Apply schema changes from a migration * @@ -359,6 +444,7 @@ class phpbb_db_migrator } } + /** TODO Revert Schema **/ var_dump($step); echo $e; die(); @@ -567,6 +653,20 @@ class phpbb_db_migrator return true; } + /** + * Checks whether a migration is installed + * + * @param string $migration String migration name to check if it is installed + * @return bool Whether the migrations have been applied + */ + public function migration_installed($migration) + { + if (isset($this->migration_state[$migration])) + { + return true; + } + } + /** * Helper to get a migration * -- cgit v1.2.1 From dbe71bb170dc684311174bb025696c81f1d50883 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 13:53:09 -0600 Subject: [feature/migrations] Revert method completed PHPBB3-9737 --- phpBB/includes/db/migrator.php | 74 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index e8d3735974..13114e7df1 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -272,7 +272,7 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration, $state['migration_data_state']); + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); $state['migration_data_state'] = ($result === true) ? '' : $result; $state['migration_data_done'] = ($result === true); @@ -300,7 +300,7 @@ class phpbb_db_migrator */ public function revert($migration) { - if (!isset($this->migration_state[$name])) + if (!isset($this->migration_state[$migration])) { // Not installed return; @@ -342,34 +342,39 @@ class phpbb_db_migrator 'class' => $migration, ); - // Left off here - - if (!isset($this->migration_state[$name])) + if ($state['migration_data_done']) { - $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); - } + if ($state['migration_data_state'] !== 'revert_data') + { + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state'], true); - if (!$state['migration_schema_done']) - { - $this->apply_schema_changes($migration->update_schema()); - $state['migration_schema_done'] = true; + $state['migration_data_state'] = ($result === true) ? 'revert_data' : $result; + } + else + { + $result = $this->process_data_step($migration->revert_data(), $state['migration_data_state'], false); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true) ? false : true; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; } else { - $result = $this->process_data_step($migration, $state['migration_data_state']); - - $state['migration_data_state'] = ($result === true) ? '' : $result; - $state['migration_data_done'] = ($result === true); - $state['migration_end_time'] = ($result === true) ? time() : 0; - } + $this->apply_schema_changes($migration->revert_schema()); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); + $sql = 'DELETE FROM ' . $this->migrations_table . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); - $this->migration_state[$name] = $state; + unset($this->migration_state[$name]); + } return true; } @@ -389,23 +394,22 @@ class phpbb_db_migrator /** * Process the data step of the migration * - * @param phpbb_db_migration $migration + * @param array $steps The steps to run * @param bool|string $state Current state of the migration + * @param bool $revert true to revert a data step * @return bool|string migration state. True if completed, serialized array if not finished */ - protected function process_data_step($migration, $state) + protected function process_data_step($steps, $state, $revert = false) { $state = ($state) ? unserialize($state) : false; - $steps = $migration->update_data(); - - foreach ($steps as $step) + foreach ($steps as $step_identifier => $step) { $last_result = false; if ($state) { // Continue until we reach the step that matches the last step called - if ($state['step'] != $step) + if ($state['step'] != $step_identifier) { continue; } @@ -420,12 +424,12 @@ class phpbb_db_migrator try { // Result will be null or true if everything completed correctly - $result = $this->run_step($step, $last_result); + $result = $this->run_step($step, $last_result, $revert); if ($result !== null && $result !== true) { return serialize(array( 'result' => $result, - 'step' => $step, + 'step' => $step_identifier, )); } } @@ -435,7 +439,7 @@ class phpbb_db_migrator foreach ($steps as $reverse_step) { // Reverse the step that was run - $result = $this->run_step($step, false, true); + $result = $this->run_step($step, false, !$revert); // If we've reached the current step we can break because we reversed everything that was run if ($reverse_step === $step) @@ -557,9 +561,11 @@ class phpbb_db_migrator // Attempt to reverse operations if ($reverse) { + array_unshift($parameters, $method); + return array( array($this->tools[$class], 'reverse'), - array_unshift($parameters, $method), + $parameters, ); } @@ -665,6 +671,8 @@ class phpbb_db_migrator { return true; } + + return false; } /** -- cgit v1.2.1 From d50500860fe44a78c8f29e0f2382b96da17c0b62 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:09:51 -0600 Subject: [feature/migrations] Store depends on in the database (serialized) This is required so that when migrations are reverted we can check through all installed migrations and make sure that all dependencies are handled properly and so that we are only required to load the migrations files that could be dependent on the ones installed. I believe in normal proper use the old way might have worked, but in case something happens and an unrelated migration file is installed, but cannot be loaded, this makes sure we do not stop everything unless we absolutely must (one of those files is dependent on something we want to revert). PHPBB3-9737 --- phpBB/includes/db/migrator.php | 79 ++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 33 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 13114e7df1..2ec44a5a45 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -106,6 +106,8 @@ class phpbb_db_migrator while ($migration = $this->db->sql_fetchrow($result)) { $this->migration_state[$migration['migration_name']] = $migration; + + $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); } $this->db->sql_freeresult($result); @@ -235,16 +237,15 @@ class phpbb_db_migrator $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( + 'migration_depends_on' => $migration->depends_on(), 'migration_schema_done' => false, - 'migration_data_done' => false, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, + 'migration_data_done' => false, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, ); - $depends = $migration->depends_on(); - - foreach ($depends as $depend) + foreach ($state['migration_depends_on'] as $depend) { if (!isset($this->migration_state[$depend]) || !$this->migration_state[$depend]['migration_schema_done'] || @@ -272,15 +273,28 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + try + { + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; + } + catch (phpbb_db_migration_exception $e) + { + // Revert the schema changes + $this->revert($name); - $state['migration_data_state'] = ($result === true) ? '' : $result; - $state['migration_data_done'] = ($result === true); - $state['migration_end_time'] = ($result === true) ? time() : 0; + // Rethrow exception + throw $e; + } } + $insert = $state; + $insert['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " + SET ' . $this->db->sql_build_array('UPDATE', $insert) . " WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); @@ -292,8 +306,9 @@ class phpbb_db_migrator /** * Runs a single revert step from the last migration installed * + * YOU MUST ADD/SET ALL MIGRATIONS THAT COULD BE DEPENDENT ON THE MIGRATION TO REVERT TO BEFORE CALLING THIS METHOD! * The revert step can either be a schema or a (partial) data revert. To - * check if revert() needs to be called again use the migration_installed() method. + * check if revert() needs to be called again use the migration_state() method. * * @param string $migration String migration name to revert (including any that depend on this migration) * @return null @@ -306,12 +321,9 @@ class phpbb_db_migrator return; } - // Iterate through all installed migrations and make sure any dependencies are removed first foreach ($this->migration_state as $name => $state) { - $migration_class = $this->get_migration($name); - - if (in_array($migration, $migration_class->depends_on())) + if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on'])) { $this->revert($name); } @@ -358,8 +370,10 @@ class phpbb_db_migrator $state['migration_data_done'] = ($result === true) ? false : true; } + $insert = $state; + $insert['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " + SET ' . $this->db->sql_build_array('UPDATE', $insert) . " WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); @@ -436,22 +450,20 @@ class phpbb_db_migrator catch (phpbb_db_migration_exception $e) { // We should try rolling back here - foreach ($steps as $reverse_step) + foreach ($steps as $reverse_step_identifier => $reverse_step) { - // Reverse the step that was run - $result = $this->run_step($step, false, !$revert); - // If we've reached the current step we can break because we reversed everything that was run - if ($reverse_step === $step) + if ($reverse_step_identifier == $step_identifier) { break; } + + // Reverse the step that was run + $result = $this->run_step($reverse_step, false, !$revert); } - /** TODO Revert Schema **/ - var_dump($step); - echo $e; - die(); + // rethrow the exception + throw $e; } } @@ -588,6 +600,7 @@ class phpbb_db_migrator { $migration_row = $state; $migration_row['migration_name'] = $name; + $migration_row['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'INSERT INTO ' . $this->migrations_table . ' ' . $this->db->sql_build_array('INSERT', $migration_row); @@ -660,19 +673,19 @@ class phpbb_db_migrator } /** - * Checks whether a migration is installed + * Gets a migration state (whether it is installed and to what extent) * * @param string $migration String migration name to check if it is installed - * @return bool Whether the migrations have been applied + * @return bool|array False if the migration has not at all been installed, array */ - public function migration_installed($migration) + public function migration_state($migration) { - if (isset($this->migration_state[$migration])) + if (!isset($this->migration_state[$migration])) { - return true; + return false; } - return false; + return $this->migration_state[$migration]; } /** -- cgit v1.2.1 From db4fcab3bb4aefcabe93dd4acd1f12e8517cf340 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:29:49 -0600 Subject: [feature/migrations] Make depends_on static to call it without dependencies PHPBB3-11318 --- phpBB/includes/db/migration/migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index 61fbf04320..4271751362 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -78,7 +78,7 @@ abstract class phpbb_db_migration * * @return array An array of migration class names */ - public function depends_on() + static public function depends_on() { return array(); } -- cgit v1.2.1 From 9affd6f7e7b95442f1ef14894858d8213f3fbd2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 11 Jan 2013 00:41:03 +0100 Subject: [ticket/11201] Remove MSN/WLM fields WLM will be shutdown in March 2013. Skype is the new replacement. But as Skype uses a different login ID and service, the values in this field are useless. So we can safely remove the field and the links/functions we create. PHPBB3-11201 --- phpBB/includes/acp/acp_users.php | 4 ---- phpBB/includes/ucp/ucp_pm_viewmessage.php | 1 - phpBB/includes/ucp/ucp_profile.php | 4 ---- 3 files changed, 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 82d8ef5cbb..2bdbf1441a 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1352,7 +1352,6 @@ class acp_users $data = array( 'icq' => request_var('icq', $user_row['user_icq']), 'aim' => request_var('aim', $user_row['user_aim']), - 'msn' => request_var('msn', $user_row['user_msnm']), 'yim' => request_var('yim', $user_row['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)), 'website' => request_var('website', $user_row['user_website']), @@ -1382,7 +1381,6 @@ class acp_users array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), - 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -1416,7 +1414,6 @@ class acp_users $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], - 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -1469,7 +1466,6 @@ class acp_users 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], - 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index c85b05f144..a1001cfa74 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -241,7 +241,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'U_ICQ' => ($user_info['user_icq']) ? 'http://www.icq.com/people/' . urlencode($user_info['user_icq']) . '/' : '', 'U_AIM' => ($user_info['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $author_id) : '', 'U_YIM' => ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '', - 'U_MSN' => ($user_info['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $author_id) : '', 'U_JABBER' => ($user_info['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $author_id) : '', 'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '', diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index e7cea06a45..c1ad9955b6 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -266,7 +266,6 @@ class ucp_profile $data = array( 'icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), - 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), @@ -299,7 +298,6 @@ class ucp_profile array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), - 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -351,7 +349,6 @@ class ucp_profile $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], - 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -423,7 +420,6 @@ class ucp_profile 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], - 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], -- cgit v1.2.1 From 93f9ebbb258a06e34198cffda0f5fd8dfdf29597 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 12 Jan 2013 18:27:33 -0600 Subject: [feature/migrations] Make load_migrations recursive (optionally) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2ec44a5a45..6b249e3ee0 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -127,7 +127,6 @@ class phpbb_db_migrator /** * Load migration data files from a directory * - * This does not loop through sub-directories. * Migration data files loaded with this function MUST contain * ONLY ONE class in them (or an exception will be thrown). * @@ -137,9 +136,10 @@ class phpbb_db_migrator * If FALSE, we will not check. You SHOULD check at least once * to prevent errors (if including multiple directories, check * with the last call to prevent throwing errors unnecessarily). - * @return array Array of migrations with names + * @param bool $recursive Set to true to also load data files from subdirectories + * @return array Array of migration names */ - public function load_migrations($path, $check_fulfillable = true) + public function load_migrations($path, $check_fulfillable = true, $recursive = true) { if (!is_dir($path)) { @@ -149,6 +149,17 @@ class phpbb_db_migrator $handle = opendir($path); while (($file = readdir($handle)) !== false) { + if ($file == '.' || $file == '..') + { + continue; + } + + // Recursion through subdirectories + if (is_dir($path . $file) && $recursive) + { + $this->load_migrations($path . $file . '/', $check_fulfillable, $recursive); + } + if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) { // We try to find what class existed by comparing the classes declared before and after including the file. -- cgit v1.2.1 From 26c16559c3496f5496ad6e83e55c40f03edda5bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 12:39:08 -0600 Subject: [feature/migrations] Function effectively_installed() in migrations Allows you to check if the migration is effectively installed (entirely optionall) This function is intended to help moving to migrations from a previous database updater, where some migrations may have been installed already even though they are not yet listed in the migrations table. PHPBB3-9737 --- phpBB/includes/db/migration/migration.php | 15 +++++++++++++++ phpBB/includes/db/migrator.php | 20 +++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index 4271751362..cf1e97b3b1 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -83,6 +83,21 @@ abstract class phpbb_db_migration return array(); } + /** + * Allows you to check if the migration is effectively installed (entirely optionall) + * + * This is checked when a migration is installed. If true is returned, the migration will be set as + * installed without performing the database changes. + * This function is intended to help moving to migrations from a previous database updater, where some + * migrations may have been installed already even though they are not yet listed in the migrations table. + * + * @return bool True if this migration is installed, False if this migration is not installed (checked on install) + */ + public function effectively_installed() + { + return false; + } + /** * Updates the database schema by providing a set of change instructions * diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 6b249e3ee0..b56da95b1a 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -271,10 +271,24 @@ class phpbb_db_migrator 'class' => $migration, ); - if (!isset($this->migration_state[$name])) + if ($migration->effectively_installed()) { - $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); + $state = array( + 'migration_depends_on' => $migration->depends_on(), + 'migration_schema_done' => true, + 'migration_data_done' => true, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, + ); + } + else + { + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } } if (!$state['migration_schema_done']) -- cgit v1.2.1 From 000b8fefd2788c7f9f6aa6efc1d93658a00e48bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:21:01 -0600 Subject: [feature/migrations] Function to populate the migrations table (for install) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index b56da95b1a..69a5a4dd9c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -124,6 +124,42 @@ class phpbb_db_migrator $this->migrations = $class_names; } + /** + * This function adds all migrations in a specified directory to the migrations table + * + * THIS SHOULD NOT GENERALLY BE USED! THIS IS FOR THE PHPBB INSTALLER. + * THIS WILL THROW ERRORS IF MIGRATIONS ALREADY EXIST IN THE TABLE, DO NOT CALL MORE THAN ONCE! + * + * @param string $path Path to migration data files + * @param bool $recursive Set to true to also load data files from subdirectories + * @return null + */ + public function populate_migrations_from_directory($path, $recursive = true) + { + $existing_migrations = $this->migrations; + + $this->migrations = array(); + $this->load_migrations($path, true, $recursive); + + foreach ($this->migrations as $name) + { + if ($this->migration_state($name) === false) + { + $state = array( + 'migration_depends_on' => $name::depends_on(), + 'migration_schema_done' => true, + 'migration_data_done' => true, + 'migration_data_state' => '', + 'migration_start_time' => time(), + 'migration_end_time' => time(), + ); + $this->insert_migration($name, $state); + } + } + + $this->migrations = $existing_migrations; + } + /** * Load migration data files from a directory * -- cgit v1.2.1 From ccd08e21f6ae97ff0ff628ff29935a70bdd7a58d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:34:16 -0600 Subject: [feature/migrations] Make sure migration data not done before running data step PHPBB3-9737 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 69a5a4dd9c..d95283ae01 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -332,7 +332,7 @@ class phpbb_db_migrator $this->apply_schema_changes($migration->update_schema()); $state['migration_schema_done'] = true; } - else + else if (!$state['migration_data_done']) { try { -- cgit v1.2.1 From 3122aeff263b5fee51440ff49274897ccb6ea46f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:32:15 +0100 Subject: [ticket/9492] Retain custom ranks and avatars when setting users default group PHPBB3-9492 --- phpBB/includes/functions_user.php | 83 +++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 30 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6abcdee8f2..22272b20f3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3208,8 +3208,8 @@ function remove_default_avatar($group_id, $user_ids) user_avatar_width = 0, user_avatar_height = 0 WHERE group_id = " . (int) $group_id . " - AND user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' - AND " . $db->sql_in_set('user_id', $user_ids); + AND user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' + AND " . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); } @@ -3246,9 +3246,9 @@ function remove_default_rank($group_id, $user_ids) $sql = 'UPDATE ' . USERS_TABLE . ' SET user_rank = 0 WHERE group_id = ' . (int)$group_id . ' - AND user_rank <> 0 - AND user_rank = ' . (int)$row['group_rank'] . ' - AND ' . $db->sql_in_set('user_id', $user_ids); + AND user_rank <> 0 + AND user_rank = ' . (int)$row['group_rank'] . ' + AND ' . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); } @@ -3277,7 +3277,8 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna case 'demote': case 'promote': - $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . " + $sql = 'SELECT user_id + FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id AND user_pending = 1 AND " . $db->sql_in_set('user_id', $user_id_ary); @@ -3375,7 +3376,8 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna return 'NO_USERS'; } - $sql = 'SELECT user_id, group_id FROM ' . USERS_TABLE . ' + $sql = 'SELECT user_id, group_id + FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $user_id_ary, false, true); $result = $db->sql_query($sql); @@ -3509,45 +3511,63 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } - // Before we update the user attributes, we will make a list of those having now the group avatar assigned + $updated_sql_ary = $sql_ary; + + // Before we update the user attributes, we will update the rank for users that don't have a custom rank + if (isset($sql_ary['user_rank'])) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', array('user_rank' => $sql_ary['user_rank'])) . ' + WHERE user_rank = 0 + AND ' . $db->sql_in_set('user_id', $user_id_ary); + $db->sql_query($sql); + unset($sql_ary['user_rank']); + } + + // Before we update the user attributes, we will update the avatar for users that don't have a custom avatar if (isset($sql_ary['user_avatar'])) { - // Ok, get the original avatar data from users having an uploaded one (we need to remove these from the filesystem) - $sql = 'SELECT user_id, group_id, user_avatar - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . ' - AND user_avatar_type = ' . AVATAR_UPLOAD; - $result = $db->sql_query($sql); + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', array( + 'user_avatar' => $sql_ary['user_avatar'], + 'user_avatar_type' => $sql_ary['user_avatar_type'], + 'user_avatar_height' => $sql_ary['user_avatar_height'], + 'user_avatar_width' => $sql_ary['user_avatar_width'], + )) . " + WHERE user_avatar = '' + AND " . $db->sql_in_set('user_id', $user_id_ary); + $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - avatar_delete('user', $row); - } - $db->sql_freeresult($result); + unset($sql_ary['user_avatar']); } - else + + unset($sql_ary['user_avatar_type']); + unset($sql_ary['user_avatar_height']); + unset($sql_ary['user_avatar_width']); + + if (!empty($sql_ary)) { - unset($sql_ary['user_avatar_type']); - unset($sql_ary['user_avatar_height']); - unset($sql_ary['user_avatar_width']); + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE ' . $db->sql_in_set('user_id', $user_id_ary); + $db->sql_query($sql); } - $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE ' . $db->sql_in_set('user_id', $user_id_ary); - $db->sql_query($sql); - if (isset($sql_ary['user_colour'])) { // Update any cached colour information for these users - $sql = 'UPDATE ' . FORUMS_TABLE . " SET forum_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET forum_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' WHERE " . $db->sql_in_set('forum_last_poster_id', $user_id_ary); $db->sql_query($sql); - $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_first_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_first_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' WHERE " . $db->sql_in_set('topic_poster', $user_id_ary); $db->sql_query($sql); - $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' WHERE " . $db->sql_in_set('topic_last_poster_id', $user_id_ary); $db->sql_query($sql); @@ -3559,6 +3579,9 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } + // Make all values available for the event + $sql_ary = $updated_sql_ary; + /** * Event when the default group is set for an array of users * -- cgit v1.2.1 From 64c27013d4835f9bede202f208679e34fb0ec7bf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:40:58 +0100 Subject: [ticket/9492] Fix undefined user_avatar_* values when updating the group avatar PHPBB3-9492 --- phpBB/includes/functions_user.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 22272b20f3..3b7c9eea92 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3525,25 +3525,31 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } // Before we update the user attributes, we will update the avatar for users that don't have a custom avatar + $avatar_options = array('user_avatar', 'user_avatar_type', 'user_avatar_height', 'user_avatar_width'); + if (isset($sql_ary['user_avatar'])) { + $avatar_sql_ary = array(); + foreach ($avatar_options as $avatar_option) + { + if (isset($sql_ary[$avatar_option])) + { + $avatar_sql_ary[$avatar_option] = $sql_ary[$avatar_option]; + } + } + $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', array( - 'user_avatar' => $sql_ary['user_avatar'], - 'user_avatar_type' => $sql_ary['user_avatar_type'], - 'user_avatar_height' => $sql_ary['user_avatar_height'], - 'user_avatar_width' => $sql_ary['user_avatar_width'], - )) . " + SSET ' . $db->sql_build_array('UPDATE', $avatar_sql_ary) . " WHERE user_avatar = '' AND " . $db->sql_in_set('user_id', $user_id_ary); $db->sql_query($sql); - - unset($sql_ary['user_avatar']); } - unset($sql_ary['user_avatar_type']); - unset($sql_ary['user_avatar_height']); - unset($sql_ary['user_avatar_width']); + // Remove the avatar options, as we already updated them + foreach ($avatar_options as $avatar_option) + { + unset($sql_ary[$avatar_option]); + } if (!empty($sql_ary)) { -- cgit v1.2.1 From bd87b068587a519b4a6275209525e069e7690ded Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:43:00 +0100 Subject: [ticket/9492] Ensure to update all avatar values when the avatar is changed PHPBB3-9492 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/ucp/ucp_groups.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index b604e20094..9145a20400 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -439,7 +439,7 @@ class acp_groups foreach ($test_variables as $test => $type) { - if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || in_array($test, $set_attributes))) + if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || isset($group_attributes['group_avatar']) && strpos($test, 'avatar') === 0 || in_array($test, $set_attributes))) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index d92aea91f8..b9a06bc3b4 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -618,7 +618,7 @@ class ucp_groups foreach ($test_variables as $test => $type) { - if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) + if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || isset($group_attributes['group_avatar']) && strpos($test, 'avatar') === 0)) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; -- cgit v1.2.1 From 9a6219d8b391eedbbd5626f845b00c3acd738e12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:45:40 +0100 Subject: [ticket/9492] Ensure to delete the avatar/rank data when we change it PHPBB3-9492 --- phpBB/includes/functions_user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3b7c9eea92..d47e04cbe5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2698,12 +2698,12 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow } $db->sql_freeresult($result); - if (isset($sql_ary['group_avatar']) && !$sql_ary['group_avatar']) + if (isset($sql_ary['group_avatar'])) { remove_default_avatar($group_id, $user_ary); } - if (isset($sql_ary['group_rank']) && !$sql_ary['group_rank']) + if (isset($sql_ary['group_rank'])) { remove_default_rank($group_id, $user_ary); } -- cgit v1.2.1 From 6a972da4c7d0cc8008ff95d41b5fb71cb17e107e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Jan 2013 20:58:46 +0100 Subject: [ticket/9492] Fix typo in SQL query PHPBB3-9492 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index d47e04cbe5..b7878ddfc7 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3539,7 +3539,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } $sql = 'UPDATE ' . USERS_TABLE . ' - SSET ' . $db->sql_build_array('UPDATE', $avatar_sql_ary) . " + SET ' . $db->sql_build_array('UPDATE', $avatar_sql_ary) . " WHERE user_avatar = '' AND " . $db->sql_in_set('user_id', $user_id_ary); $db->sql_query($sql); -- cgit v1.2.1 From dfabdbca508a3fbd60c8df57ea756a974f4f135b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 22 Jan 2013 13:19:49 -0600 Subject: [ticket/9737] Fix a few minor things in migrations PHPBB3-9737 --- phpBB/includes/db/migration/exception.php | 7 ++++++- phpBB/includes/db/migrator.php | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index bd46a4e064..ffdcd97780 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -22,7 +22,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration_exception extends \Exception { - /** @var array Extra parameters sent to exception to aid in debugging */ + /** + * Extra parameters sent to exception to aid in debugging + * @var array + */ protected $parameters; /** @@ -42,6 +45,8 @@ class phpbb_db_migration_exception extends \Exception /** * Output the error as a string + * + * @return string */ public function __toString() { diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index d95283ae01..4456600b0a 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -394,7 +394,7 @@ class phpbb_db_migrator } /** - * Attempts to apply a step of the given migration or one of its dependencies + * Attempts to revert a step of the given migration or one of its dependencies * * @param string The class name of the migration * @return bool Whether any update step was successfully run @@ -559,12 +559,12 @@ class phpbb_db_migrator /** * Get a callable statement from a data step * - * @param mixed $step Data step from migration + * @param array $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - protected function get_callable_from_step($step, $last_result = false, $reverse = false) + protected function get_callable_from_step(array $step, $last_result = false, $reverse = false) { $type = $step[0]; $parameters = $step[1]; -- cgit v1.2.1 From 7338bfe3f08b829b97a2045b6bb029dd6b3ba54a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 23 Jan 2013 09:45:20 -0600 Subject: [ticket/9737] Fix some comments PHPBB3-9737 --- phpBB/includes/db/migration/migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index cf1e97b3b1..5f14a6953c 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -74,7 +74,7 @@ abstract class phpbb_db_migration } /** - * Defines other migrations to be applied first (abstract method) + * Defines other migrations to be applied first * * @return array An array of migration class names */ @@ -84,7 +84,7 @@ abstract class phpbb_db_migration } /** - * Allows you to check if the migration is effectively installed (entirely optionall) + * Allows you to check if the migration is effectively installed (entirely optional) * * This is checked when a migration is installed. If true is returned, the migration will be set as * installed without performing the database changes. -- cgit v1.2.1 From 305b2b8f4876e9a11c30a36b10a92b112db47864 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 19:49:02 +0100 Subject: [ticket/11343] Use === when checking stored user_actkey against user input. Use strict comparison when checking whether stored user_actkey is equal to user input. PHPBB3-11343 --- phpBB/includes/ucp/ucp_activate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index 82c1937919..1177d55c12 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -51,7 +51,7 @@ class ucp_activate trigger_error('ALREADY_ACTIVATED'); } - if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] != $key) + if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) { trigger_error('WRONG_ACTIVATION'); } -- cgit v1.2.1 From 8421aa0b0e5607765593126de959bab113427272 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 19:51:17 +0100 Subject: [ticket/11343] Remove spare space. PHPBB3-11343 --- phpBB/includes/ucp/ucp_activate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index 1177d55c12..9e545cd747 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -51,7 +51,7 @@ class ucp_activate trigger_error('ALREADY_ACTIVATED'); } - if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) + if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) { trigger_error('WRONG_ACTIVATION'); } -- cgit v1.2.1 From 5a146df07f62f9963b3ec313ef27a72183f295db Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 19:52:02 +0100 Subject: [ticket/11343] Remove spare parentheses. PHPBB3-11343 --- phpBB/includes/ucp/ucp_activate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index 9e545cd747..b262dc5c1c 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -51,7 +51,7 @@ class ucp_activate trigger_error('ALREADY_ACTIVATED'); } - if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) + if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL || $user_row['user_actkey'] !== $key) { trigger_error('WRONG_ACTIVATION'); } -- cgit v1.2.1 From 36b7d7560e55ee570a2e2f5991982be6c8e66487 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 28 Jan 2013 22:26:20 +0530 Subject: [ticket/11233] prohibit selecting anonymous user as a PM recipient While composing pm, it should not be allowed to add anonymous user as a PM recipient PHPBB3-11233 --- phpBB/includes/ucp/ucp_pm_compose.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php index d1786dd9ba..8e82188aff 100644 --- a/phpBB/includes/ucp/ucp_pm_compose.php +++ b/phpBB/includes/ucp/ucp_pm_compose.php @@ -359,7 +359,7 @@ function compose_pm($id, $mode, $action, $user_folders = array()) $message_attachment = 0; $message_text = $message_subject = ''; - if ($to_user_id && $action == 'post') + if ($to_user_id && $to_user_id != ANONYMOUS && $action == 'post') { $address_list['u'][$to_user_id] = 'to'; } -- cgit v1.2.1 From 75244eafd946bb157ec5e54d5ec2ba3a309ae3ab Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 30 Jan 2013 16:20:50 -0600 Subject: [feature/migrations] Revert unrelated changes to functions.php PHPBB3-9737 --- phpBB/includes/functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 057bdba0e3..d0ef2759d5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2868,7 +2868,6 @@ function send_status_line($code, $message) else { $version = phpbb_request_http_version(); - header("$version $code $message", true, $code); } } @@ -5583,7 +5582,7 @@ function phpbb_convert_30_dbms_to_31($dbms) /* $reflection = new \ReflectionClass($dbms); - + if ($reflection->isSubclassOf('phpbb_db_driver')) { return $dbms; -- cgit v1.2.1 From 336187151a2010197ddda1bcdabc311fd10c1c87 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 4 Feb 2013 01:30:04 +0100 Subject: [ticket/11201] Revert WLM dropping because it is still used in China. Windows Live Messenger is still in use in china which accounts for ~20% of world population. Revert WLM dropping which has been merged under the assumption that WLM data and features are completely useless. This commit reverts commits - 460470229d972b93ef5a98b0d1d97a2a970d684f - 9affd6f7e7b95442f1ef14894858d8213f3fbd2a which have been merged by d59431691c27c73fba8ae9934b84b34a13280dd2. PHPBB3-11201 --- phpBB/includes/acp/acp_users.php | 4 ++++ phpBB/includes/ucp/ucp_pm_viewmessage.php | 1 + phpBB/includes/ucp/ucp_profile.php | 4 ++++ 3 files changed, 9 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 2bdbf1441a..82d8ef5cbb 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1352,6 +1352,7 @@ class acp_users $data = array( 'icq' => request_var('icq', $user_row['user_icq']), 'aim' => request_var('aim', $user_row['user_aim']), + 'msn' => request_var('msn', $user_row['user_msnm']), 'yim' => request_var('yim', $user_row['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)), 'website' => request_var('website', $user_row['user_website']), @@ -1381,6 +1382,7 @@ class acp_users array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), + 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -1414,6 +1416,7 @@ class acp_users $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], + 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -1466,6 +1469,7 @@ class acp_users 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], + 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index a1001cfa74..c85b05f144 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -241,6 +241,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'U_ICQ' => ($user_info['user_icq']) ? 'http://www.icq.com/people/' . urlencode($user_info['user_icq']) . '/' : '', 'U_AIM' => ($user_info['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $author_id) : '', 'U_YIM' => ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '', + 'U_MSN' => ($user_info['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $author_id) : '', 'U_JABBER' => ($user_info['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $author_id) : '', 'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '', diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index c1ad9955b6..e7cea06a45 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -266,6 +266,7 @@ class ucp_profile $data = array( 'icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), + 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), @@ -298,6 +299,7 @@ class ucp_profile array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), + 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -349,6 +351,7 @@ class ucp_profile $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], + 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -420,6 +423,7 @@ class ucp_profile 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], + 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], -- cgit v1.2.1 From 77df9109b61ec93c28a8120a8d81a045961b24ac Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 4 Feb 2013 13:46:23 -0600 Subject: [feature/migrations] Remove default values from necessary parameters Clean up some comments PHPBB3-9737 --- phpBB/includes/db/migration/tool/config.php | 34 ++++++++++--------- phpBB/includes/db/migration/tool/module.php | 44 +++++++++++++++---------- phpBB/includes/db/migration/tool/permission.php | 33 ++++++++++--------- 3 files changed, 61 insertions(+), 50 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index 6ae419d5e7..d9cc20053e 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -38,12 +38,14 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac /** * Add a config setting. * - * @param string $config_name The name of the config setting you would like to add + * @param string $config_name The name of the config setting + * you would like to add * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * @param bool $is_dynamic True if it is dynamic (changes very often) + * and should not be stored in the cache, false if not. * @return null */ - public function add($config_name, $config_value = '', $is_dynamic = false) + public function add($config_name, $config_value, $is_dynamic = false) { if (isset($this->config[$config_name])) { @@ -56,11 +58,12 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac /** * Update an existing config setting. * - * @param string $config_name The name of the config setting you would like to update + * @param string $config_name The name of the config setting you would + * like to update * @param mixed $config_value The value of the config setting * @return null */ - public function update($config_name, $config_value = '') + public function update($config_name, $config_value) { if (!isset($this->config[$config_name])) { @@ -71,14 +74,17 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } /** - * Update a config setting if the first argument equal to the current config value + * Update a config setting if the first argument equal to the + * current config value * - * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not - * @param string $config_name The name of the config setting you would like to update + * @param string $compare If equal to the current config value, will be + * updated to the new config value, otherwise not + * @param string $config_name The name of the config setting you would + * like to update * @param mixed $config_value The value of the config setting * @return null */ - public function update_if_equals($compare, $config_name, $config_value = '') + public function update_if_equals($compare, $config_name, $config_value) { if (!isset($this->config[$config_name])) { @@ -91,7 +97,8 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac /** * Remove an existing config setting. * - * @param string $config_name The name of the config setting you would like to remove + * @param string $config_name The name of the config setting you would + * like to remove * @return null */ public function remove($config_name) @@ -105,12 +112,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } /** - * Reverse an original install action - * - * First argument is the original call to the class (e.g. add, remove) - * After the first argument, send the original arguments to the function in the original call - * - * @return null + * {@inheritdoc} */ public function reverse() { diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 561faac552..afe1f21ec5 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -66,8 +66,10 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * Check if a module exists * * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). + * Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to + * check for to see if it exists * @return bool true/false if module exists */ public function exists($class, $parent, $module) @@ -131,10 +133,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * * @param string $class The module class(acp|mcp|ucp) * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( + * @param array $data an array of the data on the new module. + * This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. + * It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, + * if you want to create a module (instead of just a category) you must + * send module_basename and module_mode. + * array( * 'module_enabled' => 1, * 'module_display' => 1, * 'module_basename' => '', @@ -144,14 +150,19 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * 'module_mode' => '', * 'module_auth' => '', * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * 2. The "automatic" way. For inserting multiple at a time based on the + * specs in the info file for the module(s). For this to work the + * modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag + * modes from the includes/acp/info/acp_asacp.php file): * array( * 'module_basename' => 'asacp', * 'modes' => array('settings', 'log', 'flag'), * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here + * Optionally you may not send 'modes' and it will insert all of the + * modules in that info file. + * @param string|bool $include_path If you would like to use a custom include + * path, specify that here * @return null */ public function add($class, $parent = 0, $data = array(), $include_path = false) @@ -334,9 +345,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * Remove a module * * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string|bool $parent The parent module_id|module_langname(0 for no parent). + * Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @param string|bool $include_path If you would like to use a custom include path, + * specify that here * @return null */ public function remove($class, $parent = 0, $module = '', $include_path = false) @@ -473,12 +486,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } /** - * Reverse an original install action - * - * First argument is the original call to the class (e.g. add, remove) - * After the first argument, send the original arguments to the function in the original call - * - * @return null + * {@inheritdoc} */ public function reverse() { diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index a25fdb345e..001d090f5a 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -61,7 +61,8 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Check if a permission (auth) setting exists * * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting + * @param bool $global True for checking a global permission setting, + * False for a local permission setting * @return bool true if it exists, false if not */ public function exists($auth_option, $global = true) @@ -98,7 +99,8 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Add a permission (auth) option * * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting + * @param bool $global True for checking a global permission setting, + * False for a local permission setting * @return null */ public function add($auth_option, $global = true, $copy_from = false) @@ -180,7 +182,8 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Remove a permission (auth) option * * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting + * @param bool $global True for checking a global permission setting, + * False for a local permission setting * @return null */ public function remove($auth_option, $global = true) @@ -239,7 +242,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param sting $role_type The type (u_, m_, a_) * @return null */ - public function role_add($role_name, $role_type = '', $role_description = '') + public function role_add($role_name, $role_type, $role_description = '') { $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " @@ -277,7 +280,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param string $new_role_name The new role name * @return null */ - public function role_update($old_role_name, $new_role_name = '') + public function role_update($old_role_name, $new_role_name) { $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " @@ -332,12 +335,14 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Allows you to set permissions for a certain group/role * * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string|array $auth_option The auth_option or array of + * auth_options you would like to set * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + * @param bool $has_permission True if you want to give them permission, + * false if you want to deny them permission * @return null */ - public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + public function permission_set($name, $auth_option, $type = 'role', $has_permission = true) { if (!is_array($auth_option)) { @@ -477,11 +482,12 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Allows you to unset (remove) permissions for a certain group/role * * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string|array $auth_option The auth_option or array of + * auth_options you would like to set * @param string $type The type (role|group) * @return null */ - public function permission_unset($name, $auth_option = array(), $type = 'role') + public function permission_unset($name, $auth_option, $type = 'role') { if (!is_array($auth_option)) { @@ -565,12 +571,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } /** - * Reverse an original install action - * - * First argument is the original call to the class (e.g. add, remove) - * After the first argument, send the original arguments to the function in the original call - * - * @return null + * {@inheritdoc} */ public function reverse() { -- cgit v1.2.1 From 293b65e3efbf94f6521acebe1b9f3e7bbca20286 Mon Sep 17 00:00:00 2001 From: David Tobin Date: Thu, 5 Jul 2012 02:47:49 +0100 Subject: [ticket/10896] Adds email validation to email settings in ACP Adds a new validation type to the ACP validate_config_vars function and implements it on the board_contact and board_email settings. PHPBB3-10896 --- phpBB/includes/acp/acp_board.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index f437dca8f9..ebbf66657e 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -408,8 +408,8 @@ class acp_board 'board_email_form' => array('lang' => 'BOARD_EMAIL_FORM', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'email_function_name' => array('lang' => 'EMAIL_FUNCTION_NAME', 'validate' => 'string', 'type' => 'text:20:50', 'explain' => true), 'email_package_size' => array('lang' => 'EMAIL_PACKAGE_SIZE', 'validate' => 'int:0', 'type' => 'text:5:5', 'explain' => true), - 'board_contact' => array('lang' => 'CONTACT_EMAIL', 'validate' => 'string', 'type' => 'text:25:100', 'explain' => true), - 'board_email' => array('lang' => 'ADMIN_EMAIL', 'validate' => 'string', 'type' => 'text:25:100', 'explain' => true), + 'board_contact' => array('lang' => 'CONTACT_EMAIL', 'validate' => 'email', 'type' => 'text:25:100', 'explain' => true), + 'board_email' => array('lang' => 'ADMIN_EMAIL', 'validate' => 'email', 'type' => 'text:25:100', 'explain' => true), 'board_email_sig' => array('lang' => 'EMAIL_SIG', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true), 'board_hide_emails' => array('lang' => 'BOARD_HIDE_EMAILS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), -- cgit v1.2.1 From 8d3a82a4fa8ced50fbc1d1019ef439d1d5c81e71 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 19:32:39 -0600 Subject: [feature/migrations] Make the container available to extension installers This allows extensions to load and install migrations easily as per their needs. PHPBB3-11318 --- phpBB/includes/extension/base.php | 15 +++++++++++++++ phpBB/includes/extension/manager.php | 13 ++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index 9d076eb6c5..d51589d719 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * A base class for extensions without custom enable/disable/purge code. * @@ -22,6 +24,19 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_base implements phpbb_extension_interface { + /** @var ContainerInterface */ + protected $container; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + /** * Single enable step that does nothing * diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index de6f364320..8136dfa90b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * The extension manager provides means to activate/deactivate extensions. * @@ -22,6 +24,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_manager { + /** @var ContainerInterface */ + protected $container; + protected $db; protected $config; protected $cache; @@ -34,6 +39,7 @@ class phpbb_extension_manager /** * Creates a manager and loads information from database * + * @param ContainerInterface $container A container * @param phpbb_db_driver $db A database connection * @param phpbb_config $config phpbb_config * @param string $extension_table The name of the table holding extensions @@ -42,8 +48,9 @@ class phpbb_extension_manager * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { + $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; @@ -126,11 +133,11 @@ class phpbb_extension_manager if (class_exists($extension_class_name)) { - return new $extension_class_name; + return new $extension_class_name($this->container); } else { - return new phpbb_extension_base; + return new phpbb_extension_base($this->container); } } -- cgit v1.2.1 From aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 31 Jan 2013 13:53:33 -0600 Subject: [feature/migrations] Automatically install/revert migrations for extensions Migrations from ext/ext_name/migrations/ are automatically installed when enabling the extension and automatically reverted when the extension is purged. PHPBB3-11318 --- phpBB/includes/extension/manager.php | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 8136dfa90b..018324d5d6 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -173,6 +173,12 @@ class phpbb_extension_manager $old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false; + // Returns false if not completed + if (!$this->handle_migrations($name, 'enable')) + { + return true; + } + $extension = $this->get_extension($name); $state = $extension->enable_step($old_state); @@ -324,6 +330,12 @@ class phpbb_extension_manager $old_state = unserialize($this->extensions[$name]['ext_state']); + // Returns false if not completed + if (!$this->handle_migrations($name, 'purge')) + { + return true; + } + $extension = $this->get_extension($name); $state = $extension->purge_step($old_state); @@ -497,4 +509,54 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } + + /** + * Handle installing/reverting migrations + * + * @param string $extension_name Name of the extension + * @param string $mode enable or purge + * @return bool True if completed, False if not completed + */ + protected function handle_migrations($extension_name, $mode) + { + $migrator = $this->container->get('migrator'); + $migrations_path = $this->get_extension_path($extension_name) . 'migrations'; + if (file_exists($migrations_path) && is_dir($migrations_path)) + { + $migrator->load_migrations($migrations_path); + } + + // What is a safe limit of execution time? Half the max execution time should be safe. + $safe_time_limit = (ini_get('max_execution_time') / 2); + $start_time = time(); + + if ($mode == 'enable') + { + while (!$migrator->finished()) + { + $migrator->update(); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } + } + } + else if ($mode == 'purge') + { + while ($migrator->migration_state() !== false) + { + $migrator->revert(); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } + } + } + + return true; + } } -- cgit v1.2.1 From fb4f7470d481bd73dd505e7ce0522907f67773ef Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:34:03 -0600 Subject: [feature/migrations] Rebuilding migrations data on develop So this is easy to merge later. PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 28 ++ phpBB/includes/db/migration/data/3_0_10.php | 28 ++ phpBB/includes/db/migration/data/3_0_10_rc1.php | 30 ++ phpBB/includes/db/migration/data/3_0_10_rc2.php | 28 ++ phpBB/includes/db/migration/data/3_0_10_rc3.php | 28 ++ phpBB/includes/db/migration/data/3_0_11.php | 28 ++ phpBB/includes/db/migration/data/3_0_11_rc1.php | 94 ++++++ phpBB/includes/db/migration/data/3_0_11_rc2.php | 34 ++ phpBB/includes/db/migration/data/3_0_12_rc1.php | 123 +++++++ phpBB/includes/db/migration/data/3_0_1_rc1.php | 102 ++++++ phpBB/includes/db/migration/data/3_0_2.php | 28 ++ phpBB/includes/db/migration/data/3_0_2_rc1.php | 32 ++ phpBB/includes/db/migration/data/3_0_2_rc2.php | 55 +++ phpBB/includes/db/migration/data/3_0_3.php | 28 ++ phpBB/includes/db/migration/data/3_0_3_rc1.php | 63 ++++ phpBB/includes/db/migration/data/3_0_4.php | 49 +++ phpBB/includes/db/migration/data/3_0_4_rc1.php | 107 ++++++ phpBB/includes/db/migration/data/3_0_5.php | 28 ++ phpBB/includes/db/migration/data/3_0_5_rc1.php | 119 +++++++ .../includes/db/migration/data/3_0_5_rc1part2.php | 37 ++ phpBB/includes/db/migration/data/3_0_6.php | 28 ++ phpBB/includes/db/migration/data/3_0_6_rc1.php | 279 +++++++++++++++ phpBB/includes/db/migration/data/3_0_6_rc2.php | 28 ++ phpBB/includes/db/migration/data/3_0_6_rc3.php | 40 +++ phpBB/includes/db/migration/data/3_0_6_rc4.php | 28 ++ phpBB/includes/db/migration/data/3_0_7.php | 28 ++ phpBB/includes/db/migration/data/3_0_7_pl1.php | 28 ++ phpBB/includes/db/migration/data/3_0_7_rc1.php | 53 +++ phpBB/includes/db/migration/data/3_0_7_rc2.php | 72 ++++ phpBB/includes/db/migration/data/3_0_8.php | 28 ++ phpBB/includes/db/migration/data/3_0_8_rc1.php | 221 ++++++++++++ phpBB/includes/db/migration/data/3_0_9.php | 28 ++ phpBB/includes/db/migration/data/3_0_9_rc1.php | 110 ++++++ phpBB/includes/db/migration/data/3_0_9_rc2.php | 28 ++ phpBB/includes/db/migration/data/3_0_9_rc3.php | 28 ++ phpBB/includes/db/migration/data/3_0_9_rc4.php | 28 ++ phpBB/includes/db/migration/data/3_1_0_dev.php | 375 +++++++++++++++++++++ phpBB/includes/db/migration/data/extensions.php | 55 +++ .../includes/db/migration/data/style_update_p1.php | 157 +++++++++ .../includes/db/migration/data/style_update_p2.php | 42 +++ phpBB/includes/db/migration/data/timezone.php | 161 +++++++++ phpBB/includes/update_helpers.php | 112 ------ 42 files changed, 2914 insertions(+), 112 deletions(-) create mode 100644 phpBB/includes/db/migration/data/3_0_1.php create mode 100644 phpBB/includes/db/migration/data/3_0_10.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_11.php create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_2.php create mode 100644 phpBB/includes/db/migration/data/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_3.php create mode 100644 phpBB/includes/db/migration/data/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_4.php create mode 100644 phpBB/includes/db/migration/data/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_5.php create mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/data/3_0_6.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/data/3_0_7.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_8.php create mode 100644 phpBB/includes/db/migration/data/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_9.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc4.php create mode 100644 phpBB/includes/db/migration/data/3_1_0_dev.php create mode 100644 phpBB/includes/db/migration/data/extensions.php create mode 100644 phpBB/includes/db/migration/data/style_update_p1.php create mode 100644 phpBB/includes/db/migration/data/style_update_p2.php create mode 100644 phpBB/includes/db/migration/data/timezone.php delete mode 100644 phpBB/includes/update_helpers.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php new file mode 100644 index 0000000000..a2332c9b59 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -0,0 +1,28 @@ +sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $this->db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql); + } + } + + function delete_orphan_private_messages() + { + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php new file mode 100644 index 0000000000..f2bed54085 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -0,0 +1,34 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.11-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php new file mode 100644 index 0000000000..0d8702f19e --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -0,0 +1,123 @@ +db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); + $this->sql_query($sql); + } + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_u_sig\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'signature\''; + $this->sql_query($sql); + } + + public function update_bots() + { + // Update bots + if (!function_exists('user_delete')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $bots_updates = array( + // Bot Deletions + 'NG-Search [Bot]' => false, + 'Nutch/CVS [Bot]' => false, + 'OmniExplorer [Bot]' => false, + 'Seekport [Bot]' => false, + 'Synoo [Bot]' => false, + 'WiseNut [Bot]' => false, + + // Bot Updates + // Bot name to bot user agent map + 'Baidu [Spider]' => 'Baiduspider', + 'Exabot [Bot]' => 'Exabot', + 'Voyager [Bot]' => 'voyager/', + 'W3C [Validator]' => 'W3C_Validator', + ); + + foreach ($bots_updates as $bot_name => $bot_agent) + { + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_type = ' . USER_IGNORE . " + AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; + $result = $this->db->sql_query($sql); + $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if ($bot_user_id) + { + if ($bot_agent === false) + { + $sql = 'DELETE FROM ' . BOTS_TABLE . " + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + + user_delete('remove', $bot_user_id); + } + else + { + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php new file mode 100644 index 0000000000..cf067d2e2c --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -0,0 +1,102 @@ + array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array('group_legend'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list', + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + ), + 'add_index' => array( + $this->table_prefix . 'groups' => array( + 'group_legend' => 'group_legend', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + $this->table_prefix . 'groups' => array('group_legend_name'), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + + array('config.update', array('version', '3.0.1-rc1')), + ); + } + + function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php new file mode 100644 index 0000000000..3469d8d178 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.2-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php new file mode 100644 index 0000000000..dff375f438 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', $this->db->sql_server_info(true))), + array('permission.add', array('u_masspm_group', true, 'u_masspm')), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + + array('config.update', array('version', '3.0.3-rc1')), + ); + } + + function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); + } + + function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php new file mode 100644 index 0000000000..1af4508331 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -0,0 +1,49 @@ +db->sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php new file mode 100644 index 0000000000..e9bb0e01f5 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -0,0 +1,107 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + + array('config.update', array('version', '3.0.4-rc1')), + ); + } + + function update_custom_profile_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + + $this->db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php new file mode 100644 index 0000000000..2f80970781 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + $search_indexing_state = $this->config['search_indexing_state']; + + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_fonts', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } + + function hash_old_passwords() + { + $sql = 'SELECT user_id, user_password + FROM ' . $this->table_prefix . 'users + WHERE user_pass_convert = 1'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); + } + } + $this->db->sql_freeresult($result); + } + + function update_ichiro_bot() + { + // Adjust bot entry + $sql = 'UPDATE ' . $this->table_prefix . "bots + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + $this->sql_query($sql); + } + + function remove_duplicate_auth_options() + { + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + $sql = 'SELECT auth_option + FROM ' . $this->table_prefix . 'acl_options + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $this->db->sql_query($sql); + + $auth_options = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $this->db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $this->db->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $this->db->sql_fetchrow($result); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + } + $this->db->sql_freeresult($result); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php new file mode 100644 index 0000000000..1fab0f8873 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -0,0 +1,37 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.5-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php new file mode 100644 index 0000000000..26176b9437 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('if', array( + ($this->config['captcha_gd']), + array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + array('config.update', array('allow_avatar', 1)), + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + array('config.update', array('allow_avatar_remote_upload', 1)), + )), + + array('module.add', array( + 'acp', + 'ACP_BOARD_CONFIGURATION', + array( + 'module_basename' => 'acp_board', + 'modes' => array('feed'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_CAT_USERS', + array( + 'module_basename' => 'acp_users', + 'modes' => array('warnings'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_SERVER_CONFIGURATION', + array( + 'module_basename' => 'acp_send_statistics', + 'modes' => array('send_statistics'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_FORUM_BASED_PERMISSIONS', + array( + 'module_basename' => 'acp_permissions', + 'modes' => array('setting_forum_copy'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'mcp_pm_reports', + 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + + array('config.update', array('version', '3.0.6-rc1')), + ); + } + + function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + + function add_newly_registered_group() + { + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + $this->sql_query($sql); + + $group_id = $this->db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); + + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); + + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + $this->sql_query($sql); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); + } + $this->db->sql_freeresult($result); + } + + // Clear permissions... + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php new file mode 100644 index 0000000000..4092a5fa61 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -0,0 +1,28 @@ +sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php new file mode 100644 index 0000000000..e748c7a4ff --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'log' => array('log_time'), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + + array('config.update', array('version', '3.0.7-rc1')), + ); + } + + function delete_text_templates() + { + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php new file mode 100644 index 0000000000..4e380c810d --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -0,0 +1,72 @@ + ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + $i = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + $this->sql_query($sql); + } + } + $this->db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return; + } + + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php new file mode 100644 index 0000000000..a5defc8278 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -0,0 +1,28 @@ + 'acp_board', + 'modes' => array('post'), + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), + + array('config.update', array('version', '3.0.8-rc1')), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $this->db->sql_freeresult($result); + } + + function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + $this->sql_query($sql); + } + + function update_bots() + { + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + $this->sql_query($sql); + } + } + + function delete_orphan_shadow_topics() + { + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php new file mode 100644 index 0000000000..eb359e2697 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcodes' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + + array('config.update', array('version', '3.0.9-rc1')), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + function fix_firebird_qa_captcha() + { + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($this->db_tools->sql_layer == 'firebird') + { + $tables = array( + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($this->db_tools->sql_table_exists($table)) + { + $this->db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php new file mode 100644 index 0000000000..e3c4716665 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -0,0 +1,28 @@ + array( + GROUPS_TABLE => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + PROFILE_FIELDS_TABLE => array( + 'field_show_on_pm' => array('BOOL', 0), + ), + STYLES_TABLE => array( + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), + ), + REPORTS_TABLE => array( + 'reported_post_text' => array('MTEXT_UNI', ''), + 'reported_post_uid' => array('VCHAR:8', ''), + 'reported_post_bitfield' => array('VCHAR:255', ''), + ), + ), + 'change_columns' => array( + GROUPS_TABLE => array( + 'group_legend' => array('UINT', 0), + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + + array('config.add', array('fulltext_postgres_ts_name', 'simple')), + array('config.add', array('fulltext_postgres_min_word_len', 4)), + array('config.add', array('fulltext_postgres_max_word_len', 254)), + array('config.add', array('fulltext_sphinx_stopwords', 0)), + array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), + + array('config.add', array('load_jquery_cdn', 0)), + array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), + + array('config.add', array('use_system_cron', 0)), + + array('config.add', array('legend_sort_groupname', 0)), + array('config.add', array('teampage_forums', 1)), + array('config.add', array('teampage_memberships', 1)), + + array('config.add', array('load_cpf_pm', 0)), + + array('config.add', array('display_last_subject', 1)), + + array('config.add', array('assets_version', 1)), + + array('config.add', array('site_home_url', '')), + array('config.add', array('site_home_text', '')), + + array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), + + array('module.add', array( + 'acp', + 'ACP_GROUPS', + array( + 'module_basename' => 'acp_groups', + 'modes' => array('position'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_ATTACHMENTS', + array( + 'module_basename' => 'acp_attachments', + 'modes' => array('manage'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_STYLE_MANAGEMENT', + array( + 'module_basename' => 'acp_styles', + 'modes' => array('install', 'cache'), + ), + )), + array('module.add', array( + 'ucp', + 'UCP_PROFILE', + array( + 'module_basename' => 'ucp_profile', + 'modes' => array('autologin_keys'), + ), + )), + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_LANGUAGE' + )), + + array('module.remove', array( + 'acp', + false, + 'ACP_TEMPLATES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_THEMES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_IMAGESETS', + )), + + array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'rename_styles_module'))), + array('custom', array(array($this, 'add_group_teampage'))), + array('custom', array(array($this, 'update_group_legend'))), + array('custom', array(array($this, 'localise_global_announcements'))), + array('custom', array(array($this, 'update_ucp_pm_basename'))), + array('custom', array(array($this, 'update_ucp_profile_auth'))), + array('custom', array(array($this, 'move_customise_modules'))), + + array('config.update', array('version', '3.1.0-dev')), + ); + } + + public function move_customise_modules() + { + // Move language management to new location in the Customise tab + // First get language module id + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_basename = 'acp_language'"; + $result = $this->db->sql_query($sql); + $language_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + // Next get language management module id of the one just created + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = 'ACP_LANGUAGE'"; + $result = $this->db->sql_query($sql); + $language_management_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + } + // acp_modules calls adm_back_link, which is undefined at this point + if (!function_exists('adm_back_link')) + { + include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); + } + $module_manager = new acp_modules(); + $module_manager->module_class = 'acp'; + $module_manager->move_module($language_module_id, $language_management_module_id); + } + + public function update_ucp_pm_basename() + { + $sql = 'SELECT module_id, module_basename + FROM ' . MODULES_TABLE . " + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM'"; + $result = $this->db->sql_query_limit($sql, 1); + + if ($row = $this->db->sql_fetchrow($result)) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; + + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_ucp_profile_auth() + { + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'profile_info'"; + $this->sql_query($sql); + } + + public function rename_styles_module() + { + // Rename styles module to Customise + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_langname = 'ACP_CAT_CUSTOMISE' + WHERE module_langname = 'ACP_CAT_STYLES'"; + $this->sql_query($sql); + } + + public function rename_module_basenames() + { + // rename all module basenames to full classname + $sql = 'SELECT module_id, module_basename, module_class + FROM ' . MODULES_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $module_id = (int) $row['module_id']; + unset($row['module_id']); + + if (!empty($row['module_basename']) && !empty($row['module_class'])) + { + // all the class names start with class name or with phpbb_ for auto loading + if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && + strpos($row['module_basename'], 'phpbb_') !== 0) + { + $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; + + $sql_update = $this->db->sql_build_array('UPDATE', $row); + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET ' . $sql_update . ' + WHERE module_id = ' . $module_id; + $this->sql_query($sql); + } + } + } + + $this->db->sql_freeresult($result); + } + + public function add_group_teampage() + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'ADMINISTRATORS'"; + $this->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + $this->sql_query($sql); + } + + public function update_group_legend() + { + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . ' + WHERE group_legend = 1 + ORDER BY group_name ASC'; + $result = $this->db->sql_query($sql); + + $next_legend = 1; + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_legend . ' + WHERE group_id = ' . (int) $row['group_id']; + $this->sql_query($sql); + + $next_legend++; + } + $this->db->sql_freeresult($result); + } + + public function localise_global_announcements() + { + // Localise Global Announcements + $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = 0 + AND topic_type = ' . POST_GLOBAL; + $result = $this->db->sql_query($sql); + + $global_announcements = $update_lastpost_data = array(); + $update_lastpost_data['forum_last_post_time'] = 0; + $update_forum_data = array( + 'forum_posts' => 0, + 'forum_topics' => 0, + 'forum_topics_real' => 0, + ); + + while ($row = $this->db->sql_fetchrow($result)) + { + $global_announcements[] = (int) $row['topic_id']; + + $update_forum_data['forum_posts'] += (int) $row['topic_posts']; + $update_forum_data['forum_topics_real']++; + if ($row['topic_approved']) + { + $update_forum_data['forum_topics']++; + } + + if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) + { + $update_lastpost_data = array( + 'forum_last_post_id' => (int) $row['topic_last_post_id'], + 'forum_last_post_subject' => $row['topic_last_post_subject'], + 'forum_last_post_time' => (int) $row['topic_last_post_time'], + 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], + 'forum_last_poster_name' => $row['topic_last_poster_name'], + 'forum_last_poster_colour' => $row['topic_last_poster_colour'], + ); + } + } + $this->db->sql_freeresult($result); + + if (!empty($global_announcements)) + { + // Update the post/topic-count for the forum and the last-post if needed + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST; + $result = $this->db->sql_query_limit($sql, 1); + $ga_forum_id = $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT forum_last_post_time + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $ga_forum_id; + $result = $this->db->sql_query($sql); + $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); + $this->db->sql_freeresult($result); + + $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; + $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; + $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; + if ($lastpost < $update_lastpost_data['forum_last_post_time']) + { + $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); + } + + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $sql_update . ' + WHERE forum_id = ' . $ga_forum_id; + $this->sql_query($sql); + + // Update some forum_ids + $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); + foreach ($table_ary as $table) + { + $sql = "UPDATE $table + SET forum_id = $ga_forum_id + WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); + $this->sql_query($sql); + } + unset($table_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php new file mode 100644 index 0000000000..b8379483a3 --- /dev/null +++ b/phpBB/includes/db/migration/data/extensions.php @@ -0,0 +1,55 @@ + array( + EXT_TABLE => array( + 'COLUMNS' => array( + 'ext_name' => array('VCHAR', ''), + 'ext_active' => array('BOOL', 0), + 'ext_state' => array('TEXT', ''), + ), + 'KEYS' => array( + 'ext_name' => array('UNIQUE', 'ext_name'), + ), + ), + ), + ); + } + + public function update_data() + { + return array( + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_EXTENSION_MANAGEMENT' + )), + array('module.add', array( + 'acp', + 'ACP_EXTENSION_MANAGEMENT', + array( + 'module_basename' => 'acp_extensions', + 'modes' => array('main'), + ), + )), + array('permission.add', array('a_extensions', true, 'a_styles')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php new file mode 100644 index 0000000000..387b37de8e --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -0,0 +1,157 @@ +phpbb_root_path . 'styles'); + $skip_dirs = array('.', '..', 'prosilver'); + foreach ($iterator as $fileinfo) + { + if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) + { + $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); + if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) + { + // 3.1 style + $available_styles[] = $fileinfo->getFilename(); + } + } + } + + // Get all installed styles + if ($this->db_tools->sql_table_exists(STYLES_IMAGESET_TABLE)) + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + } + else + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id"; + } + $result = $this->db->sql_query($sql); + + $styles = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $styles[] = $row; + } + $this->db->sql_freeresult($result); + + // Decide which styles to keep, all others will be deleted + $valid_styles = array(); + foreach ($styles as $style_row) + { + if ( + // Delete styles with parent style (not supported yet) + $style_row['template_inherits_id'] == 0 && + // Check if components match + $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && + // Check if components are valid + in_array($style_row['template_path'], $available_styles) + ) + { + // Valid style. Keep it + $sql_ary = array( + 'style_path' => $style_row['template_path'], + 'bbcode_bitfield' => $style_row['bbcode_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + ); + $this->sql_query('UPDATE ' . STYLES_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE style_id = ' . $style_row['style_id']); + $valid_styles[] = (int) $style_row['style_id']; + } + } + + // Remove old entries from styles table + if (!sizeof($valid_styles)) + { + // No valid styles: remove everything and add prosilver + $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + + $sql_ary = array( + 'style_name' => 'prosilver', + 'style_copyright' => '© phpBB Group', + 'style_active' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'lNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', + + // Will be removed in the next step + 'imageset_id' => 0, + 'template_id' => 0, + 'theme_id' => 0, + ); + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->sql_query($sql); + + $sql = 'SELECT style_id + FROM ' . $table . " + WHERE style_name = 'prosilver'"; + $result = $this->sql_query($sql); + $default_style = $this->db->sql_fetchfield($result); + $this->db->sql_freeresult($result); + + set_config('default_style', $default_style); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $this->sql_query($sql); + } + else + { + // There are valid styles in styles table. Remove styles that are outdated + $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' + WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); + + // Change default style + if (!in_array($this->config['default_style'], $valid_styles)) + { + $this->sql_query('UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $valid_styles[0] . "' + WHERE config_name = 'default_style'"); + } + + // Reset styles for users + $this->sql_query('UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); + } + } +} diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php new file mode 100644 index 0000000000..db4b7f1753 --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -0,0 +1,42 @@ + array( + STYLES_TABLE => array( + 'imageset_id', + 'template_id', + 'theme_id', + ), + ), + + 'drop_tables' => array( + STYLES_IMAGESET_TABLE, + STYLES_IMAGESET_DATA_TABLE, + STYLES_TEMPLATE_TABLE, + STYLES_TEMPLATE_DATA_TABLE, + STYLES_THEME_TABLE, + ), + ); + } + + public function update_data() + { + return array(); + } +} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php new file mode 100644 index 0000000000..7734ed4b76 --- /dev/null +++ b/phpBB/includes/db/migration/data/timezone.php @@ -0,0 +1,161 @@ + array( + USERS_TABLE => array( + 'user_timezone' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_timezones'))), + ); + } + + public function update_timezones() + { + // Update user timezones + $sql = 'SELECT user_dst, user_timezone + FROM ' . USERS_TABLE . ' + GROUP BY user_timezone, user_dst'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' + WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' + AND user_dst = " . (int) $row['user_dst']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + + // Update board default timezone + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' + WHERE config_name = 'board_timezone'"; + $this->sql_query($sql); + + // After we have calculated the timezones we can delete user_dst column from user table. + $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); + } + + /** + * Determine the new timezone for a given phpBB 3.0 timezone and + * "Daylight Saving Time" option + * + * @param $timezone float Users timezone in 3.0 + * @param $dst int Users daylight saving time + * @return string Users new php Timezone which is used since 3.1 + */ + public function convert_phpbb30_timezone($timezone, $dst) + { + $offset = $timezone + $dst; + + switch ($timezone) + { + case '-12': + return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' + case '-11': + return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' + case '-10': + return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' + case '-9.5': + return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' + case '-9': + return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' + case '-8': + return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' + case '-7': + return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' + case '-6': + return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' + case '-5': + return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' + case '-4.5': + return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' + case '-4': + return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' + case '-3.5': + return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' + case '-3': + return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' + case '-2': + return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' + case '-1': + return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' + case '0': + return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' + case '1': + return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' + case '2': + return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' + case '3': + return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' + case '3.5': + return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' + case '4': + return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' + case '4.5': + return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' + case '5': + return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' + case '5.5': + return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' + case '5.75': + return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' + case '6': + return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' + case '6.5': + return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' + case '7': + return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' + case '8': + return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' + case '8.75': + return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' + case '9': + return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' + case '9.5': + return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' + case '10': + return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' + case '10.5': + return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' + case '11': + return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' + case '11.5': + return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' + case '12': + return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' + case '12.75': + return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' + case '13': + return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' + case '14': + return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' + default: + return 'UTC'; + } + } +} diff --git a/phpBB/includes/update_helpers.php b/phpBB/includes/update_helpers.php deleted file mode 100644 index 69d678b2f8..0000000000 --- a/phpBB/includes/update_helpers.php +++ /dev/null @@ -1,112 +0,0 @@ - Date: Thu, 10 Jan 2013 17:18:12 -0600 Subject: [feature/migrations] Revert schema for migration data PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 5 -- phpBB/includes/db/migration/data/3_0_10.php | 5 -- phpBB/includes/db/migration/data/3_0_10_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_10_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_10_rc3.php | 5 -- phpBB/includes/db/migration/data/3_0_11.php | 5 -- phpBB/includes/db/migration/data/3_0_11_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_11_rc2.php | 11 +++ phpBB/includes/db/migration/data/3_0_12_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_1_rc1.php | 14 +++- phpBB/includes/db/migration/data/3_0_2.php | 5 -- phpBB/includes/db/migration/data/3_0_2_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_2_rc2.php | 22 ++++- phpBB/includes/db/migration/data/3_0_3.php | 5 -- phpBB/includes/db/migration/data/3_0_3_rc1.php | 15 ++++ phpBB/includes/db/migration/data/3_0_4.php | 5 -- phpBB/includes/db/migration/data/3_0_4_rc1.php | 11 +++ phpBB/includes/db/migration/data/3_0_5.php | 5 -- .../includes/db/migration/data/3_0_5_rc1part2.php | 4 +- phpBB/includes/db/migration/data/3_0_6.php | 5 -- phpBB/includes/db/migration/data/3_0_6_rc1.php | 40 +++++++++ phpBB/includes/db/migration/data/3_0_6_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_6_rc3.php | 5 -- phpBB/includes/db/migration/data/3_0_6_rc4.php | 5 -- phpBB/includes/db/migration/data/3_0_7.php | 5 -- phpBB/includes/db/migration/data/3_0_7_pl1.php | 5 -- phpBB/includes/db/migration/data/3_0_7_rc1.php | 20 ++++- phpBB/includes/db/migration/data/3_0_7_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_8.php | 5 -- phpBB/includes/db/migration/data/3_0_8_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_9.php | 5 -- phpBB/includes/db/migration/data/3_0_9_rc1.php | 9 ++ phpBB/includes/db/migration/data/3_0_9_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_9_rc3.php | 5 -- phpBB/includes/db/migration/data/3_0_9_rc4.php | 5 -- phpBB/includes/db/migration/data/3_1_0_dev.php | 37 ++++++-- phpBB/includes/db/migration/data/extensions.php | 11 ++- .../includes/db/migration/data/style_update_p1.php | 11 +-- .../includes/db/migration/data/style_update_p2.php | 98 ++++++++++++++++++++-- phpBB/includes/db/migration/data/timezone.php | 11 +-- phpBB/includes/db/migration/data/timezone_p2.php | 38 +++++++++ 41 files changed, 314 insertions(+), 168 deletions(-) create mode 100644 phpBB/includes/db/migration/data/timezone_p2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index a2332c9b59..d71288c64b 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_1_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 07410c5ba1..17472562f2 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10_rc3'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index daac50a631..eebee44e39 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index 234e4c5fc7..b81fde9bcb 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index 075ce35e3e..d97b0b4aec 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index 0bc9b6c4a5..b149cd374c 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_11_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 752efd72b2..3d4920bf49 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php index f2bed54085..e0638f02d7 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -25,6 +25,17 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 0d8702f19e..0b35de2ed5 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -16,11 +16,6 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_11'); } - public function update_schema() - { - return array(); - } - public function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index cf067d2e2c..a7af5d052d 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -26,7 +26,9 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ), ), 'drop_keys' => array( - $this->table_prefix . 'groups' => array('group_legend'), + $this->table_prefix . 'groups' => array( + 'group_legend', + ), ), 'add_index' => array( $this->table_prefix . 'sessions' => array( @@ -52,12 +54,16 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ), 'add_index' => array( $this->table_prefix . 'groups' => array( - 'group_legend' => 'group_legend', + 'group_legend' => array('group_legend'), ), ), 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), - $this->table_prefix . 'groups' => array('group_legend_name'), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name', + ), ), ); } diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index 3469d8d178..19e9213262 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_2_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index d3c2200f14..7dd321d83c 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index 67fd1faec6..d73f9587c3 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -36,7 +36,9 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ), ), 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), ), 'add_index' => array( $this->table_prefix . 'sessions' => array( @@ -46,6 +48,24 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array( + 'session_forum_id', + ), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index dff375f438..d671b0cac3 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_3_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 2320c4ac4b..9cce80be74 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -29,6 +29,21 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id', + 'template_inherit_path', + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index 1af4508331..e734814530 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_4_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index e9bb0e01f5..eb2fcb8d0e 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -55,6 +55,17 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 2f80970781..6d61793d08 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_5_rc1part2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 1fab0f8873..354de748c8 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -18,10 +18,10 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration { return array( 'drop_keys' => array( - ACL_OPTIONS_TABLE => array('auth_option'), + $this->table_prefix . 'acl_options' => array('auth_option'), ), 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( + $this->table_prefix . 'acl_options' => array( 'auth_option' => array('auth_option'), ), ), diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index 26176b9437..cc6fccaae2 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc4'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index 35adcf52be..b520bda6d0 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -59,6 +59,46 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'confirm' => array( + 'attempts', + ), + $this->table_prefix . 'users' => array( + 'user_new', + 'user_reminded', + 'user_reminded_time', + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth', + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported', + ), + $this->table_prefix . 'reports' => array( + 'pm_id', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt', + ), + $this->table_prefix . 'forums' => array( + 'forum_options', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'reports' => array( + 'post_id', + 'pm_id', + ), + $this->table_prefix . 'posts' => array( + 'post_username', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index 4092a5fa61..d61c296445 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index ec22d1da77..a3f0dcacdf 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index e748c7a4ff..3855b85551 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc3'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index f27b56f778..59779c9cb0 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index 5543d6437a..5570a5dc06 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index 71584382e8..84b8f798a8 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -18,7 +18,9 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration { return array( 'drop_keys' => array( - $this->table_prefix . 'log' => array('log_time'), + $this->table_prefix . 'log' => array( + 'log_time', + ), ), 'add_index' => array( $this->table_prefix . 'topics_track' => array( @@ -28,6 +30,22 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'log' => array( + 'log_time' => array('log_time'), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index 4e380c810d..48aa818ba3 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index a5defc8278..d94fe869fb 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_8_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index 78db06b512..eb4cc5bd1a 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7_pl1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index eb359e2697..d19a24b45e 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc4'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index ea49cdbba9..4ed48061a4 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -51,6 +51,15 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'login_attempts', + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index e3c4716665..98ef232cb4 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index 3cdecb96ae..b84d61031e 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index c2a92e618a..2a00bba843 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc3'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 2771d82d83..4f7ed07158 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -15,7 +15,7 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration 'phpbb_db_migration_data_3_0_11', 'phpbb_db_migration_data_extensions', 'phpbb_db_migration_data_style_update_p2', - 'phpbb_db_migration_data_timezone', + 'phpbb_db_migration_data_timezone_p2', ); } @@ -23,32 +23,57 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { return array( 'add_columns' => array( - GROUPS_TABLE => array( + $this->table_prefix . 'groups' => array( 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), ), - PROFILE_FIELDS_TABLE => array( + $this->table_prefix . 'profile_fields' => array( 'field_show_on_pm' => array('BOOL', 0), ), - STYLES_TABLE => array( + $this->table_prefix . 'styles' => array( 'style_path' => array('VCHAR:100', ''), 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), 'style_parent_id' => array('UINT:4', 0), 'style_parent_tree' => array('TEXT', ''), ), - REPORTS_TABLE => array( + $this->table_prefix . 'reports' => array( 'reported_post_text' => array('MTEXT_UNI', ''), 'reported_post_uid' => array('VCHAR:8', ''), 'reported_post_bitfield' => array('VCHAR:255', ''), ), ), 'change_columns' => array( - GROUPS_TABLE => array( + $this->table_prefix . 'groups' => array( 'group_legend' => array('UINT', 0), ), ), ); } + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_pm', + ), + $this->table_prefix . 'styles' => array( + 'style_path', + 'bbcode_bitfield', + 'style_parent_id', + 'style_parent_tree', + ), + $this->table_prefix . 'reports' => array( + 'reported_post_text', + 'reported_post_uid', + 'reported_post_bitfield', + ), + ), + ); + } + public function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index b8379483a3..b5f5b792cf 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -18,7 +18,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration { return array( 'add_tables' => array( - EXT_TABLE => array( + $this->table_prefix . 'ext' => array( 'COLUMNS' => array( 'ext_name' => array('VCHAR', ''), 'ext_active' => array('BOOL', 0), @@ -32,6 +32,15 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration ); } + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'ext', + ), + ); + } + public function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index 387b37de8e..f1b26f525a 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_11'); } - public function update_schema() - { - return array(); - } - public function update_data() { return array( @@ -47,10 +42,10 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration } // Get all installed styles - if ($this->db_tools->sql_table_exists(STYLES_IMAGESET_TABLE)) + if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) { $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i WHERE t.template_id = s.template_id AND c.theme_id = s.theme_id AND i.imageset_id = s.imageset_id"; @@ -58,7 +53,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration else { $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c WHERE t.template_id = s.template_id AND c.theme_id = s.theme_id"; } diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index db4b7f1753..361eb5a389 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -18,7 +18,7 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration { return array( 'drop_columns' => array( - STYLES_TABLE => array( + $this->table_prefix . 'styles' => array( 'imageset_id', 'template_id', 'theme_id', @@ -26,17 +26,99 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration ), 'drop_tables' => array( - STYLES_IMAGESET_TABLE, - STYLES_IMAGESET_DATA_TABLE, - STYLES_TEMPLATE_TABLE, - STYLES_TEMPLATE_DATA_TABLE, - STYLES_THEME_TABLE, + $this->table_prefix . 'styles_imageset', + $this->table_prefix . 'styles_imageset_data', + $this->table_prefix . 'styles_template', + $this->table_prefix . 'styles_template_data', + $this->table_prefix . 'styles_theme', ), ); } - public function update_data() + public function revert_schema() { - return array(); + return array( + 'add_columns' => array( + $this->table_prefix . 'styles' => array( + 'imageset_id' => array('UINT', 0), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + ), + ), + + 'add_tables' => array( + $this->table_prefix . 'styles_imageset' => array( + 'COLUMNS' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_name' => array('VCHAR_UNI:255', ''), + 'imageset_copyright' => array('VCHAR_UNI', ''), + 'imageset_path' => array('VCHAR:100', ''), + ), + 'PRIMARY_KEY' => 'imageset_id', + 'KEYS' => array( + 'imgset_nm' => array('UNIQUE', 'imageset_name'), + ), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'COLUMNS' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'image_name' => array('VCHAR:200', ''), + 'image_filename' => array('VCHAR:200', ''), + 'image_lang' => array('VCHAR:30', ''), + 'image_height' => array('USINT', 0), + 'image_width' => array('USINT', 0), + 'imageset_id' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'image_id', + 'KEYS' => array( + 'i_d' => array('INDEX', 'imageset_id'), + ), + ), + $this->table_prefix . 'styles_template' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + 'template_name' => array('VCHAR_UNI:255', ''), + 'template_copyright' => array('VCHAR_UNI', ''), + 'template_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'template_storedb' => array('BOOL', 0), + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + 'PRIMARY_KEY' => 'template_id', + 'KEYS' => array( + 'tmplte_nm' => array('UNIQUE', 'template_name'), + ), + ), + $this->table_prefix . 'styles_template_data' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', 0), + 'template_filename' => array('VCHAR:100', ''), + 'template_included' => array('TEXT', ''), + 'template_mtime' => array('TIMESTAMP', 0), + 'template_data' => array('MTEXT_UNI', ''), + ), + 'KEYS' => array( + 'tid' => array('INDEX', 'template_id'), + 'tfn' => array('INDEX', 'template_filename'), + ), + ), + $this->table_prefix . 'styles_theme' => array( + 'COLUMNS' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + 'theme_name' => array('VCHAR_UNI:255', ''), + 'theme_copyright' => array('VCHAR_UNI', ''), + 'theme_path' => array('VCHAR:100', ''), + 'theme_storedb' => array('BOOL', 0), + 'theme_mtime' => array('TIMESTAMP', 0), + 'theme_data' => array('MTEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'theme_id', + 'KEYS' => array( + 'theme_name' => array('UNIQUE', 'theme_name'), + ), + ), + ), + ); } } diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 7734ed4b76..1a7dfe1e19 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -18,7 +18,7 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { return array( 'change_columns' => array( - USERS_TABLE => array( + $this->table_prefix . 'users' => array( 'user_timezone' => array('VCHAR:100', ''), ), ), @@ -36,13 +36,13 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { // Update user timezones $sql = 'SELECT user_dst, user_timezone - FROM ' . USERS_TABLE . ' + FROM ' . $this->table_prefix . 'users GROUP BY user_timezone, user_dst'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $sql = 'UPDATE ' . USERS_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "users SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' AND user_dst = " . (int) $row['user_dst']; @@ -51,13 +51,10 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration $this->db->sql_freeresult($result); // Update board default timezone - $sql = 'UPDATE ' . CONFIG_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "config SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' WHERE config_name = 'board_timezone'"; $this->sql_query($sql); - - // After we have calculated the timezones we can delete user_dst column from user table. - $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); } /** diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php new file mode 100644 index 0000000000..85c1cf9456 --- /dev/null +++ b/phpBB/includes/db/migration/data/timezone_p2.php @@ -0,0 +1,38 @@ + array( + $this->table_prefix . 'users' => array( + 'user_dst', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst' => array('BOOL', 0), + ), + ), + ); + } +} -- cgit v1.2.1 From 74f4397451dae0ab83d977d97d96ed9549bf3ab9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:28:48 -0600 Subject: [feature/migrations] Make depends_on static to call it without dependencies Move installing migrations to migration/install.php and handle figuring out what migrations have been installed based on phpBB version. PHPBB3-11318 --- phpBB/includes/db/migration/data/3_0_1.php | 4 +- phpBB/includes/db/migration/data/3_0_10.php | 4 +- phpBB/includes/db/migration/data/3_0_10_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_10_rc2.php | 4 +- phpBB/includes/db/migration/data/3_0_10_rc3.php | 4 +- phpBB/includes/db/migration/data/3_0_11.php | 4 +- phpBB/includes/db/migration/data/3_0_11_rc1.php | 8 +- phpBB/includes/db/migration/data/3_0_11_rc2.php | 8 +- phpBB/includes/db/migration/data/3_0_12_rc1.php | 2 +- phpBB/includes/db/migration/data/3_0_1_rc1.php | 15 +-- phpBB/includes/db/migration/data/3_0_2.php | 4 +- phpBB/includes/db/migration/data/3_0_2_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_2_rc2.php | 8 +- phpBB/includes/db/migration/data/3_0_3.php | 4 +- phpBB/includes/db/migration/data/3_0_3_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_4.php | 6 +- phpBB/includes/db/migration/data/3_0_4_rc1.php | 10 +- phpBB/includes/db/migration/data/3_0_5.php | 4 +- phpBB/includes/db/migration/data/3_0_5_rc1.php | 12 +- .../includes/db/migration/data/3_0_5_rc1part2.php | 6 +- phpBB/includes/db/migration/data/3_0_6.php | 4 +- phpBB/includes/db/migration/data/3_0_6_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_6_rc2.php | 4 +- phpBB/includes/db/migration/data/3_0_6_rc3.php | 6 +- phpBB/includes/db/migration/data/3_0_6_rc4.php | 4 +- phpBB/includes/db/migration/data/3_0_7.php | 4 +- phpBB/includes/db/migration/data/3_0_7_pl1.php | 4 +- phpBB/includes/db/migration/data/3_0_7_rc1.php | 10 +- phpBB/includes/db/migration/data/3_0_7_rc2.php | 6 +- phpBB/includes/db/migration/data/3_0_8.php | 4 +- phpBB/includes/db/migration/data/3_0_8_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_9.php | 4 +- phpBB/includes/db/migration/data/3_0_9_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_9_rc2.php | 4 +- phpBB/includes/db/migration/data/3_0_9_rc3.php | 4 +- phpBB/includes/db/migration/data/3_0_9_rc4.php | 4 +- phpBB/includes/db/migration/data/3_1_0_dev.php | 2 +- phpBB/includes/db/migration/data/extensions.php | 2 +- .../includes/db/migration/data/style_update_p1.php | 2 +- .../includes/db/migration/data/style_update_p2.php | 2 +- phpBB/includes/db/migration/data/timezone.php | 2 +- phpBB/includes/db/migration/data/timezone_p2.php | 2 +- phpBB/includes/db/migration/install.php | 129 +++++++++++++++++++++ 43 files changed, 245 insertions(+), 121 deletions(-) create mode 100644 phpBB/includes/db/migration/install.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index d71288c64b..a9eac6f110 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.1')), diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 17472562f2..89afb8a432 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc3'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.10')), diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index eebee44e39..ca8fadec61 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9'); } - function update_data() + public function update_data() { return array( array('config.add', array('email_max_chunk_size', 50)), diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index b81fde9bcb..1f39ea48e0 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.10-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index d97b0b4aec..cd82bb573e 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.10-rc3')), diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index b149cd374c..9f25f0e489 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.11')), diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 3d4920bf49..676e6baa87 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), @@ -24,7 +24,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration ); } - function cleanup_deactivated_styles() + public function cleanup_deactivated_styles() { // Updates users having current style a deactivated one $sql = 'SELECT style_id @@ -48,7 +48,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration } } - function delete_orphan_private_messages() + public function delete_orphan_private_messages() { // Delete orphan private messages $batch_size = 500; diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php index e0638f02d7..e5bb3e44a6 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc1'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -25,7 +25,7 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -36,7 +36,7 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.11-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 0b35de2ed5..4fe0828716 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -11,7 +11,7 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index a7af5d052d..9f1c04809d 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -9,12 +9,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration { - function depends_on() - { - return array(); - } - - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -41,7 +36,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -68,7 +63,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'fix_unset_last_view_time'))), @@ -78,7 +73,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ); } - function fix_unset_last_view_time() + public function fix_unset_last_view_time() { $sql = 'UPDATE ' . $this->table_prefix . "topics SET topic_last_view_time = topic_last_post_time @@ -86,7 +81,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function reset_smiley_size() + public function reset_smiley_size() { // Update smiley sizes $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index 19e9213262..8661578281 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.2')), diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index 7dd321d83c..851060c3b5 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1'); } - function update_data() + public function update_data() { return array( array('config.add', array('referer_validation', '1')), diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index d73f9587c3..c255e55aef 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc1'); } - function update_schema() + public function update_schema() { return array( 'change_columns' => array( @@ -48,7 +48,7 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'add_index' => array( @@ -66,7 +66,7 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.2-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index d671b0cac3..2873c798fd 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.3')), diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 9cce80be74..49e4170c3f 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -29,7 +29,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -44,7 +44,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('enable_queue_trigger', '0')), @@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } - function correct_acp_email_permissions() + public function correct_acp_email_permissions() { $sql = 'UPDATE ' . $this->table_prefix . 'modules SET module_auth = \'acl_a_email && cfg_email_enable\' @@ -68,7 +68,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function set_group_default_max_recipients() + public function set_group_default_max_recipients() { // Set maximum number of recipients for the registered users, bots, guests group $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index e734814530..590ae3c69f 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4_rc1'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'rename_log_delete_topic'))), @@ -23,7 +23,7 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration ); } - function rename_log_delete_topic() + public function rename_log_delete_topic() { if ($this->db->sql_layer == 'oracle') { diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index eb2fcb8d0e..8f44baf046 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -55,7 +55,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -66,7 +66,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_custom_profile_fields'))), @@ -75,7 +75,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } - function update_custom_profile_fields() + public function update_custom_profile_fields() { // Update the Custom Profile Fields based on previous settings to the new format $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 6d61793d08..65b292207e 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1part2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.5')), diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php index cbf28c0be6..a0893a0dbb 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4'); } - function update_schema() + public function update_schema() { return array( 'change_columns' => array( @@ -25,7 +25,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { $search_indexing_state = $this->config['search_indexing_state']; @@ -42,7 +42,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration ); } - function hash_old_passwords() + public function hash_old_passwords() { $sql = 'SELECT user_id, user_password FROM ' . $this->table_prefix . 'users @@ -63,7 +63,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $this->db->sql_freeresult($result); } - function update_ichiro_bot() + public function update_ichiro_bot() { // Adjust bot entry $sql = 'UPDATE ' . $this->table_prefix . "bots @@ -72,7 +72,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function remove_duplicate_auth_options() + public function remove_duplicate_auth_options() { // Before we are able to add a unique key to auth_option, we need to remove duplicate entries $sql = 'SELECT auth_option diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 354de748c8..0597fc0ff8 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1'); } - function update_schema() + public function update_schema() { return array( 'drop_keys' => array( @@ -28,7 +28,7 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.5-rc1')), diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index cc6fccaae2..a7b88e510a 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc4'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.6')), diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index b520bda6d0..5ebeceeed7 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -99,7 +99,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), @@ -184,14 +184,14 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } - function set_user_options_default() + public function set_user_options_default() { // 229376 is the added value to enable all three signature options $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; $this->sql_query($sql); } - function add_newly_registered_group() + public function add_newly_registered_group() { // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) $sql = 'SELECT group_id diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index d61c296445..7cbda4c616 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.6-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index a3f0dcacdf..209057ec70 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc2'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_cp_fields'))), @@ -23,7 +23,7 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration ); } - function update_cp_fields() + public function update_cp_fields() { // Update the Custom Profile Fields based on previous settings to the new format $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index 3855b85551..62f0e91a7d 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc3'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.6-rc4')), diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index 59779c9cb0..3e215ff905 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.7')), diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index 5570a5dc06..ffe0836d02 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.7-pl1')), diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index 84b8f798a8..b30830c21d 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6'); } - function update_schema() + public function update_schema() { return array( 'drop_keys' => array( @@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'add_index' => array( @@ -46,7 +46,7 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('feed_overall', 1)), @@ -61,7 +61,7 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } - function delete_text_templates() + public function delete_text_templates() { // Delete all text-templates from the template_data $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index 48aa818ba3..e986be23bf 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc1'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_email_hash'))), @@ -23,7 +23,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration ); } - function update_email_hash($start = 0) + public function update_email_hash($start = 0) { $limit = 1000; diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index d94fe869fb..8043b934b0 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.8')), diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index eb4cc5bd1a..8214f44f17 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_pl1'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_file_extension_group_names'))), @@ -37,7 +37,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration ); } - function update_file_extension_group_names() + public function update_file_extension_group_names() { // Update file extension group names to use language strings. $sql = 'SELECT lang_dir @@ -93,7 +93,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration $this->db->sql_freeresult($result); } - function update_module_auth() + public function update_module_auth() { $sql = 'UPDATE ' . MODULES_TABLE . ' SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' @@ -103,7 +103,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function update_bots() + public function update_bots() { $bot_name = 'Bing [Bot]'; $bot_name_clean = utf8_clean_string($bot_name); @@ -167,7 +167,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration } } - function delete_orphan_shadow_topics() + public function delete_orphan_shadow_topics() { // Delete shadow topics pointing to not existing topics $batch_size = 500; diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index d19a24b45e..c562f1f2cf 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc4'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9')), diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index 4ed48061a4..367bb25734 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8'); } - function update_schema() + public function update_schema() { return array( 'add_tables' => array( @@ -51,7 +51,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_tables' => array( @@ -60,7 +60,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('ip_login_limit_max', 50)), @@ -73,7 +73,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } - function update_file_extension_group_names() + public function update_file_extension_group_names() { // Update file extension group names to use language strings, again. $sql = 'SELECT group_id, group_name @@ -95,7 +95,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration $this->db->sql_freeresult($result); } - function fix_firebird_qa_captcha() + public function fix_firebird_qa_captcha() { // Recover from potentially broken Q&A CAPTCHA table on firebird // Q&A CAPTCHA was uninstallable, so it's safe to remove these diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index 98ef232cb4..c8566d54a5 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index b84d61031e..da977e9666 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9-rc3')), diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index 2a00bba843..0bfe26985c 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc3'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9-rc4')), diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 4f7ed07158..14953591d1 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array( 'phpbb_db_migration_data_3_0_11', diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index b5f5b792cf..ff54d0d933 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index f1b26f525a..701afc0d78 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index 361eb5a389..1a8cc9da58 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_style_update_p1'); } diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 1a7dfe1e19..3658120629 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php index 85c1cf9456..15f1a3e414 100644 --- a/phpBB/includes/db/migration/data/timezone_p2.php +++ b/phpBB/includes/db/migration/data/timezone_p2.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_timezone_p2 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_timezone'); } diff --git a/phpBB/includes/db/migration/install.php b/phpBB/includes/db/migration/install.php new file mode 100644 index 0000000000..af2ba392b1 --- /dev/null +++ b/phpBB/includes/db/migration/install.php @@ -0,0 +1,129 @@ + 'phpbb_db_migration_data_3_0_1_rc1', + '3.0.1' => 'phpbb_db_migration_data_3_0_1', + '3.0.2-rc1' => 'phpbb_db_migration_data_3_0_2_rc1', + '3.0.2-rc2' => 'phpbb_db_migration_data_3_0_2_rc2', + '3.0.2' => 'phpbb_db_migration_data_3_0_2', + '3.0.3-rc1' => 'phpbb_db_migration_data_3_0_3_rc1', + '3.0.3' => 'phpbb_db_migration_data_3_0_3', + '3.0.4-rc1' => 'phpbb_db_migration_data_3_0_4_rc1', + '3.0.4' => 'phpbb_db_migration_data_3_0_4', + '3.0.5-rc1' => array( + 'phpbb_db_migration_data_3_0_5_rc1', + 'phpbb_db_migration_data_3_0_5_rc1part2', + ), + '3.0.5' => 'phpbb_db_migration_data_3_0_5', + '3.0.6-rc1' => 'phpbb_db_migration_data_3_0_6_rc1', + '3.0.6-rc2' => 'phpbb_db_migration_data_3_0_6_rc2', + '3.0.6-rc3' => 'phpbb_db_migration_data_3_0_6_rc3', + '3.0.6-rc4' => 'phpbb_db_migration_data_3_0_6_rc4', + '3.0.6' => 'phpbb_db_migration_data_3_0_6', + '3.0.7-rc1' => 'phpbb_db_migration_data_3_0_7_rc1', + '3.0.7-rc2' => 'phpbb_db_migration_data_3_0_7_rc2', + '3.0.7' => 'phpbb_db_migration_data_3_0_7', + '3.0.7-pl1' => 'phpbb_db_migration_data_3_0_7_pl1', + '3.0.8-rc1' => 'phpbb_db_migration_data_3_0_8_rc1', + '3.0.8' => 'phpbb_db_migration_data_3_0_8', + '3.0.9-rc1' => 'phpbb_db_migration_data_3_0_9_rc1', + '3.0.9-rc2' => 'phpbb_db_migration_data_3_0_9_rc2', + '3.0.9-rc3' => 'phpbb_db_migration_data_3_0_9_rc3', + '3.0.9-rc4' => 'phpbb_db_migration_data_3_0_9_rc4', + '3.0.9' => 'phpbb_db_migration_data_3_0_9', + '3.0.10-rc1' => 'phpbb_db_migration_data_3_0_10_rc1', + '3.0.10-rc2' => 'phpbb_db_migration_data_3_0_10_rc2', + '3.0.10-rc3' => 'phpbb_db_migration_data_3_0_10_rc3', + '3.0.10' => 'phpbb_db_migration_data_3_0_10', + '3.0.11-rc1' => 'phpbb_db_migration_data_3_0_11_rc1', + '3.0.11-rc2' => 'phpbb_db_migration_data_3_0_11_rc2', + '3.0.11' => 'phpbb_db_migration_data_3_0_11', + '3.0.12-rc1' => 'phpbb_db_migration_data_3_0_12_rc1', + '3.1.0-dev' => array( + 'phpbb_db_migration_data_style_update_p1', + 'phpbb_db_migration_data_style_update_p2', + 'phpbb_db_migration_data_timezone', + 'phpbb_db_migration_data_timezone_p2', + 'phpbb_db_migration_data_extensions', + 'phpbb_db_migration_data_3_1_0_dev', + ), + ); + + public function install(phpbb_db_driver $db, phpbb_db_tools $db_tools, $table_prefix, $version) + { + $this->create_table($db_tools); + + $this->guess_installed_migrations($db, $table_prefix, $version); + } + + protected function create_table(phpbb_db_tools $db_tools) + { + if (!$db_tools->sql_table_exists(MIGRATIONS_TABLE)) + { + $db_tools->sql_create_table(MIGRATIONS_TABLE, array( + 'COLUMNS' => array( + 'migration_name' => array('VCHAR', ''), + 'migration_depends_on' => array('TEXT', ''), + 'migration_schema_done' => array('BOOL', 0), + 'migration_data_done' => array('BOOL', 0), + 'migration_data_state' => array('TEXT', ''), + 'migration_start_time' => array('TIMESTAMP', 0), + 'migration_end_time' => array('TIMESTAMP', 0), + ), + 'PRIMARY_KEY' => 'migration_name', + )); + } + } + + /** + * Guess what migrations have been installed based on phpBB version + * + * @param mixed $version + */ + protected function guess_installed_migrations(phpbb_db_driver $db, $table_prefix, $version) + { + $installed = array(); + foreach ($this->version_to_migration as $compare => $migration_list) + { + if (version_compare($version, $compare, '<=')) + { + // The migration should have effectively been installed already + if (!is_array($migration_list)) + { + $migration_list = array($migration_list); + } + + foreach ($migration_list as $migration_name) + { + $sql_ary = array( + 'migration_name' => $migration_name, + 'migration_depends_on' => $migration_name::depends_on(), + 'migration_schema_done' => 1, + 'migration_data_done' => 1, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, + ); + $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . + $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + } + } +} -- cgit v1.2.1 From 8baceacc36f06c2c14d4a4c08cecb3c80b3c76d3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:45:26 -0600 Subject: [feature/migrations] Fix migrations installer, schema for schema_data.sql PHPBB3-11318 --- phpBB/includes/db/migration/install.php | 43 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/install.php b/phpBB/includes/db/migration/install.php index af2ba392b1..95f3a3b994 100644 --- a/phpBB/includes/db/migration/install.php +++ b/phpBB/includes/db/migration/install.php @@ -66,16 +66,16 @@ class phpbb_db_migration_install public function install(phpbb_db_driver $db, phpbb_db_tools $db_tools, $table_prefix, $version) { - $this->create_table($db_tools); + $this->create_table($db_tools, $table_prefix); $this->guess_installed_migrations($db, $table_prefix, $version); } - protected function create_table(phpbb_db_tools $db_tools) + protected function create_table(phpbb_db_tools $db_tools, $table_prefix) { - if (!$db_tools->sql_table_exists(MIGRATIONS_TABLE)) + if (!$db_tools->sql_table_exists($table_prefix . 'migrations')) { - $db_tools->sql_create_table(MIGRATIONS_TABLE, array( + $db_tools->sql_create_table($table_prefix . 'migrations', array( 'COLUMNS' => array( 'migration_name' => array('VCHAR', ''), 'migration_depends_on' => array('TEXT', ''), @@ -100,7 +100,7 @@ class phpbb_db_migration_install $installed = array(); foreach ($this->version_to_migration as $compare => $migration_list) { - if (version_compare($version, $compare, '<=')) + if (version_compare($version, $compare, '>=')) { // The migration should have effectively been installed already if (!is_array($migration_list)) @@ -110,18 +110,27 @@ class phpbb_db_migration_install foreach ($migration_list as $migration_name) { - $sql_ary = array( - 'migration_name' => $migration_name, - 'migration_depends_on' => $migration_name::depends_on(), - 'migration_schema_done' => 1, - 'migration_data_done' => 1, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, - ); - $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . - $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); + $sql = 'SELECT 1 FROM ' . $table_prefix . "migrations + WHERE migration_name = '" . $db->sql_escape($migration_name) . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + $sql_ary = array( + 'migration_name' => $migration_name, + 'migration_depends_on' => serialize($migration_name::depends_on()), + 'migration_schema_done' => 1, + 'migration_data_done' => 1, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, + ); + $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . + $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } } } } -- cgit v1.2.1 From dfcf9966e95fce074a5ed6eb4036393f5b62de7c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 12 Jan 2013 19:45:20 -0600 Subject: [feature/migrations] Comments for the return in the custom functions PHPBB3-11318 --- phpBB/includes/db/migration/data/3_0_11_rc1.php | 1 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 1 + 2 files changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 676e6baa87..43e0156760 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -83,6 +83,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); $this->sql_query($sql); + // Return false to have the Migrator call this function again return false; } } diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index e986be23bf..c2720b532f 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -62,6 +62,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration return; } + // Return the next start, will be sent to $start when this function is called again return $start + $limit; } } -- cgit v1.2.1 From 5e69e1a7612a4dbe24620cc5cad33720cb0c2885 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:23:02 -0600 Subject: [feature/migrations] effectively installed check for migration data PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 5 + phpBB/includes/db/migration/data/3_0_10.php | 5 + phpBB/includes/db/migration/data/3_0_10_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_10_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_10_rc3.php | 5 + phpBB/includes/db/migration/data/3_0_11.php | 5 + phpBB/includes/db/migration/data/3_0_11_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_11_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_12_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_1_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_2.php | 5 + phpBB/includes/db/migration/data/3_0_2_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_2_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_3.php | 5 + phpBB/includes/db/migration/data/3_0_3_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_4.php | 5 + phpBB/includes/db/migration/data/3_0_4_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_5.php | 5 + phpBB/includes/db/migration/data/3_0_5_rc1.php | 5 + .../includes/db/migration/data/3_0_5_rc1part2.php | 5 + phpBB/includes/db/migration/data/3_0_6.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc3.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc4.php | 5 + phpBB/includes/db/migration/data/3_0_7.php | 5 + phpBB/includes/db/migration/data/3_0_7_pl1.php | 5 + phpBB/includes/db/migration/data/3_0_7_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_8.php | 5 + phpBB/includes/db/migration/data/3_0_8_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_9.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc3.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc4.php | 5 + phpBB/includes/db/migration/data/3_1_0_dev.php | 5 + phpBB/includes/db/migration/data/extensions.php | 5 + .../includes/db/migration/data/style_update_p1.php | 5 + .../includes/db/migration/data/style_update_p2.php | 5 + phpBB/includes/db/migration/data/timezone.php | 5 + phpBB/includes/db/migration/data/timezone_p2.php | 5 + phpBB/includes/db/migration/install.php | 138 --------------------- 43 files changed, 210 insertions(+), 138 deletions(-) delete mode 100644 phpBB/includes/db/migration/install.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index a9eac6f110..8b7c6f0f7c 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 89afb8a432..b24a876bac 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc3'); diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index ca8fadec61..46b7db4e59 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9'); diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index 1f39ea48e0..5e85467202 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index cd82bb573e..6ff81f7776 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10-rc3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index 9f25f0e489..1a63508593 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.11', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 43e0156760..19703bcc35 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.11-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10'); diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php index e5bb3e44a6..219d44c4e0 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.11-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 4fe0828716..c23e8b24b8 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -11,6 +11,11 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.12-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index 9f1c04809d..2fc2849d04 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.1-rc1', '>='); + } + public function update_schema() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index 8661578281..8aa975f779 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index 851060c3b5..6081cd682c 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.2-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1'); diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index c255e55aef..bb76c270d7 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.2-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index 2873c798fd..82039a109b 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 49e4170c3f..5e300962b7 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.3-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2'); diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index 590ae3c69f..34af9fa4ae 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.4', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index 8f44baf046..f63bebcf75 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.4-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3'); diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 65b292207e..077ed251d2 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.5', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1part2'); diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php index a0893a0dbb..df85ee4f7d 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.5-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4'); diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 0597fc0ff8..d2fad7a7f8 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.5-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index a7b88e510a..1b0cbb1435 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc4'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index 5ebeceeed7..0f85084e65 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index 7cbda4c616..a9c497b3cd 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index 209057ec70..eca19fc2ff 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index 62f0e91a7d..19611d3c56 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc4', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc3'); diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index 3e215ff905..97cdf4e3f1 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index ffe0836d02..176854a8a6 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7-pl1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7'); diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index b30830c21d..daf52213b9 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6'); diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index c2720b532f..8167d8fa40 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index 8043b934b0..25baaf0f07 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.8', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index 8214f44f17..13e68a7953 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.8-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_pl1'); diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index c562f1f2cf..b35350dbb5 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc4'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index 367bb25734..be6ced2566 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index c8566d54a5..0bec42a8de 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index da977e9666..a339670932 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index 0bfe26985c..ab5c302611 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc4', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc3'); diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 14953591d1..ac8882cb3a 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.1.0-dev', '>='); + } + static public function depends_on() { return array( diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index ff54d0d933..f077741883 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration { + public function effectively_installed() + { + return $this->db_tools->sql_table_exists($this->table_prefix . 'ext'); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index 701afc0d78..7506b7c49b 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index 1a8cc9da58..ef13f45d9b 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + static public function depends_on() { return array('phpbb_db_migration_data_style_update_p1'); diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 3658120629..66085b8872 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php index 15f1a3e414..38347a0c63 100644 --- a/phpBB/includes/db/migration/data/timezone_p2.php +++ b/phpBB/includes/db/migration/data/timezone_p2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_timezone_p2 extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + static public function depends_on() { return array('phpbb_db_migration_data_timezone'); diff --git a/phpBB/includes/db/migration/install.php b/phpBB/includes/db/migration/install.php deleted file mode 100644 index 95f3a3b994..0000000000 --- a/phpBB/includes/db/migration/install.php +++ /dev/null @@ -1,138 +0,0 @@ - 'phpbb_db_migration_data_3_0_1_rc1', - '3.0.1' => 'phpbb_db_migration_data_3_0_1', - '3.0.2-rc1' => 'phpbb_db_migration_data_3_0_2_rc1', - '3.0.2-rc2' => 'phpbb_db_migration_data_3_0_2_rc2', - '3.0.2' => 'phpbb_db_migration_data_3_0_2', - '3.0.3-rc1' => 'phpbb_db_migration_data_3_0_3_rc1', - '3.0.3' => 'phpbb_db_migration_data_3_0_3', - '3.0.4-rc1' => 'phpbb_db_migration_data_3_0_4_rc1', - '3.0.4' => 'phpbb_db_migration_data_3_0_4', - '3.0.5-rc1' => array( - 'phpbb_db_migration_data_3_0_5_rc1', - 'phpbb_db_migration_data_3_0_5_rc1part2', - ), - '3.0.5' => 'phpbb_db_migration_data_3_0_5', - '3.0.6-rc1' => 'phpbb_db_migration_data_3_0_6_rc1', - '3.0.6-rc2' => 'phpbb_db_migration_data_3_0_6_rc2', - '3.0.6-rc3' => 'phpbb_db_migration_data_3_0_6_rc3', - '3.0.6-rc4' => 'phpbb_db_migration_data_3_0_6_rc4', - '3.0.6' => 'phpbb_db_migration_data_3_0_6', - '3.0.7-rc1' => 'phpbb_db_migration_data_3_0_7_rc1', - '3.0.7-rc2' => 'phpbb_db_migration_data_3_0_7_rc2', - '3.0.7' => 'phpbb_db_migration_data_3_0_7', - '3.0.7-pl1' => 'phpbb_db_migration_data_3_0_7_pl1', - '3.0.8-rc1' => 'phpbb_db_migration_data_3_0_8_rc1', - '3.0.8' => 'phpbb_db_migration_data_3_0_8', - '3.0.9-rc1' => 'phpbb_db_migration_data_3_0_9_rc1', - '3.0.9-rc2' => 'phpbb_db_migration_data_3_0_9_rc2', - '3.0.9-rc3' => 'phpbb_db_migration_data_3_0_9_rc3', - '3.0.9-rc4' => 'phpbb_db_migration_data_3_0_9_rc4', - '3.0.9' => 'phpbb_db_migration_data_3_0_9', - '3.0.10-rc1' => 'phpbb_db_migration_data_3_0_10_rc1', - '3.0.10-rc2' => 'phpbb_db_migration_data_3_0_10_rc2', - '3.0.10-rc3' => 'phpbb_db_migration_data_3_0_10_rc3', - '3.0.10' => 'phpbb_db_migration_data_3_0_10', - '3.0.11-rc1' => 'phpbb_db_migration_data_3_0_11_rc1', - '3.0.11-rc2' => 'phpbb_db_migration_data_3_0_11_rc2', - '3.0.11' => 'phpbb_db_migration_data_3_0_11', - '3.0.12-rc1' => 'phpbb_db_migration_data_3_0_12_rc1', - '3.1.0-dev' => array( - 'phpbb_db_migration_data_style_update_p1', - 'phpbb_db_migration_data_style_update_p2', - 'phpbb_db_migration_data_timezone', - 'phpbb_db_migration_data_timezone_p2', - 'phpbb_db_migration_data_extensions', - 'phpbb_db_migration_data_3_1_0_dev', - ), - ); - - public function install(phpbb_db_driver $db, phpbb_db_tools $db_tools, $table_prefix, $version) - { - $this->create_table($db_tools, $table_prefix); - - $this->guess_installed_migrations($db, $table_prefix, $version); - } - - protected function create_table(phpbb_db_tools $db_tools, $table_prefix) - { - if (!$db_tools->sql_table_exists($table_prefix . 'migrations')) - { - $db_tools->sql_create_table($table_prefix . 'migrations', array( - 'COLUMNS' => array( - 'migration_name' => array('VCHAR', ''), - 'migration_depends_on' => array('TEXT', ''), - 'migration_schema_done' => array('BOOL', 0), - 'migration_data_done' => array('BOOL', 0), - 'migration_data_state' => array('TEXT', ''), - 'migration_start_time' => array('TIMESTAMP', 0), - 'migration_end_time' => array('TIMESTAMP', 0), - ), - 'PRIMARY_KEY' => 'migration_name', - )); - } - } - - /** - * Guess what migrations have been installed based on phpBB version - * - * @param mixed $version - */ - protected function guess_installed_migrations(phpbb_db_driver $db, $table_prefix, $version) - { - $installed = array(); - foreach ($this->version_to_migration as $compare => $migration_list) - { - if (version_compare($version, $compare, '>=')) - { - // The migration should have effectively been installed already - if (!is_array($migration_list)) - { - $migration_list = array($migration_list); - } - - foreach ($migration_list as $migration_name) - { - $sql = 'SELECT 1 FROM ' . $table_prefix . "migrations - WHERE migration_name = '" . $db->sql_escape($migration_name) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - $sql_ary = array( - 'migration_name' => $migration_name, - 'migration_depends_on' => serialize($migration_name::depends_on()), - 'migration_schema_done' => 1, - 'migration_data_done' => 1, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, - ); - $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . - $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - } - } - } -} -- cgit v1.2.1 From 747e51491859507ad2f1891df5df4e563c23dd57 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 14 Jan 2013 12:38:14 -0600 Subject: [feature/migrations] Reports table schema changes in recent develop PHPBB3-9737 --- phpBB/includes/db/migration/data/3_1_0_dev.php | 1 + .../db/migration/data/reported_posts_display.php | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 phpBB/includes/db/migration/data/reported_posts_display.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index ac8882cb3a..8b437104e0 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -21,6 +21,7 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration 'phpbb_db_migration_data_extensions', 'phpbb_db_migration_data_style_update_p2', 'phpbb_db_migration_data_timezone_p2', + 'phpbb_db_migration_data_reported_posts_display', ); } diff --git a/phpBB/includes/db/migration/data/reported_posts_display.php b/phpBB/includes/db/migration/data/reported_posts_display.php new file mode 100644 index 0000000000..fa605e28e5 --- /dev/null +++ b/phpBB/includes/db/migration/data/reported_posts_display.php @@ -0,0 +1,42 @@ +db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode' => array('BOOL', 1), + 'reported_post_enable_smilies' => array('BOOL', 1), + 'reported_post_enable_magic_url' => array('BOOL', 1), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode', + 'reported_post_enable_smilies', + 'reported_post_enable_magic_url', + ), + ), + ); + } +} -- cgit v1.2.1 From 58507f250bf11dda6a138d5f66057ec413750e03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 14 Jan 2013 12:45:01 -0600 Subject: [feature/migrations] Subdirectories for migration data Organization will set you free PHPBB3-9737 --- phpBB/includes/db/migration/data/30x/3_0_1.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_10.php | 28 ++ .../includes/db/migration/data/30x/3_0_10_rc1.php | 30 ++ .../includes/db/migration/data/30x/3_0_10_rc2.php | 28 ++ .../includes/db/migration/data/30x/3_0_10_rc3.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_11.php | 28 ++ .../includes/db/migration/data/30x/3_0_11_rc1.php | 95 +++++ .../includes/db/migration/data/30x/3_0_11_rc2.php | 50 +++ .../includes/db/migration/data/30x/3_0_12_rc1.php | 123 +++++++ phpBB/includes/db/migration/data/30x/3_0_1_rc1.php | 108 ++++++ phpBB/includes/db/migration/data/30x/3_0_2.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_2_rc1.php | 32 ++ phpBB/includes/db/migration/data/30x/3_0_2_rc2.php | 80 ++++ phpBB/includes/db/migration/data/30x/3_0_3.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_3_rc1.php | 83 +++++ phpBB/includes/db/migration/data/30x/3_0_4.php | 49 +++ phpBB/includes/db/migration/data/30x/3_0_4_rc1.php | 123 +++++++ phpBB/includes/db/migration/data/30x/3_0_5.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_5_rc1.php | 124 +++++++ .../db/migration/data/30x/3_0_5_rc1part2.php | 42 +++ phpBB/includes/db/migration/data/30x/3_0_6.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_6_rc1.php | 324 ++++++++++++++++ phpBB/includes/db/migration/data/30x/3_0_6_rc2.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_6_rc3.php | 40 ++ phpBB/includes/db/migration/data/30x/3_0_6_rc4.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_7.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_7_pl1.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_7_rc1.php | 76 ++++ phpBB/includes/db/migration/data/30x/3_0_7_rc2.php | 73 ++++ phpBB/includes/db/migration/data/30x/3_0_8.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_8_rc1.php | 221 +++++++++++ phpBB/includes/db/migration/data/30x/3_0_9.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_9_rc1.php | 124 +++++++ phpBB/includes/db/migration/data/30x/3_0_9_rc2.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_9_rc3.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_9_rc4.php | 28 ++ phpBB/includes/db/migration/data/310/dev.php | 406 +++++++++++++++++++++ .../includes/db/migration/data/310/extensions.php | 69 ++++ .../migration/data/310/reported_posts_display.php | 42 +++ .../db/migration/data/310/style_update_p1.php | 157 ++++++++ .../db/migration/data/310/style_update_p2.php | 129 +++++++ phpBB/includes/db/migration/data/310/timezone.php | 163 +++++++++ .../includes/db/migration/data/310/timezone_p2.php | 43 +++ phpBB/includes/db/migration/data/3_0_1.php | 28 -- phpBB/includes/db/migration/data/3_0_10.php | 28 -- phpBB/includes/db/migration/data/3_0_10_rc1.php | 30 -- phpBB/includes/db/migration/data/3_0_10_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_10_rc3.php | 28 -- phpBB/includes/db/migration/data/3_0_11.php | 28 -- phpBB/includes/db/migration/data/3_0_11_rc1.php | 95 ----- phpBB/includes/db/migration/data/3_0_11_rc2.php | 50 --- phpBB/includes/db/migration/data/3_0_12_rc1.php | 123 ------- phpBB/includes/db/migration/data/3_0_1_rc1.php | 108 ------ phpBB/includes/db/migration/data/3_0_2.php | 28 -- phpBB/includes/db/migration/data/3_0_2_rc1.php | 32 -- phpBB/includes/db/migration/data/3_0_2_rc2.php | 80 ---- phpBB/includes/db/migration/data/3_0_3.php | 28 -- phpBB/includes/db/migration/data/3_0_3_rc1.php | 83 ----- phpBB/includes/db/migration/data/3_0_4.php | 49 --- phpBB/includes/db/migration/data/3_0_4_rc1.php | 123 ------- phpBB/includes/db/migration/data/3_0_5.php | 28 -- phpBB/includes/db/migration/data/3_0_5_rc1.php | 124 ------- .../includes/db/migration/data/3_0_5_rc1part2.php | 42 --- phpBB/includes/db/migration/data/3_0_6.php | 28 -- phpBB/includes/db/migration/data/3_0_6_rc1.php | 324 ---------------- phpBB/includes/db/migration/data/3_0_6_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_6_rc3.php | 40 -- phpBB/includes/db/migration/data/3_0_6_rc4.php | 28 -- phpBB/includes/db/migration/data/3_0_7.php | 28 -- phpBB/includes/db/migration/data/3_0_7_pl1.php | 28 -- phpBB/includes/db/migration/data/3_0_7_rc1.php | 76 ---- phpBB/includes/db/migration/data/3_0_7_rc2.php | 73 ---- phpBB/includes/db/migration/data/3_0_8.php | 28 -- phpBB/includes/db/migration/data/3_0_8_rc1.php | 221 ----------- phpBB/includes/db/migration/data/3_0_9.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc1.php | 124 ------- phpBB/includes/db/migration/data/3_0_9_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc3.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc4.php | 28 -- phpBB/includes/db/migration/data/3_1_0_dev.php | 406 --------------------- phpBB/includes/db/migration/data/extensions.php | 69 ---- .../db/migration/data/reported_posts_display.php | 42 --- .../includes/db/migration/data/style_update_p1.php | 157 -------- .../includes/db/migration/data/style_update_p2.php | 129 ------- phpBB/includes/db/migration/data/timezone.php | 163 --------- phpBB/includes/db/migration/data/timezone_p2.php | 43 --- 86 files changed, 3310 insertions(+), 3310 deletions(-) create mode 100644 phpBB/includes/db/migration/data/30x/3_0_1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_11.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_11_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_4.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_5.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_8.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc4.php create mode 100644 phpBB/includes/db/migration/data/310/dev.php create mode 100644 phpBB/includes/db/migration/data/310/extensions.php create mode 100644 phpBB/includes/db/migration/data/310/reported_posts_display.php create mode 100644 phpBB/includes/db/migration/data/310/style_update_p1.php create mode 100644 phpBB/includes/db/migration/data/310/style_update_p2.php create mode 100644 phpBB/includes/db/migration/data/310/timezone.php create mode 100644 phpBB/includes/db/migration/data/310/timezone_p2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_12_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_1_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_3_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_4.php delete mode 100644 phpBB/includes/db/migration/data/3_0_4_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1part2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc4.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_pl1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_8.php delete mode 100644 phpBB/includes/db/migration/data/3_0_8_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc4.php delete mode 100644 phpBB/includes/db/migration/data/3_1_0_dev.php delete mode 100644 phpBB/includes/db/migration/data/extensions.php delete mode 100644 phpBB/includes/db/migration/data/reported_posts_display.php delete mode 100644 phpBB/includes/db/migration/data/style_update_p1.php delete mode 100644 phpBB/includes/db/migration/data/style_update_p2.php delete mode 100644 phpBB/includes/db/migration/data/timezone.php delete mode 100644 phpBB/includes/db/migration/data/timezone_p2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/30x/3_0_1.php b/phpBB/includes/db/migration/data/30x/3_0_1.php new file mode 100644 index 0000000000..c996a0138a --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_1.php @@ -0,0 +1,28 @@ +config['version'], '3.0.1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_1_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10.php b/phpBB/includes/db/migration/data/30x/3_0_10.php new file mode 100644 index 0000000000..122f93d6b4 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10.php @@ -0,0 +1,28 @@ +config['version'], '3.0.10', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10_rc3'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.10')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php new file mode 100644 index 0000000000..0ed05812dc --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php @@ -0,0 +1,30 @@ +config['version'], '3.0.10-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9'); + } + + public function update_data() + { + return array( + array('config.add', array('email_max_chunk_size', 50)), + + array('config.update', array('version', '3.0.10-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php new file mode 100644 index 0000000000..b14b3b00aa --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.10-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.10-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php b/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php new file mode 100644 index 0000000000..473057d65d --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php @@ -0,0 +1,28 @@ +config['version'], '3.0.10-rc3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.10-rc3')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_11.php b/phpBB/includes/db/migration/data/30x/3_0_11.php new file mode 100644 index 0000000000..e063c699cc --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_11.php @@ -0,0 +1,28 @@ +config['version'], '3.0.11', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.11')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php new file mode 100644 index 0000000000..dddfc0e0e7 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php @@ -0,0 +1,95 @@ +config['version'], '3.0.11-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), + array('custom', array(array(&$this, 'delete_orphan_private_messages'))), + + array('config.update', array('version', '3.0.11-rc1')), + ); + } + + public function cleanup_deactivated_styles() + { + // Updates users having current style a deactivated one + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_active = 0'; + $result = $this->sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $this->db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql); + } + } + + public function delete_orphan_private_messages() + { + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql); + + // Return false to have the Migrator call this function again + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php new file mode 100644 index 0000000000..fac8523e8c --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php @@ -0,0 +1,50 @@ +config['version'], '3.0.11-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11_rc1'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.11-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php new file mode 100644 index 0000000000..6a31a51201 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php @@ -0,0 +1,123 @@ +config['version'], '3.0.12-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_module_auth'))), + array('custom', array(array(&$this, 'update_bots'))), + array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))), + + array('config.update', array('version', '3.0.12-rc1')), + ); + } + + public function disable_bots_from_receiving_pms() + { + // Disable receiving pms for bots + $sql = 'SELECT user_id + FROM ' . BOTS_TABLE; + $result = $this->db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); + $this->sql_query($sql); + } + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_u_sig\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'signature\''; + $this->sql_query($sql); + } + + public function update_bots() + { + // Update bots + if (!function_exists('user_delete')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $bots_updates = array( + // Bot Deletions + 'NG-Search [Bot]' => false, + 'Nutch/CVS [Bot]' => false, + 'OmniExplorer [Bot]' => false, + 'Seekport [Bot]' => false, + 'Synoo [Bot]' => false, + 'WiseNut [Bot]' => false, + + // Bot Updates + // Bot name to bot user agent map + 'Baidu [Spider]' => 'Baiduspider', + 'Exabot [Bot]' => 'Exabot', + 'Voyager [Bot]' => 'voyager/', + 'W3C [Validator]' => 'W3C_Validator', + ); + + foreach ($bots_updates as $bot_name => $bot_agent) + { + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_type = ' . USER_IGNORE . " + AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; + $result = $this->db->sql_query($sql); + $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if ($bot_user_id) + { + if ($bot_agent === false) + { + $sql = 'DELETE FROM ' . BOTS_TABLE . " + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + + user_delete('remove', $bot_user_id); + } + else + { + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php new file mode 100644 index 0000000000..562ccf077c --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php @@ -0,0 +1,108 @@ +config['version'], '3.0.1-rc1', '>='); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array( + 'group_legend', + ), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list', + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + ), + 'add_index' => array( + $this->table_prefix . 'groups' => array( + 'group_legend' => array('group_legend'), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name', + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + + array('config.update', array('version', '3.0.1-rc1')), + ); + } + + public function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + public function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_2.php b/phpBB/includes/db/migration/data/30x/3_0_2.php new file mode 100644 index 0000000000..eed5acef82 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_2_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php new file mode 100644 index 0000000000..a960e90765 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php @@ -0,0 +1,32 @@ +config['version'], '3.0.2-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_1'); + } + + public function update_data() + { + return array( + array('config.add', array('referer_validation', '1')), + array('config.add', array('check_attachment_content', '1')), + array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')), + + array('config.update', array('version', '3.0.2-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php new file mode 100644 index 0000000000..8917dfea77 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php @@ -0,0 +1,80 @@ +config['version'], '3.0.2-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_2_rc1'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array( + 'session_forum_id', + ), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.2-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_3.php b/phpBB/includes/db/migration/data/30x/3_0_3.php new file mode 100644 index 0000000000..8984cf7b76 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_3.php @@ -0,0 +1,28 @@ +config['version'], '3.0.3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_3_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.3')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php new file mode 100644 index 0000000000..4b102e1a2e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php @@ -0,0 +1,83 @@ +config['version'], '3.0.3-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_2'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id', + 'template_inherit_path', + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', $this->db->sql_server_info(true))), + array('permission.add', array('u_masspm_group', true, 'u_masspm')), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + + array('config.update', array('version', '3.0.3-rc1')), + ); + } + + public function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); + } + + public function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_4.php b/phpBB/includes/db/migration/data/30x/3_0_4.php new file mode 100644 index 0000000000..9a0c132e78 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_4.php @@ -0,0 +1,49 @@ +config['version'], '3.0.4', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_4_rc1'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'rename_log_delete_topic'))), + + array('config.update', array('version', '3.0.4')), + ); + } + + public function rename_log_delete_topic() + { + if ($this->db->sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php new file mode 100644 index 0000000000..8ad75a557b --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php @@ -0,0 +1,123 @@ +config['version'], '3.0.4-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_3'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile', + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + + array('config.update', array('version', '3.0.4-rc1')), + ); + } + + public function update_custom_profile_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + + $this->db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_5.php b/phpBB/includes/db/migration/data/30x/3_0_5.php new file mode 100644 index 0000000000..16d2dee457 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_5.php @@ -0,0 +1,28 @@ +config['version'], '3.0.5', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_5_rc1part2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.5')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php new file mode 100644 index 0000000000..ea17cc1e31 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php @@ -0,0 +1,124 @@ +config['version'], '3.0.5-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_4'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + public function update_data() + { + $search_indexing_state = $this->config['search_indexing_state']; + + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_fonts', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } + + public function hash_old_passwords() + { + $sql = 'SELECT user_id, user_password + FROM ' . $this->table_prefix . 'users + WHERE user_pass_convert = 1'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); + } + } + $this->db->sql_freeresult($result); + } + + public function update_ichiro_bot() + { + // Adjust bot entry + $sql = 'UPDATE ' . $this->table_prefix . "bots + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + $this->sql_query($sql); + } + + public function remove_duplicate_auth_options() + { + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + $sql = 'SELECT auth_option + FROM ' . $this->table_prefix . 'acl_options + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $this->db->sql_query($sql); + + $auth_options = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $this->db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $this->db->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $this->db->sql_fetchrow($result); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + } + $this->db->sql_freeresult($result); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php new file mode 100644 index 0000000000..8538347b1a --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php @@ -0,0 +1,42 @@ +config['version'], '3.0.5-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_5_rc1'); + } + + public function update_schema() + { + return array( + 'drop_keys' => array( + $this->table_prefix . 'acl_options' => array('auth_option'), + ), + 'add_unique_index' => array( + $this->table_prefix . 'acl_options' => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.5-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6.php b/phpBB/includes/db/migration/data/30x/3_0_6.php new file mode 100644 index 0000000000..bb651dc7cd --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6.php @@ -0,0 +1,28 @@ +config['version'], '3.0.6', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc4'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.6')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php new file mode 100644 index 0000000000..38c282ebf0 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php @@ -0,0 +1,324 @@ +config['version'], '3.0.6-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_5'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'confirm' => array( + 'attempts', + ), + $this->table_prefix . 'users' => array( + 'user_new', + 'user_reminded', + 'user_reminded_time', + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth', + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported', + ), + $this->table_prefix . 'reports' => array( + 'pm_id', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt', + ), + $this->table_prefix . 'forums' => array( + 'forum_options', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'reports' => array( + 'post_id', + 'pm_id', + ), + $this->table_prefix . 'posts' => array( + 'post_username', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('if', array( + ($this->config['captcha_gd']), + array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + array('config.update', array('allow_avatar', 1)), + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + array('config.update', array('allow_avatar_remote_upload', 1)), + )), + + array('module.add', array( + 'acp', + 'ACP_BOARD_CONFIGURATION', + array( + 'module_basename' => 'acp_board', + 'modes' => array('feed'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_CAT_USERS', + array( + 'module_basename' => 'acp_users', + 'modes' => array('warnings'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_SERVER_CONFIGURATION', + array( + 'module_basename' => 'acp_send_statistics', + 'modes' => array('send_statistics'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_FORUM_BASED_PERMISSIONS', + array( + 'module_basename' => 'acp_permissions', + 'modes' => array('setting_forum_copy'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'mcp_pm_reports', + 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + + array('config.update', array('version', '3.0.6-rc1')), + ); + } + + public function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + + public function add_newly_registered_group() + { + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + $this->sql_query($sql); + + $group_id = $this->db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); + + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); + + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + $this->sql_query($sql); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); + } + $this->db->sql_freeresult($result); + } + + // Clear permissions... + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php new file mode 100644 index 0000000000..a939dbd489 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.6-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.6-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php new file mode 100644 index 0000000000..b3f09d8ab8 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php @@ -0,0 +1,40 @@ +config['version'], '3.0.6-rc3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc2'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_cp_fields'))), + + array('config.update', array('version', '3.0.6-rc3')), + ); + } + + public function update_cp_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' + SET field_show_on_vt = 1 + WHERE field_hide = 0 + AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)'; + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php new file mode 100644 index 0000000000..fc2923f99b --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php @@ -0,0 +1,28 @@ +config['version'], '3.0.6-rc4', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc3'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.6-rc4')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7.php b/phpBB/includes/db/migration/data/30x/3_0_7.php new file mode 100644 index 0000000000..9ff2e9e4ab --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7.php @@ -0,0 +1,28 @@ +config['version'], '3.0.7', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.7')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php b/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php new file mode 100644 index 0000000000..c9cc9d19ac --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php @@ -0,0 +1,28 @@ +config['version'], '3.0.7-pl1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.7-pl1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php new file mode 100644 index 0000000000..ffebf66f2d --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php @@ -0,0 +1,76 @@ +config['version'], '3.0.7-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6'); + } + + public function update_schema() + { + return array( + 'drop_keys' => array( + $this->table_prefix . 'log' => array( + 'log_time', + ), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'log' => array( + 'log_time' => array('log_time'), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + + array('config.update', array('version', '3.0.7-rc1')), + ); + } + + public function delete_text_templates() + { + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php new file mode 100644 index 0000000000..55bc2bc679 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php @@ -0,0 +1,73 @@ +config['version'], '3.0.7-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7_rc1'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_email_hash'))), + + array('config.update', array('version', '3.0.7-rc2')), + ); + } + + public function update_email_hash($start = 0) + { + $limit = 1000; + + $sql = 'SELECT user_id, user_email, user_email_hash + FROM ' . USERS_TABLE . ' + WHERE user_type <> ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + $i = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + $this->sql_query($sql); + } + } + $this->db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return; + } + + // Return the next start, will be sent to $start when this function is called again + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_8.php b/phpBB/includes/db/migration/data/30x/3_0_8.php new file mode 100644 index 0000000000..8998ef9627 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_8.php @@ -0,0 +1,28 @@ +config['version'], '3.0.8', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_8_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.8')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php new file mode 100644 index 0000000000..aeff35333e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php @@ -0,0 +1,221 @@ +config['version'], '3.0.8-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7_pl1'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'update_module_auth'))), + array('custom', array(array(&$this, 'update_bots'))), + array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))), + array('module.add', array( + 'acp', + 'ACP_MESSAGES', + array( + 'module_basename' => 'acp_board', + 'modes' => array('post'), + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), + + array('config.update', array('version', '3.0.8-rc1')), + ); + } + + public function update_file_extension_group_names() + { + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $this->db->sql_freeresult($result); + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + $this->sql_query($sql); + } + + public function update_bots() + { + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + $this->sql_query($sql); + } + } + + public function delete_orphan_shadow_topics() + { + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9.php b/phpBB/includes/db/migration/data/30x/3_0_9.php new file mode 100644 index 0000000000..d5269ea6f0 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc4'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php new file mode 100644 index 0000000000..1f8622798e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php @@ -0,0 +1,124 @@ +config['version'], '3.0.9-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_8'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcodes' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'login_attempts', + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + + array('config.update', array('version', '3.0.9-rc1')), + ); + } + + public function update_file_extension_group_names() + { + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function fix_firebird_qa_captcha() + { + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($this->db_tools->sql_layer == 'firebird') + { + $tables = array( + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($this->db_tools->sql_table_exists($table)) + { + $this->db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php new file mode 100644 index 0000000000..c0e662aa45 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php new file mode 100644 index 0000000000..d6d1f14b2e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9-rc3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9-rc3')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php new file mode 100644 index 0000000000..e673249343 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9-rc4', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc3'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9-rc4')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php new file mode 100644 index 0000000000..f41750e327 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -0,0 +1,406 @@ +config['version'], '3.1.0-dev', '>='); + } + + static public function depends_on() + { + return array( + 'phpbb_db_migration_data_30x_11', + 'phpbb_db_migration_data_310_extensions', + 'phpbb_db_migration_data_310_style_update_p2', + 'phpbb_db_migration_data_310_timezone_p2', + 'phpbb_db_migration_data_310_reported_posts_display', + ); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_pm' => array('BOOL', 0), + ), + $this->table_prefix . 'styles' => array( + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), + ), + $this->table_prefix . 'reports' => array( + 'reported_post_text' => array('MTEXT_UNI', ''), + 'reported_post_uid' => array('VCHAR:8', ''), + 'reported_post_bitfield' => array('VCHAR:255', ''), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_legend' => array('UINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_pm', + ), + $this->table_prefix . 'styles' => array( + 'style_path', + 'bbcode_bitfield', + 'style_parent_id', + 'style_parent_tree', + ), + $this->table_prefix . 'reports' => array( + 'reported_post_text', + 'reported_post_uid', + 'reported_post_bitfield', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + + array('config.add', array('fulltext_postgres_ts_name', 'simple')), + array('config.add', array('fulltext_postgres_min_word_len', 4)), + array('config.add', array('fulltext_postgres_max_word_len', 254)), + array('config.add', array('fulltext_sphinx_stopwords', 0)), + array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), + + array('config.add', array('load_jquery_cdn', 0)), + array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), + + array('config.add', array('use_system_cron', 0)), + + array('config.add', array('legend_sort_groupname', 0)), + array('config.add', array('teampage_forums', 1)), + array('config.add', array('teampage_memberships', 1)), + + array('config.add', array('load_cpf_pm', 0)), + + array('config.add', array('display_last_subject', 1)), + + array('config.add', array('assets_version', 1)), + + array('config.add', array('site_home_url', '')), + array('config.add', array('site_home_text', '')), + + array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), + + array('module.add', array( + 'acp', + 'ACP_GROUPS', + array( + 'module_basename' => 'acp_groups', + 'modes' => array('position'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_ATTACHMENTS', + array( + 'module_basename' => 'acp_attachments', + 'modes' => array('manage'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_STYLE_MANAGEMENT', + array( + 'module_basename' => 'acp_styles', + 'modes' => array('install', 'cache'), + ), + )), + array('module.add', array( + 'ucp', + 'UCP_PROFILE', + array( + 'module_basename' => 'ucp_profile', + 'modes' => array('autologin_keys'), + ), + )), + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_LANGUAGE' + )), + + array('module.remove', array( + 'acp', + false, + 'ACP_TEMPLATES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_THEMES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_IMAGESETS', + )), + + array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'rename_styles_module'))), + array('custom', array(array($this, 'add_group_teampage'))), + array('custom', array(array($this, 'update_group_legend'))), + array('custom', array(array($this, 'localise_global_announcements'))), + array('custom', array(array($this, 'update_ucp_pm_basename'))), + array('custom', array(array($this, 'update_ucp_profile_auth'))), + array('custom', array(array($this, 'move_customise_modules'))), + + array('config.update', array('version', '3.1.0-dev')), + ); + } + + public function move_customise_modules() + { + // Move language management to new location in the Customise tab + // First get language module id + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_basename = 'acp_language'"; + $result = $this->db->sql_query($sql); + $language_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + // Next get language management module id of the one just created + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = 'ACP_LANGUAGE'"; + $result = $this->db->sql_query($sql); + $language_management_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + } + // acp_modules calls adm_back_link, which is undefined at this point + if (!function_exists('adm_back_link')) + { + include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); + } + $module_manager = new acp_modules(); + $module_manager->module_class = 'acp'; + $module_manager->move_module($language_module_id, $language_management_module_id); + } + + public function update_ucp_pm_basename() + { + $sql = 'SELECT module_id, module_basename + FROM ' . MODULES_TABLE . " + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM'"; + $result = $this->db->sql_query_limit($sql, 1); + + if ($row = $this->db->sql_fetchrow($result)) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; + + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_ucp_profile_auth() + { + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'profile_info'"; + $this->sql_query($sql); + } + + public function rename_styles_module() + { + // Rename styles module to Customise + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_langname = 'ACP_CAT_CUSTOMISE' + WHERE module_langname = 'ACP_CAT_STYLES'"; + $this->sql_query($sql); + } + + public function rename_module_basenames() + { + // rename all module basenames to full classname + $sql = 'SELECT module_id, module_basename, module_class + FROM ' . MODULES_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $module_id = (int) $row['module_id']; + unset($row['module_id']); + + if (!empty($row['module_basename']) && !empty($row['module_class'])) + { + // all the class names start with class name or with phpbb_ for auto loading + if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && + strpos($row['module_basename'], 'phpbb_') !== 0) + { + $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; + + $sql_update = $this->db->sql_build_array('UPDATE', $row); + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET ' . $sql_update . ' + WHERE module_id = ' . $module_id; + $this->sql_query($sql); + } + } + } + + $this->db->sql_freeresult($result); + } + + public function add_group_teampage() + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'ADMINISTRATORS'"; + $this->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + $this->sql_query($sql); + } + + public function update_group_legend() + { + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . ' + WHERE group_legend = 1 + ORDER BY group_name ASC'; + $result = $this->db->sql_query($sql); + + $next_legend = 1; + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_legend . ' + WHERE group_id = ' . (int) $row['group_id']; + $this->sql_query($sql); + + $next_legend++; + } + $this->db->sql_freeresult($result); + } + + public function localise_global_announcements() + { + // Localise Global Announcements + $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = 0 + AND topic_type = ' . POST_GLOBAL; + $result = $this->db->sql_query($sql); + + $global_announcements = $update_lastpost_data = array(); + $update_lastpost_data['forum_last_post_time'] = 0; + $update_forum_data = array( + 'forum_posts' => 0, + 'forum_topics' => 0, + 'forum_topics_real' => 0, + ); + + while ($row = $this->db->sql_fetchrow($result)) + { + $global_announcements[] = (int) $row['topic_id']; + + $update_forum_data['forum_posts'] += (int) $row['topic_posts']; + $update_forum_data['forum_topics_real']++; + if ($row['topic_approved']) + { + $update_forum_data['forum_topics']++; + } + + if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) + { + $update_lastpost_data = array( + 'forum_last_post_id' => (int) $row['topic_last_post_id'], + 'forum_last_post_subject' => $row['topic_last_post_subject'], + 'forum_last_post_time' => (int) $row['topic_last_post_time'], + 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], + 'forum_last_poster_name' => $row['topic_last_poster_name'], + 'forum_last_poster_colour' => $row['topic_last_poster_colour'], + ); + } + } + $this->db->sql_freeresult($result); + + if (!empty($global_announcements)) + { + // Update the post/topic-count for the forum and the last-post if needed + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST; + $result = $this->db->sql_query_limit($sql, 1); + $ga_forum_id = $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT forum_last_post_time + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $ga_forum_id; + $result = $this->db->sql_query($sql); + $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); + $this->db->sql_freeresult($result); + + $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; + $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; + $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; + if ($lastpost < $update_lastpost_data['forum_last_post_time']) + { + $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); + } + + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $sql_update . ' + WHERE forum_id = ' . $ga_forum_id; + $this->sql_query($sql); + + // Update some forum_ids + $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); + foreach ($table_ary as $table) + { + $sql = "UPDATE $table + SET forum_id = $ga_forum_id + WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); + $this->sql_query($sql); + } + unset($table_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/310/extensions.php b/phpBB/includes/db/migration/data/310/extensions.php new file mode 100644 index 0000000000..925fa29384 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/extensions.php @@ -0,0 +1,69 @@ +db_tools->sql_table_exists($this->table_prefix . 'ext'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_11'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'ext' => array( + 'COLUMNS' => array( + 'ext_name' => array('VCHAR', ''), + 'ext_active' => array('BOOL', 0), + 'ext_state' => array('TEXT', ''), + ), + 'KEYS' => array( + 'ext_name' => array('UNIQUE', 'ext_name'), + ), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'ext', + ), + ); + } + + public function update_data() + { + return array( + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_EXTENSION_MANAGEMENT' + )), + array('module.add', array( + 'acp', + 'ACP_EXTENSION_MANAGEMENT', + array( + 'module_basename' => 'acp_extensions', + 'modes' => array('main'), + ), + )), + array('permission.add', array('a_extensions', true, 'a_styles')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/reported_posts_display.php b/phpBB/includes/db/migration/data/310/reported_posts_display.php new file mode 100644 index 0000000000..64f0f1aaec --- /dev/null +++ b/phpBB/includes/db/migration/data/310/reported_posts_display.php @@ -0,0 +1,42 @@ +db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode' => array('BOOL', 1), + 'reported_post_enable_smilies' => array('BOOL', 1), + 'reported_post_enable_magic_url' => array('BOOL', 1), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode', + 'reported_post_enable_smilies', + 'reported_post_enable_magic_url', + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/style_update_p1.php b/phpBB/includes/db/migration/data/310/style_update_p1.php new file mode 100644 index 0000000000..d19ccc37cf --- /dev/null +++ b/phpBB/includes/db/migration/data/310/style_update_p1.php @@ -0,0 +1,157 @@ +db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_11'); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'styles_update'))), + ); + } + + public function styles_update() + { + // Get list of valid 3.1 styles + $available_styles = array('prosilver'); + + $iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); + $skip_dirs = array('.', '..', 'prosilver'); + foreach ($iterator as $fileinfo) + { + if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) + { + $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); + if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) + { + // 3.1 style + $available_styles[] = $fileinfo->getFilename(); + } + } + } + + // Get all installed styles + if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + } + else + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id"; + } + $result = $this->db->sql_query($sql); + + $styles = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $styles[] = $row; + } + $this->db->sql_freeresult($result); + + // Decide which styles to keep, all others will be deleted + $valid_styles = array(); + foreach ($styles as $style_row) + { + if ( + // Delete styles with parent style (not supported yet) + $style_row['template_inherits_id'] == 0 && + // Check if components match + $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && + // Check if components are valid + in_array($style_row['template_path'], $available_styles) + ) + { + // Valid style. Keep it + $sql_ary = array( + 'style_path' => $style_row['template_path'], + 'bbcode_bitfield' => $style_row['bbcode_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + ); + $this->sql_query('UPDATE ' . STYLES_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE style_id = ' . $style_row['style_id']); + $valid_styles[] = (int) $style_row['style_id']; + } + } + + // Remove old entries from styles table + if (!sizeof($valid_styles)) + { + // No valid styles: remove everything and add prosilver + $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + + $sql_ary = array( + 'style_name' => 'prosilver', + 'style_copyright' => '© phpBB Group', + 'style_active' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'lNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', + + // Will be removed in the next step + 'imageset_id' => 0, + 'template_id' => 0, + 'theme_id' => 0, + ); + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->sql_query($sql); + + $sql = 'SELECT style_id + FROM ' . $table . " + WHERE style_name = 'prosilver'"; + $result = $this->sql_query($sql); + $default_style = $this->db->sql_fetchfield($result); + $this->db->sql_freeresult($result); + + set_config('default_style', $default_style); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $this->sql_query($sql); + } + else + { + // There are valid styles in styles table. Remove styles that are outdated + $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' + WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); + + // Change default style + if (!in_array($this->config['default_style'], $valid_styles)) + { + $this->sql_query('UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $valid_styles[0] . "' + WHERE config_name = 'default_style'"); + } + + // Reset styles for users + $this->sql_query('UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); + } + } +} diff --git a/phpBB/includes/db/migration/data/310/style_update_p2.php b/phpBB/includes/db/migration/data/310/style_update_p2.php new file mode 100644 index 0000000000..7b10518a66 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/style_update_p2.php @@ -0,0 +1,129 @@ +db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_style_update_p1'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'styles' => array( + 'imageset_id', + 'template_id', + 'theme_id', + ), + ), + + 'drop_tables' => array( + $this->table_prefix . 'styles_imageset', + $this->table_prefix . 'styles_imageset_data', + $this->table_prefix . 'styles_template', + $this->table_prefix . 'styles_template_data', + $this->table_prefix . 'styles_theme', + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'styles' => array( + 'imageset_id' => array('UINT', 0), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + ), + ), + + 'add_tables' => array( + $this->table_prefix . 'styles_imageset' => array( + 'COLUMNS' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_name' => array('VCHAR_UNI:255', ''), + 'imageset_copyright' => array('VCHAR_UNI', ''), + 'imageset_path' => array('VCHAR:100', ''), + ), + 'PRIMARY_KEY' => 'imageset_id', + 'KEYS' => array( + 'imgset_nm' => array('UNIQUE', 'imageset_name'), + ), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'COLUMNS' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'image_name' => array('VCHAR:200', ''), + 'image_filename' => array('VCHAR:200', ''), + 'image_lang' => array('VCHAR:30', ''), + 'image_height' => array('USINT', 0), + 'image_width' => array('USINT', 0), + 'imageset_id' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'image_id', + 'KEYS' => array( + 'i_d' => array('INDEX', 'imageset_id'), + ), + ), + $this->table_prefix . 'styles_template' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + 'template_name' => array('VCHAR_UNI:255', ''), + 'template_copyright' => array('VCHAR_UNI', ''), + 'template_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'template_storedb' => array('BOOL', 0), + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + 'PRIMARY_KEY' => 'template_id', + 'KEYS' => array( + 'tmplte_nm' => array('UNIQUE', 'template_name'), + ), + ), + $this->table_prefix . 'styles_template_data' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', 0), + 'template_filename' => array('VCHAR:100', ''), + 'template_included' => array('TEXT', ''), + 'template_mtime' => array('TIMESTAMP', 0), + 'template_data' => array('MTEXT_UNI', ''), + ), + 'KEYS' => array( + 'tid' => array('INDEX', 'template_id'), + 'tfn' => array('INDEX', 'template_filename'), + ), + ), + $this->table_prefix . 'styles_theme' => array( + 'COLUMNS' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + 'theme_name' => array('VCHAR_UNI:255', ''), + 'theme_copyright' => array('VCHAR_UNI', ''), + 'theme_path' => array('VCHAR:100', ''), + 'theme_storedb' => array('BOOL', 0), + 'theme_mtime' => array('TIMESTAMP', 0), + 'theme_data' => array('MTEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'theme_id', + 'KEYS' => array( + 'theme_name' => array('UNIQUE', 'theme_name'), + ), + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/timezone.php b/phpBB/includes/db/migration/data/310/timezone.php new file mode 100644 index 0000000000..7a6a9bce05 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/timezone.php @@ -0,0 +1,163 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_11'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_timezone' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_timezones'))), + ); + } + + public function update_timezones() + { + // Update user timezones + $sql = 'SELECT user_dst, user_timezone + FROM ' . $this->table_prefix . 'users + GROUP BY user_timezone, user_dst'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "users + SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' + WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' + AND user_dst = " . (int) $row['user_dst']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + + // Update board default timezone + $sql = 'UPDATE ' . $this->table_prefix . "config + SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' + WHERE config_name = 'board_timezone'"; + $this->sql_query($sql); + } + + /** + * Determine the new timezone for a given phpBB 3.0 timezone and + * "Daylight Saving Time" option + * + * @param $timezone float Users timezone in 3.0 + * @param $dst int Users daylight saving time + * @return string Users new php Timezone which is used since 3.1 + */ + public function convert_phpbb30_timezone($timezone, $dst) + { + $offset = $timezone + $dst; + + switch ($timezone) + { + case '-12': + return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' + case '-11': + return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' + case '-10': + return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' + case '-9.5': + return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' + case '-9': + return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' + case '-8': + return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' + case '-7': + return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' + case '-6': + return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' + case '-5': + return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' + case '-4.5': + return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' + case '-4': + return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' + case '-3.5': + return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' + case '-3': + return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' + case '-2': + return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' + case '-1': + return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' + case '0': + return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' + case '1': + return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' + case '2': + return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' + case '3': + return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' + case '3.5': + return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' + case '4': + return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' + case '4.5': + return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' + case '5': + return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' + case '5.5': + return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' + case '5.75': + return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' + case '6': + return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' + case '6.5': + return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' + case '7': + return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' + case '8': + return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' + case '8.75': + return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' + case '9': + return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' + case '9.5': + return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' + case '10': + return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' + case '10.5': + return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' + case '11': + return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' + case '11.5': + return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' + case '12': + return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' + case '12.75': + return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' + case '13': + return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' + case '14': + return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' + default: + return 'UTC'; + } + } +} diff --git a/phpBB/includes/db/migration/data/310/timezone_p2.php b/phpBB/includes/db/migration/data/310/timezone_p2.php new file mode 100644 index 0000000000..113b979e4f --- /dev/null +++ b/phpBB/includes/db/migration/data/310/timezone_p2.php @@ -0,0 +1,43 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_timezone'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst' => array('BOOL', 0), + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php deleted file mode 100644 index 8b7c6f0f7c..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_1_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php deleted file mode 100644 index b24a876bac..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.10', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10_rc3'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.10')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php deleted file mode 100644 index 46b7db4e59..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ /dev/null @@ -1,30 +0,0 @@ -config['version'], '3.0.10-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9'); - } - - public function update_data() - { - return array( - array('config.add', array('email_max_chunk_size', 50)), - - array('config.update', array('version', '3.0.10-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php deleted file mode 100644 index 5e85467202..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.10-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.10-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php deleted file mode 100644 index 6ff81f7776..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.10-rc3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.10-rc3')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php deleted file mode 100644 index 1a63508593..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.11', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.11')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php deleted file mode 100644 index 19703bcc35..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ /dev/null @@ -1,95 +0,0 @@ -config['version'], '3.0.11-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), - array('custom', array(array(&$this, 'delete_orphan_private_messages'))), - - array('config.update', array('version', '3.0.11-rc1')), - ); - } - - public function cleanup_deactivated_styles() - { - // Updates users having current style a deactivated one - $sql = 'SELECT style_id - FROM ' . STYLES_TABLE . ' - WHERE style_active = 0'; - $result = $this->sql_query($sql); - - $deactivated_style_ids = array(); - while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) - { - $deactivated_style_ids[] = (int) $style_id; - } - $this->db->sql_freeresult($result); - - if (!empty($deactivated_style_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->config['default_style'] .' - WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); - $this->sql_query($sql); - } - } - - public function delete_orphan_private_messages() - { - // Delete orphan private messages - $batch_size = 500; - - $sql_array = array( - 'SELECT' => 'p.msg_id', - 'FROM' => array( - PRIVMSGS_TABLE => 'p', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), - 'ON' => 'p.msg_id = t.msg_id', - ), - ), - 'WHERE' => 't.user_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - - $result = $this->db->sql_query_limit($sql, $batch_size); - - $delete_pms = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql); - - // Return false to have the Migrator call this function again - return false; - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php deleted file mode 100644 index 219d44c4e0..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ /dev/null @@ -1,50 +0,0 @@ -config['version'], '3.0.11-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11_rc1'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.11-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php deleted file mode 100644 index c23e8b24b8..0000000000 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ /dev/null @@ -1,123 +0,0 @@ -config['version'], '3.0.12-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_module_auth'))), - array('custom', array(array(&$this, 'update_bots'))), - array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))), - - array('config.update', array('version', '3.0.12-rc1')), - ); - } - - public function disable_bots_from_receiving_pms() - { - // Disable receiving pms for bots - $sql = 'SELECT user_id - FROM ' . BOTS_TABLE; - $result = $this->db->sql_query($sql); - - $bot_user_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $bot_user_ids[] = (int) $row['user_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($bot_user_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_allow_pm = 0 - WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); - $this->sql_query($sql); - } - } - - public function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'acl_u_sig\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'signature\''; - $this->sql_query($sql); - } - - public function update_bots() - { - // Update bots - if (!function_exists('user_delete')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - - $bots_updates = array( - // Bot Deletions - 'NG-Search [Bot]' => false, - 'Nutch/CVS [Bot]' => false, - 'OmniExplorer [Bot]' => false, - 'Seekport [Bot]' => false, - 'Synoo [Bot]' => false, - 'WiseNut [Bot]' => false, - - // Bot Updates - // Bot name to bot user agent map - 'Baidu [Spider]' => 'Baiduspider', - 'Exabot [Bot]' => 'Exabot', - 'Voyager [Bot]' => 'voyager/', - 'W3C [Validator]' => 'W3C_Validator', - ); - - foreach ($bots_updates as $bot_name => $bot_agent) - { - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . ' - WHERE user_type = ' . USER_IGNORE . " - AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; - $result = $this->db->sql_query($sql); - $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if ($bot_user_id) - { - if ($bot_agent === false) - { - $sql = 'DELETE FROM ' . BOTS_TABLE . " - WHERE user_id = $bot_user_id"; - $this->sql_query($sql); - - user_delete('remove', $bot_user_id); - } - else - { - $sql = 'UPDATE ' . BOTS_TABLE . " - SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' - WHERE user_id = $bot_user_id"; - $this->sql_query($sql); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php deleted file mode 100644 index 2fc2849d04..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ /dev/null @@ -1,108 +0,0 @@ -config['version'], '3.0.1-rc1', '>='); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list' => array('BOOL', 1), - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('UINT', 0), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'groups' => array( - 'group_legend', - ), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('session_forum_id'), - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name' => array('group_legend', 'group_name'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list', - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id', - ), - ), - 'add_index' => array( - $this->table_prefix . 'groups' => array( - 'group_legend' => array('group_legend'), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id', - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name', - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - - array('config.update', array('version', '3.0.1-rc1')), - ); - } - - public function fix_unset_last_view_time() - { - $sql = 'UPDATE ' . $this->table_prefix . "topics - SET topic_last_view_time = topic_last_post_time - WHERE topic_last_view_time = 0"; - $this->sql_query($sql); - } - - public function reset_smiley_size() - { - // Update smiley sizes - $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); - - foreach ($smileys as $smiley) - { - if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) - { - list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); - - $sql = 'UPDATE ' . SMILIES_TABLE . ' - SET smiley_width = ' . $width . ', smiley_height = ' . $height . " - WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; - - $this->sql_query($sql); - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php deleted file mode 100644 index 8aa975f779..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_2_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php deleted file mode 100644 index 6081cd682c..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ /dev/null @@ -1,32 +0,0 @@ -config['version'], '3.0.2-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_1'); - } - - public function update_data() - { - return array( - array('config.add', array('referer_validation', '1')), - array('config.add', array('check_attachment_content', '1')), - array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')), - - array('config.update', array('version', '3.0.2-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php deleted file mode 100644 index bb76c270d7..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ /dev/null @@ -1,80 +0,0 @@ -config['version'], '3.0.2-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_2_rc1'); - } - - public function update_schema() - { - return array( - 'change_columns' => array( - $this->table_prefix . 'drafts' => array( - 'draft_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'forums' => array( - 'forum_last_post_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'posts' => array( - 'post_subject' => array('STEXT_UNI', '', 'true_sort'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'topics' => array( - 'topic_title' => array('STEXT_UNI', '', 'true_sort'), - 'topic_last_post_subject' => array('STEXT_UNI', ''), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id', - ), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid' => array('session_forum_id'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array( - 'session_forum_id', - ), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.2-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php deleted file mode 100644 index 82039a109b..0000000000 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_3_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.3')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php deleted file mode 100644 index 5e300962b7..0000000000 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ /dev/null @@ -1,83 +0,0 @@ -config['version'], '3.0.3-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_2'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients' => array('UINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id', - 'template_inherit_path', - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('enable_queue_trigger', '0')), - array('config.add', array('queue_trigger_posts', '3')), - array('config.add', array('pm_max_recipients', '0')), - array('custom', array(array(&$this, 'set_group_default_max_recipients'))), - array('config.add', array('dbms_version', $this->db->sql_server_info(true))), - array('permission.add', array('u_masspm_group', true, 'u_masspm')), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - - array('config.update', array('version', '3.0.3-rc1')), - ); - } - - public function correct_acp_email_permissions() - { - $sql = 'UPDATE ' . $this->table_prefix . 'modules - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - $this->sql_query($sql); - } - - public function set_group_default_max_recipients() - { - // Set maximum number of recipients for the registered users, bots, guests group - $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 - WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php deleted file mode 100644 index 34af9fa4ae..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ /dev/null @@ -1,49 +0,0 @@ -config['version'], '3.0.4', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_4_rc1'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'rename_log_delete_topic'))), - - array('config.update', array('version', '3.0.4')), - ); - } - - public function rename_log_delete_topic() - { - if ($this->db->sql_layer == 'oracle') - { - // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation = 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php deleted file mode 100644 index f63bebcf75..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ /dev/null @@ -1,123 +0,0 @@ -config['version'], '3.0.4-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_3'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile' => array('BOOL', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'styles' => array( - 'style_id' => array('UINT', NULL, 'auto_increment'), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_imageset' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_theme' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template_data' => array( - 'template_id' => array('UINT', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_style' => array('UINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile', - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_custom_profile_fields'))), - - array('config.update', array('version', '3.0.4-rc1')), - ); - } - - public function update_custom_profile_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide - FROM ' . PROFILE_FIELDS_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'field_required' => 0, - 'field_show_on_reg' => 0, - 'field_hide' => 0, - 'field_show_profile'=> 0, - ); - - if ($row['field_required']) - { - $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_show_on_reg']) - { - $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_hide']) - { - // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module - $sql_ary['field_hide'] = 1; - } - else - { - // equivelant to "none", which is the "Display in user control panel" option - $sql_ary['field_show_profile'] = 1; - } - - $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); - } - - $this->db->sql_freeresult($result); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php deleted file mode 100644 index 077ed251d2..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.5', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_5_rc1part2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.5')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php deleted file mode 100644 index df85ee4f7d..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ /dev/null @@ -1,124 +0,0 @@ -config['version'], '3.0.5-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_4'); - } - - public function update_schema() - { - return array( - 'change_columns' => array( - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - ), - ); - } - - public function update_data() - { - $search_indexing_state = $this->config['search_indexing_state']; - - return array( - array('config.add', array('captcha_gd_wave', 0)), - array('config.add', array('captcha_gd_3d_noise', 1)), - array('config.add', array('captcha_gd_fonts', 1)), - array('config.add', array('confirm_refresh', 1)), - array('config.add', array('max_num_search_keywords', 10)), - array('config.remove', array('search_indexing_state')), - array('config.add', array('search_indexing_state', $search_indexing_state, true)), - array('custom', array(array(&$this, 'hash_old_passwords'))), - array('custom', array(array(&$this, 'update_ichiro_bot'))), - ); - } - - public function hash_old_passwords() - { - $sql = 'SELECT user_id, user_password - FROM ' . $this->table_prefix . 'users - WHERE user_pass_convert = 1'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (strlen($row['user_password']) == 32) - { - $sql_ary = array( - 'user_password' => phpbb_hash($row['user_password']), - ); - - $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); - } - } - $this->db->sql_freeresult($result); - } - - public function update_ichiro_bot() - { - // Adjust bot entry - $sql = 'UPDATE ' . $this->table_prefix . "bots - SET bot_agent = 'ichiro/' - WHERE bot_agent = 'ichiro/2'"; - $this->sql_query($sql); - } - - public function remove_duplicate_auth_options() - { - // Before we are able to add a unique key to auth_option, we need to remove duplicate entries - $sql = 'SELECT auth_option - FROM ' . $this->table_prefix . 'acl_options - GROUP BY auth_option - HAVING COUNT(*) >= 2'; - $result = $this->db->sql_query($sql); - - $auth_options = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $auth_options[] = $row['auth_option']; - } - $this->db->sql_freeresult($result); - - // Remove specific auth options - if (!empty($auth_options)) - { - foreach ($auth_options as $option) - { - // Select auth_option_ids... the largest id will be preserved - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $db->sql_escape($option) . "' - ORDER BY auth_option_id DESC"; - // sql_query_limit not possible here, due to bug in postgresql layer - $result = $this->db->sql_query($sql); - - // Skip first row, this is our original auth option we want to preserve - $row = $this->db->sql_fetchrow($result); - - while ($row = $this->db->sql_fetchrow($result)) - { - // Ok, remove this auth option... - $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - } - $this->db->sql_freeresult($result); - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php deleted file mode 100644 index d2fad7a7f8..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ /dev/null @@ -1,42 +0,0 @@ -config['version'], '3.0.5-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_5_rc1'); - } - - public function update_schema() - { - return array( - 'drop_keys' => array( - $this->table_prefix . 'acl_options' => array('auth_option'), - ), - 'add_unique_index' => array( - $this->table_prefix . 'acl_options' => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.5-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php deleted file mode 100644 index 1b0cbb1435..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.6', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc4'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.6')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php deleted file mode 100644 index 0f85084e65..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ /dev/null @@ -1,324 +0,0 @@ -config['version'], '3.0.6-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_5'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'confirm' => array( - 'attempts' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_new' => array('BOOL', 1), - 'user_reminded' => array('TINT:4', 0), - 'user_reminded_time' => array('TIMESTAMP', 0), - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported' => array('BOOL', 0), - ), - $this->table_prefix . 'reports' => array( - 'pm_id' => array('UINT', 0), - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_vt' => array('BOOL', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_options' => array('UINT:20', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_options' => array('UINT:11', 230271), - ), - ), - 'add_index' => array( - $this->table_prefix . 'reports' => array( - 'post_id' => array('post_id'), - 'pm_id' => array('pm_id'), - ), - $this->table_prefix . 'posts' => array( - 'post_username' => array('post_username:255'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'confirm' => array( - 'attempts', - ), - $this->table_prefix . 'users' => array( - 'user_new', - 'user_reminded', - 'user_reminded_time', - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth', - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported', - ), - $this->table_prefix . 'reports' => array( - 'pm_id', - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_vt', - ), - $this->table_prefix . 'forums' => array( - 'forum_options', - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'reports' => array( - 'post_id', - 'pm_id', - ), - $this->table_prefix . 'posts' => array( - 'post_username', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('if', array( - ($this->config['captcha_gd']), - array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), - )), - - array('config.add', array('feed_enable', 0)), - array('config.add', array('feed_limit', 10)), - array('config.add', array('feed_overall_forums', 1)), - array('config.add', array('feed_overall_forums_limit', 15)), - array('config.add', array('feed_overall_topics', 0)), - array('config.add', array('feed_overall_topics_limit', 15)), - array('config.add', array('feed_forum', 1)), - array('config.add', array('feed_topic', 1)), - array('config.add', array('feed_item_statistics', 1)), - - array('config.add', array('smilies_per_page', 50)), - array('config.add', array('allow_pm_report', 1)), - array('config.add', array('min_post_chars', 1)), - array('config.add', array('allow_quick_reply', 1)), - array('config.add', array('new_member_post_limit', 0)), - array('config.add', array('new_member_group_default', 0)), - array('config.add', array('delete_time', $this->config['edit_time'])), - - array('config.add', array('allow_avatar', 0)), - array('if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - array('config.update', array('allow_avatar', 1)), - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - array('config.update', array('allow_avatar_remote_upload', 1)), - )), - - array('module.add', array( - 'acp', - 'ACP_BOARD_CONFIGURATION', - array( - 'module_basename' => 'acp_board', - 'modes' => array('feed'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_CAT_USERS', - array( - 'module_basename' => 'acp_users', - 'modes' => array('warnings'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_SERVER_CONFIGURATION', - array( - 'module_basename' => 'acp_send_statistics', - 'modes' => array('send_statistics'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_FORUM_BASED_PERMISSIONS', - array( - 'module_basename' => 'acp_permissions', - 'modes' => array('setting_forum_copy'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'mcp_pm_reports', - 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - - array('config.update', array('version', '3.0.6-rc1')), - ); - } - - public function set_user_options_default() - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - $this->sql_query($sql); - } - - public function add_newly_registered_group() - { - // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'NEWLY_REGISTERED'"; - $result = $this->db->sql_query($sql); - $group_id = (int) $this->db->sql_fetchfield('group_id'); - $this->db->sql_freeresult($result); - - if (!$group_id) - { - $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; - $this->sql_query($sql); - - $group_id = $this->db->sql_nextid(); - } - - // Insert new user role... at the end of the chain - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_USER_NEW_MEMBER' - AND role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $u_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$u_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; - $this->sql_query($sql); - $u_role = $this->db->sql_nextid(); - - // Now add the correct data to the roles... - // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - $this->sql_query($sql); - - // Add user role to group - $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - $this->sql_query($sql); - } - - // Insert new forum role - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' - AND role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $f_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$f_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; - $this->sql_query($sql); - $f_role = $this->db->sql_nextid(); - - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - $this->sql_query($sql); - } - - // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) - $sql = 'SELECT 1 - FROM ' . USERS_TABLE . ' - WHERE user_new = 0'; - $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; - $this->sql_query($sql); - } - - // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... - // Check if the role is already assigned... - $sql = 'SELECT forum_id - FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id = ' . $f_role; - $result = $this->db->sql_query($sql); - $is_options = (int) $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - // Not assigned at all... :/ - if (!$is_options) - { - // Get postable forums - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type != ' . FORUM_LINK; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); - } - $this->db->sql_freeresult($result); - } - - // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php deleted file mode 100644 index a9c497b3cd..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.6-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.6-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php deleted file mode 100644 index eca19fc2ff..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ /dev/null @@ -1,40 +0,0 @@ -config['version'], '3.0.6-rc3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc2'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_cp_fields'))), - - array('config.update', array('version', '3.0.6-rc3')), - ); - } - - public function update_cp_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' - SET field_show_on_vt = 1 - WHERE field_hide = 0 - AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)'; - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php deleted file mode 100644 index 19611d3c56..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.6-rc4', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc3'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.6-rc4')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php deleted file mode 100644 index 97cdf4e3f1..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.7', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.7')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php deleted file mode 100644 index 176854a8a6..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.7-pl1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.7-pl1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php deleted file mode 100644 index daf52213b9..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ /dev/null @@ -1,76 +0,0 @@ -config['version'], '3.0.7-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6'); - } - - public function update_schema() - { - return array( - 'drop_keys' => array( - $this->table_prefix . 'log' => array( - 'log_time', - ), - ), - 'add_index' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id' => array('topic_id'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'add_index' => array( - $this->table_prefix . 'log' => array( - 'log_time' => array('log_time'), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('feed_overall', 1)), - array('config.add', array('feed_http_auth', 0)), - array('config.add', array('feed_limit_post', $this->config['feed_limit'])), - array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), - array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), - array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), - array('custom', array(array(&$this, 'delete_text_templates'))), - - array('config.update', array('version', '3.0.7-rc1')), - ); - } - - public function delete_text_templates() - { - // Delete all text-templates from the template_data - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php deleted file mode 100644 index 8167d8fa40..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ /dev/null @@ -1,73 +0,0 @@ -config['version'], '3.0.7-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7_rc1'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_email_hash'))), - - array('config.update', array('version', '3.0.7-rc2')), - ); - } - - public function update_email_hash($start = 0) - { - $limit = 1000; - - $sql = 'SELECT user_id, user_email, user_email_hash - FROM ' . USERS_TABLE . ' - WHERE user_type <> ' . USER_IGNORE . " - AND user_email <> ''"; - $result = $this->db->sql_query_limit($sql, $limit, $start); - - $i = 0; - while ($row = $this->db->sql_fetchrow($result)) - { - $i++; - - // Snapshot of the phpbb_email_hash() function - // We cannot call it directly because the auto updater updates the DB first. :/ - $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); - - if ($user_email_hash != $row['user_email_hash']) - { - $sql_ary = array( - 'user_email_hash' => $user_email_hash, - ); - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_id = ' . (int) $row['user_id']; - $this->sql_query($sql); - } - } - $this->db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return; - } - - // Return the next start, will be sent to $start when this function is called again - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php deleted file mode 100644 index 25baaf0f07..0000000000 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.8', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_8_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.8')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php deleted file mode 100644 index 13e68a7953..0000000000 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ /dev/null @@ -1,221 +0,0 @@ -config['version'], '3.0.8-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7_pl1'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'update_module_auth'))), - array('custom', array(array(&$this, 'update_bots'))), - array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))), - array('module.add', array( - 'acp', - 'ACP_MESSAGES', - array( - 'module_basename' => 'acp_board', - 'modes' => array('post'), - ), - )), - array('config.add', array('load_unreads_search', 1)), - array('config.update_if_equals', array(600, 'queue_interval', 60)), - array('config.update_if_equals', array(50, 'email_package_size', 20)), - - array('config.update', array('version', '3.0.8-rc1')), - ); - } - - public function update_file_extension_group_names() - { - // Update file extension group names to use language strings. - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - $extension_groups_updated = array(); - while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) - { - $lang_dir = basename($lang_dir); - - // The language strings we need are either in language/.../acp/attachments.php - // in the update package if we're updating to 3.0.8-RC1 or later, - // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. - // On an already updated board, they can also already be in language/.../acp/attachments.php - // in the board root. - $lang_files = array( - "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", - "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", - ); - - foreach ($lang_files as $lang_file) - { - if (!file_exists($lang_file)) - { - continue; - } - - $lang = array(); - include($lang_file); - - foreach($lang as $lang_key => $lang_val) - { - if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) - { - continue; - } - - $sql_ary = array( - 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; - $this->sql_query($sql); - - $extension_groups_updated[$lang_key] = true; - } - } - } - $this->db->sql_freeresult($result); - } - - public function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'avatar\''; - $this->sql_query($sql); - } - - public function update_bots() - { - $bot_name = 'Bing [Bot]'; - $bot_name_clean = utf8_clean_string($bot_name); - - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; - $result = $this->db->sql_query($sql); - $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if (!$bing_already_added) - { - $bot_agent = 'bingbot/'; - $bot_ip = ''; - $sql = 'SELECT group_id, group_colour - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'BOTS'"; - $result = $this->db->sql_query($sql); - $group_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$group_row) - { - // default fallback, should never get here - $group_row['group_id'] = 6; - $group_row['group_colour'] = '9E8DA7'; - } - - if (!function_exists('user_add')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - - $user_row = array( - 'user_type' => USER_IGNORE, - 'group_id' => $group_row['group_id'], - 'username' => $bot_name, - 'user_regdate' => time(), - 'user_password' => '', - 'user_colour' => $group_row['group_colour'], - 'user_email' => '', - 'user_lang' => $this->config['default_lang'], - 'user_style' => $this->config['default_style'], - 'user_timezone' => 0, - 'user_dateformat' => $this->config['default_dateformat'], - 'user_allow_massemail' => 0, - ); - - $user_id = user_add($user_row); - - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'bot_active' => 1, - 'bot_name' => (string) $bot_name, - 'user_id' => (int) $user_id, - 'bot_agent' => (string) $bot_agent, - 'bot_ip' => (string) $bot_ip, - )); - - $this->sql_query($sql); - } - } - - public function delete_orphan_shadow_topics() - { - // Delete shadow topics pointing to not existing topics - $batch_size = 500; - - // Set of affected forums we have to resync - $sync_forum_ids = array(); - - $sql_array = array( - 'SELECT' => 't1.topic_id, t1.forum_id', - 'FROM' => array( - TOPICS_TABLE => 't1', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(TOPICS_TABLE => 't2'), - 'ON' => 't1.topic_moved_id = t2.topic_id', - ), - ), - 'WHERE' => 't1.topic_moved_id <> 0 - AND t2.topic_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - $result = $this->db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['topic_id']; - - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); - $this->db->sql_query($sql); - - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); - - return false; - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php deleted file mode 100644 index b35350dbb5..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc4'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php deleted file mode 100644 index be6ced2566..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ /dev/null @@ -1,124 +0,0 @@ -config['version'], '3.0.9-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_8'); - } - - public function update_schema() - { - return array( - 'add_tables' => array( - $this->table_prefix . 'login_attempts' => array( - 'COLUMNS' => array( - // this column was removed from the database updater - // after 3.0.9-RC3 was released. It might still exist - // in 3.0.9-RCX installations and has to be dropped in - // 3.0.12 after the db_tools class is capable of properly - // removing a primary key. - // 'attempt_id' => array('UINT', NULL, 'auto_increment'), - 'attempt_ip' => array('VCHAR:40', ''), - 'attempt_browser' => array('VCHAR:150', ''), - 'attempt_forwarded_for' => array('VCHAR:255', ''), - 'attempt_time' => array('TIMESTAMP', 0), - 'user_id' => array('UINT', 0), - 'username' => array('VCHAR_UNI:255', 0), - 'username_clean' => array('VCHAR_CI', 0), - ), - //'PRIMARY_KEY' => 'attempt_id', - 'KEYS' => array( - 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), - 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), - 'att_time' => array('INDEX', array('attempt_time')), - 'user_id' => array('INDEX', 'user_id'), - ), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'bbcodes' => array( - 'bbcode_id' => array('USINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_tables' => array( - $this->table_prefix . 'login_attempts', - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('ip_login_limit_max', 50)), - array('config.add', array('ip_login_limit_time', 21600)), - array('config.add', array('ip_login_limit_use_forwarded', 0)), - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), - - array('config.update', array('version', '3.0.9-rc1')), - ); - } - - public function update_file_extension_group_names() - { - // Update file extension group names to use language strings, again. - $sql = 'SELECT group_id, group_name - FROM ' . EXTENSION_GROUPS_TABLE . ' - WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - public function fix_firebird_qa_captcha() - { - // Recover from potentially broken Q&A CAPTCHA table on firebird - // Q&A CAPTCHA was uninstallable, so it's safe to remove these - // without data loss - if ($this->db_tools->sql_layer == 'firebird') - { - $tables = array( - $this->table_prefix . 'captcha_questions', - $this->table_prefix . 'captcha_answers', - $this->table_prefix . 'qa_confirm', - ); - foreach ($tables as $table) - { - if ($this->db_tools->sql_table_exists($table)) - { - $this->db_tools->sql_table_drop($table); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php deleted file mode 100644 index 0bec42a8de..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php deleted file mode 100644 index a339670932..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9-rc3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9-rc3')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php deleted file mode 100644 index ab5c302611..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9-rc4', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc3'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9-rc4')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php deleted file mode 100644 index 8b437104e0..0000000000 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ /dev/null @@ -1,406 +0,0 @@ -config['version'], '3.1.0-dev', '>='); - } - - static public function depends_on() - { - return array( - 'phpbb_db_migration_data_3_0_11', - 'phpbb_db_migration_data_extensions', - 'phpbb_db_migration_data_style_update_p2', - 'phpbb_db_migration_data_timezone_p2', - 'phpbb_db_migration_data_reported_posts_display', - ); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_pm' => array('BOOL', 0), - ), - $this->table_prefix . 'styles' => array( - 'style_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'style_parent_id' => array('UINT:4', 0), - 'style_parent_tree' => array('TEXT', ''), - ), - $this->table_prefix . 'reports' => array( - 'reported_post_text' => array('MTEXT_UNI', ''), - 'reported_post_uid' => array('VCHAR:8', ''), - 'reported_post_bitfield' => array('VCHAR:255', ''), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_legend' => array('UINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_teampage', - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_pm', - ), - $this->table_prefix . 'styles' => array( - 'style_path', - 'bbcode_bitfield', - 'style_parent_id', - 'style_parent_tree', - ), - $this->table_prefix . 'reports' => array( - 'reported_post_text', - 'reported_post_uid', - 'reported_post_bitfield', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), - - array('config.add', array('fulltext_postgres_ts_name', 'simple')), - array('config.add', array('fulltext_postgres_min_word_len', 4)), - array('config.add', array('fulltext_postgres_max_word_len', 254)), - array('config.add', array('fulltext_sphinx_stopwords', 0)), - array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), - - array('config.add', array('load_jquery_cdn', 0)), - array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), - - array('config.add', array('use_system_cron', 0)), - - array('config.add', array('legend_sort_groupname', 0)), - array('config.add', array('teampage_forums', 1)), - array('config.add', array('teampage_memberships', 1)), - - array('config.add', array('load_cpf_pm', 0)), - - array('config.add', array('display_last_subject', 1)), - - array('config.add', array('assets_version', 1)), - - array('config.add', array('site_home_url', '')), - array('config.add', array('site_home_text', '')), - - array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), - - array('module.add', array( - 'acp', - 'ACP_GROUPS', - array( - 'module_basename' => 'acp_groups', - 'modes' => array('position'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_ATTACHMENTS', - array( - 'module_basename' => 'acp_attachments', - 'modes' => array('manage'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_STYLE_MANAGEMENT', - array( - 'module_basename' => 'acp_styles', - 'modes' => array('install', 'cache'), - ), - )), - array('module.add', array( - 'ucp', - 'UCP_PROFILE', - array( - 'module_basename' => 'ucp_profile', - 'modes' => array('autologin_keys'), - ), - )), - // Module will be renamed later - array('module.add', array( - 'acp', - 'ACP_CAT_STYLES', - 'ACP_LANGUAGE' - )), - - array('module.remove', array( - 'acp', - false, - 'ACP_TEMPLATES', - )), - array('module.remove', array( - 'acp', - false, - 'ACP_THEMES', - )), - array('module.remove', array( - 'acp', - false, - 'ACP_IMAGESETS', - )), - - array('custom', array(array($this, 'rename_module_basenames'))), - array('custom', array(array($this, 'rename_styles_module'))), - array('custom', array(array($this, 'add_group_teampage'))), - array('custom', array(array($this, 'update_group_legend'))), - array('custom', array(array($this, 'localise_global_announcements'))), - array('custom', array(array($this, 'update_ucp_pm_basename'))), - array('custom', array(array($this, 'update_ucp_profile_auth'))), - array('custom', array(array($this, 'move_customise_modules'))), - - array('config.update', array('version', '3.1.0-dev')), - ); - } - - public function move_customise_modules() - { - // Move language management to new location in the Customise tab - // First get language module id - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_basename = 'acp_language'"; - $result = $this->db->sql_query($sql); - $language_module_id = $this->db->sql_fetchfield('module_id'); - $this->db->sql_freeresult($result); - // Next get language management module id of the one just created - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = 'ACP_LANGUAGE'"; - $result = $this->db->sql_query($sql); - $language_management_module_id = $this->db->sql_fetchfield('module_id'); - $this->db->sql_freeresult($result); - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - } - // acp_modules calls adm_back_link, which is undefined at this point - if (!function_exists('adm_back_link')) - { - include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); - } - $module_manager = new acp_modules(); - $module_manager->module_class = 'acp'; - $module_manager->move_module($language_module_id, $language_management_module_id); - } - - public function update_ucp_pm_basename() - { - $sql = 'SELECT module_id, module_basename - FROM ' . MODULES_TABLE . " - WHERE module_basename <> 'ucp_pm' AND - module_langname='UCP_PM'"; - $result = $this->db->sql_query_limit($sql, 1); - - if ($row = $this->db->sql_fetchrow($result)) - { - // This update is still not applied. Applying it - - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_basename = 'ucp_pm' - WHERE module_id = " . (int) $row['module_id']; - - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - public function update_ucp_profile_auth() - { - // Update the auth setting for the module - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_auth = 'acl_u_chgprofileinfo' - WHERE module_class = 'ucp' - AND module_basename = 'ucp_profile' - AND module_mode = 'profile_info'"; - $this->sql_query($sql); - } - - public function rename_styles_module() - { - // Rename styles module to Customise - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_langname = 'ACP_CAT_CUSTOMISE' - WHERE module_langname = 'ACP_CAT_STYLES'"; - $this->sql_query($sql); - } - - public function rename_module_basenames() - { - // rename all module basenames to full classname - $sql = 'SELECT module_id, module_basename, module_class - FROM ' . MODULES_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $module_id = (int) $row['module_id']; - unset($row['module_id']); - - if (!empty($row['module_basename']) && !empty($row['module_class'])) - { - // all the class names start with class name or with phpbb_ for auto loading - if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && - strpos($row['module_basename'], 'phpbb_') !== 0) - { - $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; - - $sql_update = $this->db->sql_build_array('UPDATE', $row); - - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET ' . $sql_update . ' - WHERE module_id = ' . $module_id; - $this->sql_query($sql); - } - } - } - - $this->db->sql_freeresult($result); - } - - public function add_group_teampage() - { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 1 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'ADMINISTRATORS'"; - $this->sql_query($sql); - - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 2 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'GLOBAL_MODERATORS'"; - $this->sql_query($sql); - } - - public function update_group_legend() - { - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . ' - WHERE group_legend = 1 - ORDER BY group_name ASC'; - $result = $this->db->sql_query($sql); - - $next_legend = 1; - while ($row = $this->db->sql_fetchrow($result)) - { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_legend = ' . $next_legend . ' - WHERE group_id = ' . (int) $row['group_id']; - $this->sql_query($sql); - - $next_legend++; - } - $this->db->sql_freeresult($result); - } - - public function localise_global_announcements() - { - // Localise Global Announcements - $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = 0 - AND topic_type = ' . POST_GLOBAL; - $result = $this->db->sql_query($sql); - - $global_announcements = $update_lastpost_data = array(); - $update_lastpost_data['forum_last_post_time'] = 0; - $update_forum_data = array( - 'forum_posts' => 0, - 'forum_topics' => 0, - 'forum_topics_real' => 0, - ); - - while ($row = $this->db->sql_fetchrow($result)) - { - $global_announcements[] = (int) $row['topic_id']; - - $update_forum_data['forum_posts'] += (int) $row['topic_posts']; - $update_forum_data['forum_topics_real']++; - if ($row['topic_approved']) - { - $update_forum_data['forum_topics']++; - } - - if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) - { - $update_lastpost_data = array( - 'forum_last_post_id' => (int) $row['topic_last_post_id'], - 'forum_last_post_subject' => $row['topic_last_post_subject'], - 'forum_last_post_time' => (int) $row['topic_last_post_time'], - 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], - 'forum_last_poster_name' => $row['topic_last_poster_name'], - 'forum_last_poster_colour' => $row['topic_last_poster_colour'], - ); - } - } - $this->db->sql_freeresult($result); - - if (!empty($global_announcements)) - { - // Update the post/topic-count for the forum and the last-post if needed - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type = ' . FORUM_POST; - $result = $this->db->sql_query_limit($sql, 1); - $ga_forum_id = $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - $sql = 'SELECT forum_last_post_time - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $ga_forum_id; - $result = $this->db->sql_query($sql); - $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); - $this->db->sql_freeresult($result); - - $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; - $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; - $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; - if ($lastpost < $update_lastpost_data['forum_last_post_time']) - { - $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); - } - - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET ' . $sql_update . ' - WHERE forum_id = ' . $ga_forum_id; - $this->sql_query($sql); - - // Update some forum_ids - $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); - foreach ($table_ary as $table) - { - $sql = "UPDATE $table - SET forum_id = $ga_forum_id - WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); - $this->sql_query($sql); - } - unset($table_ary); - } - } -} diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php deleted file mode 100644 index f077741883..0000000000 --- a/phpBB/includes/db/migration/data/extensions.php +++ /dev/null @@ -1,69 +0,0 @@ -db_tools->sql_table_exists($this->table_prefix . 'ext'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_schema() - { - return array( - 'add_tables' => array( - $this->table_prefix . 'ext' => array( - 'COLUMNS' => array( - 'ext_name' => array('VCHAR', ''), - 'ext_active' => array('BOOL', 0), - 'ext_state' => array('TEXT', ''), - ), - 'KEYS' => array( - 'ext_name' => array('UNIQUE', 'ext_name'), - ), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_tables' => array( - $this->table_prefix . 'ext', - ), - ); - } - - public function update_data() - { - return array( - // Module will be renamed later - array('module.add', array( - 'acp', - 'ACP_CAT_STYLES', - 'ACP_EXTENSION_MANAGEMENT' - )), - array('module.add', array( - 'acp', - 'ACP_EXTENSION_MANAGEMENT', - array( - 'module_basename' => 'acp_extensions', - 'modes' => array('main'), - ), - )), - array('permission.add', array('a_extensions', true, 'a_styles')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/reported_posts_display.php b/phpBB/includes/db/migration/data/reported_posts_display.php deleted file mode 100644 index fa605e28e5..0000000000 --- a/phpBB/includes/db/migration/data/reported_posts_display.php +++ /dev/null @@ -1,42 +0,0 @@ -db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'reports' => array( - 'reported_post_enable_bbcode' => array('BOOL', 1), - 'reported_post_enable_smilies' => array('BOOL', 1), - 'reported_post_enable_magic_url' => array('BOOL', 1), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'reports' => array( - 'reported_post_enable_bbcode', - 'reported_post_enable_smilies', - 'reported_post_enable_magic_url', - ), - ), - ); - } -} diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php deleted file mode 100644 index 7506b7c49b..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ /dev/null @@ -1,157 +0,0 @@ -db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_data() - { - return array( - array('custom', array(array($this, 'styles_update'))), - ); - } - - public function styles_update() - { - // Get list of valid 3.1 styles - $available_styles = array('prosilver'); - - $iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); - $skip_dirs = array('.', '..', 'prosilver'); - foreach ($iterator as $fileinfo) - { - if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) - { - $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); - if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) - { - // 3.1 style - $available_styles[] = $fileinfo->getFilename(); - } - } - } - - // Get all installed styles - if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) - { - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path - FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i - WHERE t.template_id = s.template_id - AND c.theme_id = s.theme_id - AND i.imageset_id = s.imageset_id"; - } - else - { - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c - WHERE t.template_id = s.template_id - AND c.theme_id = s.theme_id"; - } - $result = $this->db->sql_query($sql); - - $styles = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $styles[] = $row; - } - $this->db->sql_freeresult($result); - - // Decide which styles to keep, all others will be deleted - $valid_styles = array(); - foreach ($styles as $style_row) - { - if ( - // Delete styles with parent style (not supported yet) - $style_row['template_inherits_id'] == 0 && - // Check if components match - $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && - // Check if components are valid - in_array($style_row['template_path'], $available_styles) - ) - { - // Valid style. Keep it - $sql_ary = array( - 'style_path' => $style_row['template_path'], - 'bbcode_bitfield' => $style_row['bbcode_bitfield'], - 'style_parent_id' => 0, - 'style_parent_tree' => '', - ); - $this->sql_query('UPDATE ' . STYLES_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE style_id = ' . $style_row['style_id']); - $valid_styles[] = (int) $style_row['style_id']; - } - } - - // Remove old entries from styles table - if (!sizeof($valid_styles)) - { - // No valid styles: remove everything and add prosilver - $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); - - $sql_ary = array( - 'style_name' => 'prosilver', - 'style_copyright' => '© phpBB Group', - 'style_active' => 1, - 'style_path' => 'prosilver', - 'bbcode_bitfield' => 'lNg=', - 'style_parent_id' => 0, - 'style_parent_tree' => '', - - // Will be removed in the next step - 'imageset_id' => 0, - 'template_id' => 0, - 'theme_id' => 0, - ); - - $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->sql_query($sql); - - $sql = 'SELECT style_id - FROM ' . $table . " - WHERE style_name = 'prosilver'"; - $result = $this->sql_query($sql); - $default_style = $this->db->sql_fetchfield($result); - $this->db->sql_freeresult($result); - - set_config('default_style', $default_style); - - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; - $this->sql_query($sql); - } - else - { - // There are valid styles in styles table. Remove styles that are outdated - $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' - WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); - - // Change default style - if (!in_array($this->config['default_style'], $valid_styles)) - { - $this->sql_query('UPDATE ' . CONFIG_TABLE . " - SET config_value = '" . $valid_styles[0] . "' - WHERE config_name = 'default_style'"); - } - - // Reset styles for users - $this->sql_query('UPDATE ' . USERS_TABLE . ' - SET user_style = 0 - WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); - } - } -} diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php deleted file mode 100644 index ef13f45d9b..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ /dev/null @@ -1,129 +0,0 @@ -db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_style_update_p1'); - } - - public function update_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'styles' => array( - 'imageset_id', - 'template_id', - 'theme_id', - ), - ), - - 'drop_tables' => array( - $this->table_prefix . 'styles_imageset', - $this->table_prefix . 'styles_imageset_data', - $this->table_prefix . 'styles_template', - $this->table_prefix . 'styles_template_data', - $this->table_prefix . 'styles_theme', - ), - ); - } - - public function revert_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'styles' => array( - 'imageset_id' => array('UINT', 0), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - ), - ), - - 'add_tables' => array( - $this->table_prefix . 'styles_imageset' => array( - 'COLUMNS' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_name' => array('VCHAR_UNI:255', ''), - 'imageset_copyright' => array('VCHAR_UNI', ''), - 'imageset_path' => array('VCHAR:100', ''), - ), - 'PRIMARY_KEY' => 'imageset_id', - 'KEYS' => array( - 'imgset_nm' => array('UNIQUE', 'imageset_name'), - ), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'COLUMNS' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'image_name' => array('VCHAR:200', ''), - 'image_filename' => array('VCHAR:200', ''), - 'image_lang' => array('VCHAR:30', ''), - 'image_height' => array('USINT', 0), - 'image_width' => array('USINT', 0), - 'imageset_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'image_id', - 'KEYS' => array( - 'i_d' => array('INDEX', 'imageset_id'), - ), - ), - $this->table_prefix . 'styles_template' => array( - 'COLUMNS' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - 'template_name' => array('VCHAR_UNI:255', ''), - 'template_copyright' => array('VCHAR_UNI', ''), - 'template_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'template_storedb' => array('BOOL', 0), - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - 'PRIMARY_KEY' => 'template_id', - 'KEYS' => array( - 'tmplte_nm' => array('UNIQUE', 'template_name'), - ), - ), - $this->table_prefix . 'styles_template_data' => array( - 'COLUMNS' => array( - 'template_id' => array('UINT', 0), - 'template_filename' => array('VCHAR:100', ''), - 'template_included' => array('TEXT', ''), - 'template_mtime' => array('TIMESTAMP', 0), - 'template_data' => array('MTEXT_UNI', ''), - ), - 'KEYS' => array( - 'tid' => array('INDEX', 'template_id'), - 'tfn' => array('INDEX', 'template_filename'), - ), - ), - $this->table_prefix . 'styles_theme' => array( - 'COLUMNS' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - 'theme_name' => array('VCHAR_UNI:255', ''), - 'theme_copyright' => array('VCHAR_UNI', ''), - 'theme_path' => array('VCHAR:100', ''), - 'theme_storedb' => array('BOOL', 0), - 'theme_mtime' => array('TIMESTAMP', 0), - 'theme_data' => array('MTEXT_UNI', ''), - ), - 'PRIMARY_KEY' => 'theme_id', - 'KEYS' => array( - 'theme_name' => array('UNIQUE', 'theme_name'), - ), - ), - ), - ); - } -} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php deleted file mode 100644 index 66085b8872..0000000000 --- a/phpBB/includes/db/migration/data/timezone.php +++ /dev/null @@ -1,163 +0,0 @@ -db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_schema() - { - return array( - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_timezone' => array('VCHAR:100', ''), - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array($this, 'update_timezones'))), - ); - } - - public function update_timezones() - { - // Update user timezones - $sql = 'SELECT user_dst, user_timezone - FROM ' . $this->table_prefix . 'users - GROUP BY user_timezone, user_dst'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql = 'UPDATE ' . $this->table_prefix . "users - SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' - WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' - AND user_dst = " . (int) $row['user_dst']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - - // Update board default timezone - $sql = 'UPDATE ' . $this->table_prefix . "config - SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' - WHERE config_name = 'board_timezone'"; - $this->sql_query($sql); - } - - /** - * Determine the new timezone for a given phpBB 3.0 timezone and - * "Daylight Saving Time" option - * - * @param $timezone float Users timezone in 3.0 - * @param $dst int Users daylight saving time - * @return string Users new php Timezone which is used since 3.1 - */ - public function convert_phpbb30_timezone($timezone, $dst) - { - $offset = $timezone + $dst; - - switch ($timezone) - { - case '-12': - return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' - case '-11': - return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' - case '-10': - return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' - case '-9.5': - return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' - case '-9': - return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' - case '-8': - return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' - case '-7': - return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' - case '-6': - return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' - case '-5': - return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' - case '-4.5': - return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' - case '-4': - return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' - case '-3.5': - return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' - case '-3': - return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' - case '-2': - return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' - case '-1': - return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' - case '0': - return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' - case '1': - return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' - case '2': - return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' - case '3': - return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' - case '3.5': - return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' - case '4': - return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' - case '4.5': - return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' - case '5': - return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' - case '5.5': - return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' - case '5.75': - return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' - case '6': - return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' - case '6.5': - return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' - case '7': - return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' - case '8': - return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' - case '8.75': - return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' - case '9': - return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' - case '9.5': - return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' - case '10': - return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' - case '10.5': - return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' - case '11': - return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' - case '11.5': - return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' - case '12': - return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' - case '12.75': - return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' - case '13': - return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' - case '14': - return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' - default: - return 'UTC'; - } - } -} diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php deleted file mode 100644 index 38347a0c63..0000000000 --- a/phpBB/includes/db/migration/data/timezone_p2.php +++ /dev/null @@ -1,43 +0,0 @@ -db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_timezone'); - } - - public function update_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'users' => array( - 'user_dst', - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'users' => array( - 'user_dst' => array('BOOL', 0), - ), - ), - ); - } -} -- cgit v1.2.1 From e4afb68dc35131918a6b91ae9874ade97f448475 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 14 Jan 2013 12:50:13 -0600 Subject: [feature/migrations] Correct depends_on PHPBB3-9737 --- phpBB/includes/db/migration/data/310/dev.php | 1 - phpBB/includes/db/migration/data/310/extensions.php | 2 +- phpBB/includes/db/migration/data/310/reported_posts_display.php | 5 +++++ phpBB/includes/db/migration/data/310/style_update_p1.php | 2 +- phpBB/includes/db/migration/data/310/timezone.php | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php index f41750e327..13b36bbf30 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -17,7 +17,6 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration static public function depends_on() { return array( - 'phpbb_db_migration_data_30x_11', 'phpbb_db_migration_data_310_extensions', 'phpbb_db_migration_data_310_style_update_p2', 'phpbb_db_migration_data_310_timezone_p2', diff --git a/phpBB/includes/db/migration/data/310/extensions.php b/phpBB/includes/db/migration/data/310/extensions.php index 925fa29384..6a9caa1cfc 100644 --- a/phpBB/includes/db/migration/data/310/extensions.php +++ b/phpBB/includes/db/migration/data/310/extensions.php @@ -16,7 +16,7 @@ class phpbb_db_migration_data_310_extensions extends phpbb_db_migration static public function depends_on() { - return array('phpbb_db_migration_data_30x_11'); + return array('phpbb_db_migration_data_30x_3_0_11'); } public function update_schema() diff --git a/phpBB/includes/db/migration/data/310/reported_posts_display.php b/phpBB/includes/db/migration/data/310/reported_posts_display.php index 64f0f1aaec..80a0a0e43f 100644 --- a/phpBB/includes/db/migration/data/310/reported_posts_display.php +++ b/phpBB/includes/db/migration/data/310/reported_posts_display.php @@ -14,6 +14,11 @@ class phpbb_db_migration_data_310_reported_posts_display extends phpbb_db_migrat return $this->db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); } + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + public function update_schema() { return array( diff --git a/phpBB/includes/db/migration/data/310/style_update_p1.php b/phpBB/includes/db/migration/data/310/style_update_p1.php index d19ccc37cf..e324ce7f24 100644 --- a/phpBB/includes/db/migration/data/310/style_update_p1.php +++ b/phpBB/includes/db/migration/data/310/style_update_p1.php @@ -16,7 +16,7 @@ class phpbb_db_migration_data_310_style_update_p1 extends phpbb_db_migration static public function depends_on() { - return array('phpbb_db_migration_data_30x_11'); + return array('phpbb_db_migration_data_30x_3_0_11'); } public function update_data() diff --git a/phpBB/includes/db/migration/data/310/timezone.php b/phpBB/includes/db/migration/data/310/timezone.php index 7a6a9bce05..6e50cbe45f 100644 --- a/phpBB/includes/db/migration/data/310/timezone.php +++ b/phpBB/includes/db/migration/data/310/timezone.php @@ -16,7 +16,7 @@ class phpbb_db_migration_data_310_timezone extends phpbb_db_migration static public function depends_on() { - return array('phpbb_db_migration_data_30x_11'); + return array('phpbb_db_migration_data_30x_3_0_11'); } public function update_schema() -- cgit v1.2.1 From a665ad5c2e44922fbd9790597913091c68311533 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 18:58:19 -0600 Subject: [feature/migrations] Remove user_msnm migration PHPBB3-9737 --- phpBB/includes/db/migration/data/310/dev.php | 1 + .../includes/db/migration/data/310/remove_msnm.php | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/remove_msnm.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php index 13b36bbf30..34f081bf62 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -21,6 +21,7 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration 'phpbb_db_migration_data_310_style_update_p2', 'phpbb_db_migration_data_310_timezone_p2', 'phpbb_db_migration_data_310_reported_posts_display', + 'phpbb_db_migration_data_310_remove_msnm', ); } diff --git a/phpBB/includes/db/migration/data/310/remove_msnm.php b/phpBB/includes/db/migration/data/310/remove_msnm.php new file mode 100644 index 0000000000..521161df6b --- /dev/null +++ b/phpBB/includes/db/migration/data/310/remove_msnm.php @@ -0,0 +1,43 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_msnm'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'users' => array( + 'user_msnm', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_msnm' => array('VCHAR_UNI', ''), + ), + ), + ); + } +} -- cgit v1.2.1 From daf243026a1c6bcd369381433b556732674c41f6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 6 Feb 2013 13:08:35 -0600 Subject: [ticket/11350] Do not pass $db by reference; typehint phpbb_db_driver PHPBB3-11350 --- phpBB/includes/db/db_tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index a4bf40fcd7..9235317958 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -303,7 +303,7 @@ class phpbb_db_tools * @param phpbb_db_driver $db Database connection * @param bool $return_statements True if only statements should be returned and no SQL being executed */ - function phpbb_db_tools(&$db, $return_statements = false) + function phpbb_db_tools(phpbb_db_driver $db, $return_statements = false) { $this->db = $db; $this->return_statements = $return_statements; -- cgit v1.2.1 From 5705c3d377d097ef8bf7b99863eabc08fe3276e7 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 6 Feb 2013 13:14:40 -0600 Subject: [feature/migrations] Fix path to extension migrations PHPBB3-11318 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 018324d5d6..008bd35376 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -520,7 +520,7 @@ class phpbb_extension_manager protected function handle_migrations($extension_name, $mode) { $migrator = $this->container->get('migrator'); - $migrations_path = $this->get_extension_path($extension_name) . 'migrations'; + $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; if (file_exists($migrations_path) && is_dir($migrations_path)) { $migrator->load_migrations($migrations_path); -- cgit v1.2.1 From a8da6b89e9da1d3b4e16317c21fc88fa1173d0f1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:01:40 -0600 Subject: [feature/migrations] Inject Migrator instead of using the container to fetch PHPBB3-11318 --- phpBB/includes/extension/manager.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 008bd35376..926cc015de 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -29,6 +29,7 @@ class phpbb_extension_manager protected $db; protected $config; + protected $migrator; protected $cache; protected $php_ext; protected $extensions; @@ -48,12 +49,13 @@ class phpbb_extension_manager * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_db_migrator $migrator, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; + $this->migrator = $migrator; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -519,11 +521,10 @@ class phpbb_extension_manager */ protected function handle_migrations($extension_name, $mode) { - $migrator = $this->container->get('migrator'); $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; if (file_exists($migrations_path) && is_dir($migrations_path)) { - $migrator->load_migrations($migrations_path); + $this->migrator->load_migrations($migrations_path); } // What is a safe limit of execution time? Half the max execution time should be safe. @@ -532,9 +533,9 @@ class phpbb_extension_manager if ($mode == 'enable') { - while (!$migrator->finished()) + while (!$this->migrator->finished()) { - $migrator->update(); + $this->migrator->update(); // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $start_time) >= $safe_time_limit) @@ -545,9 +546,9 @@ class phpbb_extension_manager } else if ($mode == 'purge') { - while ($migrator->migration_state() !== false) + while ($this->migrator->migration_state() !== false) { - $migrator->revert(); + $this->migrator->revert(); // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $start_time) >= $safe_time_limit) -- cgit v1.2.1 From fc4d5f74c0b82989370e899939d6f31e9a85723d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:05:39 -0600 Subject: [feature/migrations] Call revert correctly when purging an extension PHPBB3-11318 --- phpBB/includes/extension/manager.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 926cc015de..21a9ec1370 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -522,11 +522,13 @@ class phpbb_extension_manager protected function handle_migrations($extension_name, $mode) { $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; - if (file_exists($migrations_path) && is_dir($migrations_path)) + if (!file_exists($migrations_path) || !is_dir($migrations_path)) { - $this->migrator->load_migrations($migrations_path); + return true; } + $migrations = $this->migrator->load_migrations($migrations_path); + // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = (ini_get('max_execution_time') / 2); $start_time = time(); @@ -546,14 +548,17 @@ class phpbb_extension_manager } else if ($mode == 'purge') { - while ($this->migrator->migration_state() !== false) + foreach ($migrations as $migration) { - $this->migrator->revert(); - - // Are we approaching the time limit? If so we want to pause the update and continue after refreshing - if ((time() - $start_time) >= $safe_time_limit) + while ($this->migrator->migration_state($migration) !== false) { - return false; + $this->migrator->revert($migration); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } } } } -- cgit v1.2.1 From cacaffee6e013e43b75212d49960922f88f9f69a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:56:42 -0600 Subject: [feature/migrations] Add language strings for migrations errors Unfulfillable returns string of the missing dependency name now if the migration is unfulfillable (this is significantly more helpful). PHPBB3-11351 --- phpBB/includes/db/migration/tool/config.php | 2 +- phpBB/includes/db/migration/tool/module.php | 6 +++--- phpBB/includes/db/migration/tool/permission.php | 6 +++--- phpBB/includes/db/migrator.php | 16 +++++++++------- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index d9cc20053e..458a25fb66 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -49,7 +49,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac { if (isset($this->config[$config_name])) { - throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); + throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXIST', $config_name); } $this->config->set($config_name, $config_value, !$is_dynamic); diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index afe1f21ec5..4d7fae2bb0 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -242,14 +242,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!$module_id) { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $parent); } $parent = $data['parent_id'] = $module_id; } else if (!$this->exists($class, false, $parent)) { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $parent); } if ($this->exists($class, $parent, $data['module_langname'])) @@ -477,7 +477,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $result = $acp_modules->delete_module($module_id); if (!empty($result)) { - throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); + throw new phpbb_db_migration_exception('MODULE_NOT_REMOVABLE', $module_id, $result); } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 001d090f5a..4231fbe1dd 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -107,7 +107,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte { if ($this->exists($auth_option, $global)) { - throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); + throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXIST', $auth_option); } // We've added permissions, so set to true to notify the user. @@ -252,7 +252,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte if ($role_id) { - throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); + return; } $sql = 'SELECT MAX(role_order) AS max_role_order @@ -290,7 +290,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte if (!$role_id) { - throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $old_role_name); } $sql = 'UPDATE ' . ACL_ROLES_TABLE . " diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4456600b0a..3c311e96d7 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -228,9 +228,10 @@ class phpbb_db_migrator { foreach ($this->migrations as $name) { - if ($this->unfulfillable($name)) + $unfulfillable = $this->unfulfillable($name); + if ($unfulfillable !== false) { - throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); } } } @@ -674,13 +675,13 @@ class phpbb_db_migrator * Checks if a migration's dependencies can even theoretically be satisfied. * * @param string $name The class name of the migration - * @return bool Whether the migration cannot be fulfilled + * @return bool|string False if fulfillable, string of missing migration name if unfulfillable */ public function unfulfillable($name) { if (isset($this->migration_state[$name])) { - return false; + return $name; } if (!class_exists($name)) @@ -693,9 +694,10 @@ class phpbb_db_migrator foreach ($depends as $depend) { - if ($this->unfulfillable($depend)) + $unfulfillable = $this->unfulfillable($depend); + if ($unfulfillable !== false) { - return true; + return $unfulfillable; } } @@ -715,7 +717,7 @@ class phpbb_db_migrator { // skip unfulfillable migrations, but fulfillables mean we // are not finished yet - if ($this->unfulfillable($name)) + if ($this->unfulfillable($name) !== false) { continue; } -- cgit v1.2.1 From b398fa2050ab720d9a3ae2b809bb3cdf4f153dc6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:09:29 -0600 Subject: [feature/migrations] Catch and display errors from the migrator PHPBB3-11318 --- phpBB/includes/acp/acp_extensions.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a0bcf62ecc..17ab4f3169 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -37,7 +37,7 @@ class acp_extensions $this->template = $template; $this->user = $user; - $user->add_lang(array('install', 'acp/extensions')); + $user->add_lang(array('install', 'acp/extensions', 'migrator')); $this->page_title = 'ACP_EXTENSIONS'; @@ -103,11 +103,18 @@ class acp_extensions trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); } - if ($phpbb_extension_manager->enable_step($ext_name)) + try { - $template->assign_var('S_NEXT_STEP', true); + if ($phpbb_extension_manager->enable_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + } + } + catch (phpbb_db_migration_exception $e) + { + $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); } $this->tpl_name = 'acp_ext_enable'; @@ -156,11 +163,18 @@ class acp_extensions break; case 'purge': - if ($phpbb_extension_manager->purge_step($ext_name)) + try { - $template->assign_var('S_NEXT_STEP', true); + if ($phpbb_extension_manager->purge_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + } + } + catch (phpbb_db_migration_exception $e) + { + $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); } $this->tpl_name = 'acp_ext_purge'; -- cgit v1.2.1 From f18b096df945648aa3ecc2b8b914869871b1823f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:10:56 -0600 Subject: [feature/migrations] getParameters function for migration exception PHPBB3-11351 --- phpBB/includes/db/migration/exception.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index ffdcd97780..b3abcdb5e5 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -52,4 +52,14 @@ class phpbb_db_migration_exception extends \Exception { return $this->message . ': ' . var_export($this->parameters, true); } + + /** + * Get the parameters + * + * @return array + */ + public function getParameters() + { + return $this->parameters; + } } -- cgit v1.2.1 From f9a1b27a99e30a41db4facd415b39a690614d6c6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:16:39 -0600 Subject: [feature/migrations] Fix unfulfillable function Returned unfulfillable name in the wrong place previously PHPBB3-11351 --- phpBB/includes/db/migrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 3c311e96d7..41d996b1e3 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -681,12 +681,12 @@ class phpbb_db_migrator { if (isset($this->migration_state[$name])) { - return $name; + return false; } if (!class_exists($name)) { - return true; + return $name; } $migration = $this->get_migration($name); -- cgit v1.2.1 From 8ec55b062dbaf40f5ad3aec49bf987a14b34dfe8 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Mon, 11 Feb 2013 15:29:12 +0530 Subject: [ticket/11196] Changed 401 response message in session.php. In session.php 401 response message was "Not Authorized". I changed it to "Unauthorized". PHPBB3-11196 --- phpBB/includes/session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 496c12a0d1..d980f50e05 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -325,7 +325,7 @@ class session // if no session id is set, redirect to index.php if (defined('NEED_SID') && (!isset($_GET['sid']) || $this->session_id !== $_GET['sid'])) { - send_status_line(401, 'Not authorized'); + send_status_line(401, 'Unauthorized'); redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } -- cgit v1.2.1 From f6bb14569b0a777d3511b732201af9d1a415f2ed Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 15 Feb 2013 22:19:24 -0600 Subject: [feature/migrations] getLocalisedMessage function for migration exception PHPBB3-11351 --- phpBB/includes/db/migration/exception.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index b3abcdb5e5..e84330dd71 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -62,4 +62,18 @@ class phpbb_db_migration_exception extends \Exception { return $this->parameters; } + + /** + * Get localised message (with $user->lang()) + * + * @param phpbb_user $user + * @return string + */ + public function getLocalisedMessage(phpbb_user $user) + { + $parameters = $this->getParameters(); + array_unshift($parameters, $this->getMessage()); + + return call_user_func_array(array($user, 'lang'), $parameters); + } } -- cgit v1.2.1 From 872773a21897ccad754a53d7c8ad7899bcc05796 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 15 Feb 2013 22:22:13 -0600 Subject: [feature/migrations] Use getLocalisedMessage() function to get error message PHPBB3-11318 --- phpBB/includes/acp/acp_extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 17ab4f3169..24211196bd 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -114,7 +114,7 @@ class acp_extensions } catch (phpbb_db_migration_exception $e) { - $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); + $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_enable'; @@ -174,7 +174,7 @@ class acp_extensions } catch (phpbb_db_migration_exception $e) { - $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); + $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_purge'; -- cgit v1.2.1 From 5b99f0c113390959f693222055715413addef34e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 18 Feb 2013 14:01:46 +0530 Subject: [ticket/11359] close span PHPBB3-11359 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 4bacf74f93..07bcbdadc1 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -878,7 +878,7 @@ class phpbb_search_fulltext_sphinx
' . $this->user->lang['MIB'] . '
-

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
+

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 3c6256b3e7489b9aca1e153b3e3bb754f3dd6a7d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 18 Feb 2013 14:05:25 +0530 Subject: [ticket/11359] add id attribute to textarea PHPBB3-11359 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 07bcbdadc1..6c66499d21 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -879,7 +879,7 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
-
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
+
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 38360c71f298efee54396118b8afb5c642c79db3 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 18 Feb 2013 14:13:31 +0530 Subject: [ticket/11359] html escape sphinx config data PHPBB3-11359 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 6c66499d21..7304e70ff8 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -879,7 +879,7 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
-
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
+
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 737b99966de8e12ffa13d762b7065043a39399d7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 03:39:51 +0530 Subject: [ticket/11179] add search query in case initial one fails changes the start parameter according to the total search results and executes the search query again to get the results. PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 324c214e91..acb1a7bde8 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -381,7 +381,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { return $result_count; } - $id_ary = array(); $join_topic = ($type == 'posts') ? false : true; @@ -490,7 +489,38 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!sizeof($id_ary)) { - return false; + $sql_count = "SELECT COUNT(*) as result_count + FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p + WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) + $sql_where_options + ORDER BY $sql_sort"; + $result = $this->db->sql_query($sql_count); + $total_match_count = (int) $this->db->sql_fetchfield('result_count'); + + if ($total_match_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $total_match_count) + { + $start = floor(($total_match_count - 1) / $per_page) * $per_page; + } + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + } + + if (!sizeof($id_ary)) + { + return false; + } } // if the total result count is not cached yet, retrieve it from the db -- cgit v1.2.1 From 00d34617ccb6a53185f0e872a735b4dd2f65009b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 13:36:14 +0100 Subject: [ticket/11179] correct the start parameter while retrieving from cache Start parameter if not between 0 and the total result count of the cached search results is changed accordingly PHPBB3-11179 --- phpBB/includes/search/base.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index b364dead9a..11e5535979 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -97,7 +97,6 @@ class phpbb_search_base function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) { global $cache; - if (!($stored_ids = $cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key @@ -109,6 +108,19 @@ class phpbb_search_base $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; $complete = true; + // change start parameter in case out of bounds + if ($result_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + } + // change the start to the actual end of the current request if the sort direction differs // from the dirction in the cache and reverse the ids later if ($reverse_ids) -- cgit v1.2.1 From 3e5ef8ab2cc1d8c6e0850e36ddb546489cc5ab12 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 13:39:40 +0100 Subject: [ticket/11179] pass start parameter by reference start parameter is passed by reference so that in case it is not in bounds the changes made to it are reflected back to the phpBB/search.php file PHPBB3-11179 --- phpBB/includes/search/base.php | 2 +- phpBB/includes/search/fulltext_mysql.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index 11e5535979..2047742367 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -94,7 +94,7 @@ class phpbb_search_base * * @return int SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE */ - function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) + function obtain_ids($search_key, &$result_count, &$id_ary, &$start, $per_page, $sort_dir) { global $cache; if (!($stored_ids = $cache->get('_search_results_' . $search_key))) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index acb1a7bde8..749353b2ee 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -353,7 +353,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) -- cgit v1.2.1 From 1c9c666ef193942a2d88ec59741ddc49900e92e9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 14:17:38 +0100 Subject: [ticket/11179] use FOUND_ROWS query to re-search with changed start param PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 60 ++++++++++++-------------------- 1 file changed, 22 insertions(+), 38 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 749353b2ee..3ecc2cd39d 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -375,6 +375,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base implode(',', $author_ary) ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -487,47 +492,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $id_ary = array_unique($id_ary); - if (!sizeof($id_ary)) - { - $sql_count = "SELECT COUNT(*) as result_count - FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) - $sql_where_options - ORDER BY $sql_sort"; - $result = $this->db->sql_query($sql_count); - $total_match_count = (int) $this->db->sql_fetchfield('result_count'); - - if ($total_match_count) - { - if ($start < 0) - { - $start = 0; - } - else if ($start >= $total_match_count) - { - $start = floor(($total_match_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); - - $id_ary = array_unique($id_ary); - } - - if (!sizeof($id_ary)) - { - return false; - } - } - // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { - $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $this->db->sql_query($sql); + $sql_found_rows = 'SELECT FOUND_ROWS() as result_count'; + $result = $this->db->sql_query($sql_found_rows); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); @@ -537,6 +506,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From 2601411a9cfb79de1c45523005e91f00a8583ad1 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 14:28:29 +0100 Subject: [ticket/11179] correct start parameter for author search PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 3ecc2cd39d..54e2007da3 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -571,6 +571,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $author_name, ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -676,8 +681,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // retrieve the total result count if needed if (!$result_count) { - $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $this->db->sql_query($sql); + $sql_found_rows = 'SELECT FOUND_ROWS() as result_count'; + $result = $this->db->sql_query($sql_found_rows); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); @@ -687,6 +692,20 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From 80f8e3abceabab658a5a935e5a6079e73f663698 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 14:29:39 +0100 Subject: [ticket/11179] pass start param by reference in author search PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 54e2007da3..69f76ba99e 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -547,7 +547,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) @@ -578,7 +578,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // try reading the results from cache $result_count = 0; - if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $result_count, $id_ary, &$start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) { return $result_count; } -- cgit v1.2.1 From 2cb48f034153038d71d89ab58904cd048b8524d9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:35:05 +0100 Subject: [ticket/11179] correct start parameter in psql keyword search PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 1475cc31d0..d968a934f4 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -371,6 +371,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base implode(',', $author_ary) ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -495,11 +500,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $id_ary = array_unique($id_ary); - if (!sizeof($id_ary)) - { - return false; - } - // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { @@ -518,6 +518,21 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $this->db->sql_transaction('commit'); + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From ef88edbcf69541bd79e220c87c444b33a6751c67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:44:16 +0100 Subject: [ticket/11179] correct start param in author search of postgres PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index d968a934f4..e8a5353b05 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -583,6 +583,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $author_name, ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -725,6 +730,20 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $this->db->sql_transaction('commit'); + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From bc77ca4d4eb6a5bcf3e47706c6b6fd2b0fe33f82 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:45:15 +0100 Subject: [ticket/11179] pass start param by reference in postgres PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index e8a5353b05..bdc2fa4f19 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -343,7 +343,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) @@ -559,7 +559,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) -- cgit v1.2.1 From 16bbdf4a52b2cb2fa4aa2cd607ae726ea1c7af67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 11 Nov 2012 10:11:58 +0100 Subject: [ticket/11179] minor fixes Amends comments to start with capitals. Reinsert blank lines which were not supposed to be removed PHPBB3-11179 --- phpBB/includes/search/base.php | 3 ++- phpBB/includes/search/fulltext_mysql.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index 2047742367..914cef9167 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -97,6 +97,7 @@ class phpbb_search_base function obtain_ids($search_key, &$result_count, &$id_ary, &$start, $per_page, $sort_dir) { global $cache; + if (!($stored_ids = $cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key @@ -108,7 +109,7 @@ class phpbb_search_base $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; $complete = true; - // change start parameter in case out of bounds + // Change start parameter in case out of bounds if ($result_count) { if ($start < 0) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 69f76ba99e..ad5119f67c 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -386,6 +386,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { return $result_count; } + $id_ary = array(); $join_topic = ($type == 'posts') ? false : true; -- cgit v1.2.1 From f0d63594e68fa7a165b8ba90d0fcf35f38e42de9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 14:15:04 +0530 Subject: [ticket/11179] fix success query path for mysql Additional query to check start parameter executed only incase of no results. PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index ad5119f67c..4dc62753aa 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -510,17 +510,17 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); @@ -696,16 +696,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } if (sizeof($id_ary)) { -- cgit v1.2.1 From 8b7f306897cddcb16cbed50488848ee357c26f39 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 14:31:12 +0530 Subject: [ticket/11179] fix success query path for postgres Additional query to check start parameter executed only incase of no results. PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index bdc2fa4f19..eeb628b18f 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -521,17 +521,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = $row[$field]; - } - $this->db->sql_freeresult($result); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); @@ -733,16 +733,16 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } if (sizeof($id_ary)) { -- cgit v1.2.1 From a0ae223ef46e30c9413350ed7c4e52eaab5bb159 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Dec 2012 19:10:48 +0530 Subject: [ticket/11179] correct start parameter in native keyword search PHPBB3-11179 --- phpBB/includes/search/fulltext_native.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 53df8348ae..fccdcd855e 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -516,7 +516,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts. if (empty($this->search_query)) @@ -855,10 +855,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base } $this->db->sql_freeresult($result); - if (!sizeof($id_ary)) - { - return false; - } // if we use mysql and the total result count is not cached yet, retrieve it from the db if (!$total_results && $is_mysql) @@ -867,14 +863,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_array_copy = $sql_array; $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id '; - $sql = $this->db->sql_build_query('SELECT', $sql_array_copy); + $sql_calc = $this->db->sql_build_query('SELECT', $sql_array_copy); unset($sql_array_copy); - $this->db->sql_query($sql); + $this->db->sql_query($sql_calc); $this->db->sql_freeresult($result); - $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $this->db->sql_query($sql); + $sql_count = 'SELECT FOUND_ROWS() as total_results'; + $result = $this->db->sql_query($sql_count); $total_results = (int) $this->db->sql_fetchfield('total_results'); $this->db->sql_freeresult($result); @@ -884,6 +880,20 @@ class phpbb_search_fulltext_native extends phpbb_search_base } } + if ($start >= $total_results) + { + $start = floor(($total_results - 1) / $per_page) * $per_page; + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')]; + } + $this->db->sql_freeresult($result); + + } + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, $this->search_query, $author_ary, $total_results, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From 2ff874fe930d458382212cfe5495080231ec76e6 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Dec 2012 19:11:20 +0530 Subject: [ticket/11179] correct start parameter in native author search PHPBB3-11179 --- phpBB/includes/search/fulltext_native.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index fccdcd855e..c9f33054fc 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -920,7 +920,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) @@ -1106,13 +1106,13 @@ class phpbb_search_fulltext_native extends phpbb_search_base if (!$total_results && $is_mysql) { // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. - $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); + $sql_calc = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); - $this->db->sql_query($sql); + $this->db->sql_query($sql_calc); $this->db->sql_freeresult($result); - $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $this->db->sql_query($sql); + $sql_count = 'SELECT FOUND_ROWS() as total_results'; + $result = $this->db->sql_query($sql_count); $total_results = (int) $this->db->sql_fetchfield('total_results'); $this->db->sql_freeresult($result); @@ -1122,6 +1122,19 @@ class phpbb_search_fulltext_native extends phpbb_search_base } } + if ($start >= $total_results) + { + $start = floor(($total_results - 1) / $per_page) * $per_page; + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + } + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From 38bb7dca31740f9d4f188b75167f736ee6666c2f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Dec 2012 21:54:41 +0530 Subject: [ticket/11179] correct start parameter in sphinx search PHPBB3-11179 --- phpBB/includes/search/fulltext_sphinx.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 7304e70ff8..48445d0794 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -454,7 +454,7 @@ class phpbb_search_fulltext_sphinx * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts. if (!strlen($this->search_query) && !sizeof($author_ary)) @@ -609,6 +609,25 @@ class phpbb_search_fulltext_sphinx } } + $result_count = $result['total_found']; + + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + + $this->sphinx->SetLimits((int) $start, (int) $per_page, SPHINX_MAX_MATCHES); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + + // Could be connection to localhost:9312 failed (errno=111, + // msg=Connection refused) during rotate, retry if so + $retries = SPHINX_CONNECT_RETRIES; + while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--) + { + usleep(SPHINX_CONNECT_WAIT_TIME); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + } + } + $id_ary = array(); if (isset($result['matches'])) { @@ -629,8 +648,6 @@ class phpbb_search_fulltext_sphinx return false; } - $result_count = $result['total_found']; - $id_ary = array_slice($id_ary, 0, (int) $per_page); return $result_count; -- cgit v1.2.1 From 1ee4702ec51ecfc7d40c8768ba7927439c73002c Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 25 Jan 2013 18:15:55 +0530 Subject: [ticket/11179] remove extra & in function call PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 4dc62753aa..adaf025730 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -579,7 +579,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // try reading the results from cache $result_count = 0; - if ($this->obtain_ids($search_key, $result_count, $id_ary, &$start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) { return $result_count; } -- cgit v1.2.1 From ae3a22bd0c06bd6098c229963402d660572a0598 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 23 Feb 2013 11:06:48 +0100 Subject: [ticket/11361] Make sure that array passed to strtr() has the proper format. The array $date_cache[$format]['lang'] passed to strtr() contains a sub-array which results in an E_NOTICE being thrown for 'Array to string conversion' on PHP 5.4. Ensure that the array passed to strtr() is one-dimensional by filtering out non-string values. PHPBB3-11361 --- phpBB/includes/session.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index d980f50e05..b93f2ff65e 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -2156,7 +2156,8 @@ class user extends session 'is_short' => strpos($format, '|'), 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), 'format_long' => str_replace('|', '', $format), - 'lang' => $this->lang['datetime'], + // Filter out values that are not strings (e.g. arrays) for strtr(). + 'lang' => array_filter($this->lang['datetime'], 'is_string'), ); // Short representation of month in format? Some languages use different terms for the long and short format of May -- cgit v1.2.1 From b7a222cdd593edb3e61183d9e28707ac9005aa82 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 Feb 2013 14:20:56 -0500 Subject: [ticket/11298] Fix typo in language key; EXTENSIONS -> EXTENSION PHPBB3-11298 --- phpBB/includes/acp/info/acp_extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/info/acp_extensions.php b/phpBB/includes/acp/info/acp_extensions.php index 03d7059165..174b365af0 100644 --- a/phpBB/includes/acp/info/acp_extensions.php +++ b/phpBB/includes/acp/info/acp_extensions.php @@ -16,10 +16,10 @@ class acp_extensions_info { return array( 'filename' => 'acp_extensions', - 'title' => 'ACP_EXTENSIONS_MANAGEMENT', + 'title' => 'ACP_EXTENSION_MANAGEMENT', 'version' => '1.0.0', 'modes' => array( - 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_EXTENSIONS_MANAGEMENT')), + 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_EXTENSION_MANAGEMENT')), ), ); } -- cgit v1.2.1 From 4bf64b5e38efd194b6ab41fcc5d62ee0cc6fad5a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 23 Feb 2013 15:10:21 -0600 Subject: [feature/migrations] Fully revert the removal of the user_msnm field PHBB3-9737 --- phpBB/includes/db/migration/data/310/dev.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php index 34f081bf62..13b36bbf30 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -21,7 +21,6 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration 'phpbb_db_migration_data_310_style_update_p2', 'phpbb_db_migration_data_310_timezone_p2', 'phpbb_db_migration_data_310_reported_posts_display', - 'phpbb_db_migration_data_310_remove_msnm', ); } -- cgit v1.2.1 From e8b3e8498d9842296a905fdaad8c0c32e31bceb4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Feb 2013 12:54:05 +0100 Subject: [ticket/7262] Backport set_config() and set_config_count() docs from develop. PHPBB3-7262 --- phpBB/includes/functions.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 571c863839..04b69f8c69 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -137,7 +137,14 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) } /** -* Set config value. Creates missing config entry. +* Sets a configuration option's value. +* +* @param string $config_name The configuration option's name +* @param string $config_value New configuration value +* @param bool $is_dynamic Whether this variable should be cached or if it +* changes too frequently to be efficiently cached. +* +* @return null */ function set_config($config_name, $config_value, $is_dynamic = false) { @@ -166,7 +173,14 @@ function set_config($config_name, $config_value, $is_dynamic = false) } /** -* Set dynamic config value with arithmetic operation. +* Increments an integer config value directly in the database. +* +* @param string $config_name The configuration option's name +* @param int $increment Amount to increment by +* @param bool $is_dynamic Whether this variable should be cached or if it +* changes too frequently to be efficiently cached. +* +* @return null */ function set_config_count($config_name, $increment, $is_dynamic = false) { -- cgit v1.2.1 From a9037a68c177d396b2ed4b9bfcaad64536a01aaa Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Feb 2013 13:03:48 +0100 Subject: [ticket/7262] Add $is_dynamic example to set_config() and set_config_count(). The logic is the other way around here in comparison to develop's phpbb_config_db class, so add examples to make things more clear. PHPBB3-7262 --- phpBB/includes/functions.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 04b69f8c69..2ca7d7f898 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -141,8 +141,9 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) * * @param string $config_name The configuration option's name * @param string $config_value New configuration value -* @param bool $is_dynamic Whether this variable should be cached or if it -* changes too frequently to be efficiently cached. +* @param bool $is_dynamic Whether this variable should be cached (false) or +* if it changes too frequently (true) to be +* efficiently cached. * * @return null */ @@ -177,8 +178,9 @@ function set_config($config_name, $config_value, $is_dynamic = false) * * @param string $config_name The configuration option's name * @param int $increment Amount to increment by -* @param bool $is_dynamic Whether this variable should be cached or if it -* changes too frequently to be efficiently cached. +* @param bool $is_dynamic Whether this variable should be cached (false) or +* if it changes too frequently (true) to be +* efficiently cached. * * @return null */ -- cgit v1.2.1 From 6bf64d5620b1b9f165a65b50042c391a29ef151c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Feb 2013 13:37:52 +0100 Subject: [ticket/7262] Add note about set_config() not updating is_dynamic. PHPBB3-7262 --- phpBB/includes/functions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2ca7d7f898..ccd2d3147c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -139,6 +139,9 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) /** * Sets a configuration option's value. * +* Please note that this function does not update the is_dynamic value for +* an already existing config option. +* * @param string $config_name The configuration option's name * @param string $config_value New configuration value * @param bool $is_dynamic Whether this variable should be cached (false) or -- cgit v1.2.1 From d2a15d9afe06509ff3e9fe5b6463800f66813783 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 24 Feb 2013 17:42:53 +0100 Subject: [ticket/10896] Add missing email validation lost in develop merge Fix incomplete merge, by adding a piece of code moved to another file in olympus back. PHPBB3-10896 --- phpBB/includes/functions_acp.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 32fd76e74d..d6bd9e35dd 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -443,6 +443,13 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) } break; + case 'email': + if (!preg_match('/^' . get_preg_expression('email') . '$/i', $cfg_array[$config_name])) + { + $error[] = $user->lang['EMAIL_INVALID_EMAIL']; + } + break; + // Absolute path case 'script_path': if (!$cfg_array[$config_name]) -- cgit v1.2.1 From f8e184c54e85dc55a803b76a6ccefb769ef38e17 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Mon, 18 Feb 2013 11:04:14 +0530 Subject: [ticket/11355] Wrong error message when no user is selected. In ACP group membership management, if you select 'remove member from group' without selecting any users and submit,it will display a wrong error after confirmbox. Since no users are selected, this should not go even until confirmbox. Added a new condition to check weather any users are selected when the action is 'deleteusers' in acp_groups.php and disply a correct error. PHPBB3-11355 --- phpBB/includes/acp/acp_groups.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 486616c33d..ec44f4fc0c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -179,6 +179,10 @@ class acp_groups break; case 'deleteusers': + if (!$name_ary) + { + trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); + } case 'delete': if (!$group_id) { @@ -795,4 +799,4 @@ class acp_groups } } -?> \ No newline at end of file +?> -- cgit v1.2.1 From ab530a999ed64a2e1fcc10252bdae6d9139d7538 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Thu, 21 Feb 2013 22:47:42 +0530 Subject: [ticket/11355] Referred proper variable when validating selection. Earlier PR was referring wrong variable $name_ary. Changed it to $mark_ary which actually contains selected user ids. PHPBB3-11355 --- phpBB/includes/acp/acp_groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index ec44f4fc0c..bbe85f8038 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -179,7 +179,7 @@ class acp_groups break; case 'deleteusers': - if (!$name_ary) + if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } -- cgit v1.2.1 From 373c9a3f4ea92f1bcbe63404a2b3bf356fe5abcb Mon Sep 17 00:00:00 2001 From: erangamapa Date: Mon, 18 Feb 2013 11:17:27 +0530 Subject: [ticket/11358] Success message even without selecting a user. In group membership management, if you perform the action 'Make group default for member' without selecting any user, a confirm box will be displayed and will show a success message after confirming. Added a new condition to fix this issue in acp_groups.php. It will check weather any users are selected before performing above action. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index bbe85f8038..dbe692aee0 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,6 +120,10 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } + else if (!$name_ary) + { + trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); + } if (confirm_box(true)) { -- cgit v1.2.1 From 880786d68610aff0c30573dc599af9e5b3ad56cf Mon Sep 17 00:00:00 2001 From: erangamapa Date: Thu, 21 Feb 2013 22:25:12 +0530 Subject: [ticket/11358] Removed redundant code and referred proper variable. Error was thrown when no users are selected before executing the code chunk which manually adds all the user to make the group default. Removed this code and referred $mark_ary instead of $name_ary which will not have selected user ids. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 42 ++------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index dbe692aee0..af25d9d014 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,7 +120,7 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if (!$name_ary) + else if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } @@ -128,45 +128,7 @@ class acp_groups if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; - - if (!sizeof($mark_ary)) - { - $start = 0; - - do - { - $sql = 'SELECT user_id - FROM ' . USER_GROUP_TABLE . " - WHERE group_id = $group_id - ORDER BY user_id"; - $result = $db->sql_query_limit($sql, 200, $start); - - $mark_ary = array(); - if ($row = $db->sql_fetchrow($result)) - { - do - { - $mark_ary[] = $row['user_id']; - } - while ($row = $db->sql_fetchrow($result)); - - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); - - $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200; - } - else - { - $start = 0; - } - $db->sql_freeresult($result); - } - while ($start); - } - else - { - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); - } - + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else -- cgit v1.2.1 From 538b09ba6115a1f90821a18d045f2056e66b5178 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Fri, 22 Feb 2013 00:31:55 +0530 Subject: [ticket/11358] Enabled link making all users default for a group. Detect whether link is clicked or form is posted for making users default for a group. If form is posted and no users are selected, validation happens and displays an error message. When the link is clicked, all the users will be default users for that group. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 42 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index af25d9d014..c70327c6f1 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,7 +120,7 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if (empty($mark_ary)) + else if (empty($mark_ary) && $request->is_set_post('default')) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } @@ -128,7 +128,45 @@ class acp_groups if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + + if (!sizeof($mark_ary)) + { + $start = 0; + + do + { + $sql = 'SELECT user_id + FROM ' . USER_GROUP_TABLE . " + WHERE group_id = $group_id + ORDER BY user_id"; + $result = $db->sql_query_limit($sql, 200, $start); + + $mark_ary = array(); + if ($row = $db->sql_fetchrow($result)) + { + do + { + $mark_ary[] = $row['user_id']; + } + while ($row = $db->sql_fetchrow($result)); + + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + + $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200; + } + else + { + $start = 0; + } + $db->sql_freeresult($result); + } + while ($start); + } + else + { + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + } + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else -- cgit v1.2.1 From c0a39537e38c350365c0baa74be31c000b1e9381 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Fri, 22 Feb 2013 09:53:49 +0530 Subject: [ticket/11358] Changed the action parameter value to represent the link. Changed the action parameter value to recognize whether 'Make default group for every member' is clicked. If so execute a seperate code block under switch statement for $action and add all the users as default for the group. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 50 +++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index c70327c6f1..33d5c16ed0 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,7 +120,7 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if (empty($mark_ary) && $request->is_set_post('default')) + else if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } @@ -128,9 +128,26 @@ class acp_groups if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; - - if (!sizeof($mark_ary)) + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); + } + else + { + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + 'mark' => $mark_ary, + 'g' => $group_id, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + + break; + case 'defaultbylink': + if (confirm_box(true)) { + $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; + $start = 0; do @@ -161,27 +178,20 @@ class acp_groups $db->sql_freeresult($result); } while ($start); + + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + 'mark' => $mark_ary, + 'g' => $group_id, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); } - - trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); - } - else - { - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( - 'mark' => $mark_ary, - 'g' => $group_id, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'deleteusers': if (empty($mark_ary)) { @@ -691,7 +701,7 @@ class acp_groups 'U_ACTION' => $this->u_action . "&g=$group_id", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), - 'U_DEFAULT_ALL' => "{$this->u_action}&action=default&g=$group_id", + 'U_DEFAULT_ALL' => "{$this->u_action}&action=defaultbylink&g=$group_id", )); // Grab the members -- cgit v1.2.1 From 1b39d6d65e2af632e6ad2ccba7fa2e61ab36c30c Mon Sep 17 00:00:00 2001 From: erangamapa Date: Sun, 24 Feb 2013 21:34:29 +0530 Subject: [ticket/11358] Changed the name of post parameter. Replaced the parameter name 'defaultbylink' to a meaningful name 'set_default_on_all'. Parameter is used for making all users default for selected group in acp_groups.php. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 33d5c16ed0..00ca26dfa6 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -143,7 +143,7 @@ class acp_groups } break; - case 'defaultbylink': + case 'set_default_on_all': if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; @@ -701,7 +701,7 @@ class acp_groups 'U_ACTION' => $this->u_action . "&g=$group_id", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), - 'U_DEFAULT_ALL' => "{$this->u_action}&action=defaultbylink&g=$group_id", + 'U_DEFAULT_ALL' => "{$this->u_action}&action=set_default_on_all&g=$group_id", )); // Grab the members -- cgit v1.2.1 From 4615698807e17c55d5ab93e872f7efefb1e6acd7 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 24 Feb 2013 19:07:24 +0100 Subject: [ticket/10986] message.id fallback to SERVER_NAME or phpbb.generated Rather than send invalid message ids with a missing domain part we try to read one from $_SERVER and otherwise use phpbb.generated PHPBB3-10986 --- phpBB/includes/functions_messenger.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index e837811c86..db2dea33e8 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -389,6 +389,28 @@ class messenger } } + /** + * Generates a valid message id to be used in emails + * + * @return string message id + */ + function generate_message_id() + { + global $config; + + $domain = 'phpbb.generated'; + if ($config['server_name']) + { + $domain = $config['server_name']; + } + else if (!empty($_SERVER['SERVER_NAME'])) + { + $domain = $_SERVER['SERVER_NAME']; + } + + return md5(unique_id(time())) . '@' . $domain; + } + /** * Return email header */ @@ -415,7 +437,7 @@ class messenger $headers[] = 'Return-Path: <' . $config['board_email'] . '>'; $headers[] = 'Sender: <' . $config['board_email'] . '>'; $headers[] = 'MIME-Version: 1.0'; - $headers[] = 'Message-ID: <' . md5(unique_id(time())) . '@' . $config['server_name'] . '>'; + $headers[] = 'Message-ID: <' . $this->generate_message_id() . '>'; $headers[] = 'Date: ' . date('r', time()); $headers[] = 'Content-Type: text/plain; charset=UTF-8'; // format=flowed $headers[] = 'Content-Transfer-Encoding: 8bit'; // 7bit -- cgit v1.2.1 From 6045aa7aa2fb63358e3f736504b17533b1085712 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 25 Feb 2013 19:16:29 -0600 Subject: [ticket/11367] Migrator throws error if migrations table does not exist Force load_migration_state to not throw errors if the table does not exist. PHPBB3-11367 --- phpBB/includes/db/migrator.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 41d996b1e3..ea5de3372f 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -99,18 +99,26 @@ class phpbb_db_migrator { $this->migration_state = array(); + // prevent errors in case the table does not exist yet + $this->db->sql_return_on_error(true); + $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); - while ($migration = $this->db->sql_fetchrow($result)) + if (!$this->db->sql_error_triggered) { - $this->migration_state[$migration['migration_name']] = $migration; + while ($migration = $this->db->sql_fetchrow($result)) + { + $this->migration_state[$migration['migration_name']] = $migration; + + $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); + } - $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); + $this->db->sql_freeresult($result); } - $this->db->sql_freeresult($result); + $this->db->sql_return_on_error(false); } /** -- cgit v1.2.1 From 9a319fefb2ffed58da1d3339d59e53de09521e03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 26 Feb 2013 10:22:13 -0600 Subject: [ticket/11367] Always freeresult PHPBB3-11367 --- phpBB/includes/db/migrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ea5de3372f..74f71775f3 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -114,10 +114,10 @@ class phpbb_db_migrator $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); } - - $this->db->sql_freeresult($result); } + $this->db->sql_freeresult($result); + $this->db->sql_return_on_error(false); } -- cgit v1.2.1