diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 5c450a5cf6..4125491dd0 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -94,6 +94,12 @@ services: calls: - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] + dbal.tools: + file: %core.root_path%includes/db/db_tools.%core.php_ext% + class: phpbb_db_tools + arguments: + - @dbal.conn + event.subscriber_loader: class: phpbb_event_extension_subscriber_loader arguments: @@ -156,6 +162,45 @@ services: tags: - { name: kernel.event_subscriber } + migrator: + class: phpbb_db_migrator + arguments: + - @service_container + + migrator.tools_collection + class: phpbb_di_service_collection + arguments: + - @service_container + + migrator.tools.config: + class: phpbb_db_migration_tools_config + arguments: + - @config + tags: + - { name: migrator:tool } + + migrator.tools.module: + class: phpbb_db_migration_tools_module + arguments: + - @db + - @cache + - @user + - %core.root_path% + - %core.php_ext% + tags: + - { name: migrator:tool } + + migrator.tools.permission: + class: phpbb_db_migration_tools_permission + arguments: + - @db + - @cache + - @auth + - %core.root_path% + - %core.php_ext% + tags: + - { name: migrator:tool } + request: class: phpbb_request diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml index cfc6dbcfed..a9414cf66c 100644 --- a/phpBB/config/tables.yml +++ b/phpBB/config/tables.yml @@ -1,3 +1,4 @@ parameters: tables.config: %core.table_prefix%config tables.ext: %core.table_prefix%ext + tables.migrations: %core.table_prefix%migrations diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 3d3e478032..1abafb3b6d 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1258,7 +1258,7 @@ function get_schema_struct() ), ); - $schema_data['phpbb_moderator_cache'] = array( + $schema_data['phpbb_migrations'] = array( 'COLUMNS' => array( 'forum_id' => array('UINT', 0), 'user_id' => array('UINT', 0), @@ -1273,6 +1273,18 @@ function get_schema_struct() ), ); + $schema_data['phpbb_moderator_cache'] = array( + 'COLUMNS' => array( + 'migration_name' => array('VCHAR', ''), + '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', + ); + $schema_data['phpbb_modules'] = array( 'COLUMNS' => array( 'module_id' => array('UINT', NULL, 'auto_increment'), 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.php similarity index 86% rename from phpBB/includes/db/migration/data/3_0_11_rc2 rename to phpBB/includes/db/migration/data/3_0_11_rc2.php index 6add980c73..f2bed54085 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2 +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -27,5 +27,8 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration 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/update_helpers.php b/phpBB/includes/db/migration/data/timezone.php similarity index 74% rename from phpBB/includes/update_helpers.php rename to phpBB/includes/db/migration/data/timezone.php index 69d678b2f8..89fafbad28 100644 --- a/phpBB/includes/update_helpers.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -1,16 +1,62 @@ 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 @@ -19,7 +65,7 @@ class phpbb_update_helpers * @param $dst int Users daylight saving time * @return string Users new php Timezone which is used since 3.1 */ - function convert_phpbb30_timezone($timezone, $dst) + public function convert_phpbb30_timezone($timezone, $dst) { $offset = $timezone + $dst; 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->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 = $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'); + + /** @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/install/database_update.php b/phpBB/install/database_update.php index 1f89035b43..207ad716de 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -881,6 +881,277 @@ function _add_permission(auth_admin $auth_admin, phpbb_db_driver $db, $permissio function database_update_info() { return array( + // Changes from 3.0.0 to the next version + '3.0.0' => array( + // Add the following columns + 'add_columns' => array( + FORUMS_TABLE => array( + 'display_subforum_list' => array('BOOL', 1), + ), + SESSIONS_TABLE => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + GROUPS_TABLE => array('group_legend'), + ), + 'add_index' => array( + SESSIONS_TABLE => array( + 'session_forum_id' => array('session_forum_id'), + ), + GROUPS_TABLE => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ), + // No changes from 3.0.1-RC1 to 3.0.1 + '3.0.1-RC1' => array(), + // No changes from 3.0.1 to 3.0.2-RC1 + '3.0.1' => array(), + // Changes from 3.0.2-RC1 to 3.0.2-RC2 + '3.0.2-RC1' => array( + 'change_columns' => array( + DRAFTS_TABLE => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + FORUMS_TABLE => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + POSTS_TABLE => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + PRIVMSGS_TABLE => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + TOPICS_TABLE => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + SESSIONS_TABLE => array('session_forum_id'), + ), + 'add_index' => array( + SESSIONS_TABLE => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ), + // No changes from 3.0.2-RC2 to 3.0.2 + '3.0.2-RC2' => array(), + + // Changes from 3.0.2 to 3.0.3-RC1 + '3.0.2' => array( + // Add the following columns + 'add_columns' => array( + STYLES_TEMPLATE_TABLE => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + GROUPS_TABLE => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ), + + // No changes from 3.0.3-RC1 to 3.0.3 + '3.0.3-RC1' => array(), + + // Changes from 3.0.3 to 3.0.4-RC1 + '3.0.3' => array( + 'add_columns' => array( + PROFILE_FIELDS_TABLE => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + STYLES_TABLE => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + STYLES_IMAGESET_TABLE => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + STYLES_IMAGESET_DATA_TABLE => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + STYLES_THEME_TABLE => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + STYLES_TEMPLATE_TABLE => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + STYLES_TEMPLATE_DATA_TABLE => array( + 'template_id' => array('UINT', 0), + ), + FORUMS_TABLE => array( + 'forum_style' => array('UINT', 0), + ), + USERS_TABLE => array( + 'user_style' => array('UINT', 0), + ), + ), + ), + + // Changes from 3.0.4-RC1 to 3.0.4 + '3.0.4-RC1' => array(), + + // Changes from 3.0.4 to 3.0.5-RC1 + '3.0.4' => array( + 'change_columns' => array( + FORUMS_TABLE => array( + 'forum_style' => array('UINT', 0), + ), + ), + ), + + // No changes from 3.0.5-RC1 to 3.0.5 + '3.0.5-RC1' => array(), + + // Changes from 3.0.5 to 3.0.6-RC1 + '3.0.5' => array( + 'add_columns' => array( + CONFIRM_TABLE => array( + 'attempts' => array('UINT', 0), + ), + USERS_TABLE => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time'=> array('TIMESTAMP', 0), + ), + GROUPS_TABLE => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + PRIVMSGS_TABLE => array( + 'message_reported' => array('BOOL', 0), + ), + REPORTS_TABLE => array( + 'pm_id' => array('UINT', 0), + ), + PROFILE_FIELDS_TABLE => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + FORUMS_TABLE => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + USERS_TABLE => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + REPORTS_TABLE => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + POSTS_TABLE => array( + 'post_username' => array('post_username:255'), + ), + ), + ), + + // No changes from 3.0.6-RC1 to 3.0.6-RC2 + '3.0.6-RC1' => array(), + // No changes from 3.0.6-RC2 to 3.0.6-RC3 + '3.0.6-RC2' => array(), + // No changes from 3.0.6-RC3 to 3.0.6-RC4 + '3.0.6-RC3' => array(), + // No changes from 3.0.6-RC4 to 3.0.6 + '3.0.6-RC4' => array(), + + // Changes from 3.0.6 to 3.0.7-RC1 + '3.0.6' => array( + 'drop_keys' => array( + LOG_TABLE => array('log_time'), + ), + 'add_index' => array( + TOPICS_TRACK_TABLE => array( + 'topic_id' => array('topic_id'), + ), + ), + ), + + // No changes from 3.0.7-RC1 to 3.0.7-RC2 + '3.0.7-RC1' => array(), + // No changes from 3.0.7-RC2 to 3.0.7 + '3.0.7-RC2' => array(), + // No changes from 3.0.7 to 3.0.7-PL1 + '3.0.7' => array(), + // No changes from 3.0.7-PL1 to 3.0.8-RC1 + '3.0.7-PL1' => array(), + // No changes from 3.0.8-RC1 to 3.0.8 + '3.0.8-RC1' => array(), + // Changes from 3.0.8 to 3.0.9-RC1 + '3.0.8' => array( + 'add_tables' => array( + LOGIN_ATTEMPT_TABLE => 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( + BBCODES_TABLE => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ), + // No changes from 3.0.9-RC1 to 3.0.9-RC2 + '3.0.9-RC1' => array(), + // No changes from 3.0.9-RC2 to 3.0.9-RC3 + '3.0.9-RC2' => array(), + // No changes from 3.0.9-RC3 to 3.0.9-RC4 + '3.0.9-RC3' => array(), + // No changes from 3.0.9-RC4 to 3.0.9 + '3.0.9-RC4' => array(), + // No changes from 3.0.9 to 3.0.10-RC1 + '3.0.9' => array(), + // No changes from 3.0.10-RC1 to 3.0.10-RC2 + '3.0.10-RC1' => array(), + // No changes from 3.0.10-RC2 to 3.0.10-RC3 + '3.0.10-RC2' => array(), + // No changes from 3.0.10-RC3 to 3.0.10 + '3.0.10-RC3' => array(), + // No changes from 3.0.10 to 3.0.11-RC1 + '3.0.10' => array(), + // Changes from 3.0.11-RC1 to 3.0.11-RC2 + '3.0.11-RC1' => array( + 'add_columns' => array( + PROFILE_FIELDS_TABLE => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ), + // No changes from 3.0.11-RC2 to 3.0.11 + '3.0.11-RC2' => array(), + // No changes from 3.0.11 to 3.0.12-RC1 + '3.0.11' => array(), + + /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 */ + // Changes from 3.1.0-dev to 3.1.0-A1 '3.1.0-dev' => array( 'add_tables' => array( @@ -939,6 +1210,1159 @@ function change_database_data(&$no_updates, $version) switch ($version) { + case '3.0.0': + + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + _sql($sql, $errored, $error_ary); + + // 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($phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $db->sql_escape($smiley) . "'"; + + _sql($sql, $errored, $error_ary); + } + } + + $no_updates = false; + break; + + // No changes from 3.0.1-RC1 to 3.0.1 + case '3.0.1-RC1': + break; + + // changes from 3.0.1 to 3.0.2-RC1 + case '3.0.1': + + set_config('referer_validation', '1'); + set_config('check_attachment_content', '1'); + set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title'); + + $no_updates = false; + break; + + // No changes from 3.0.2-RC1 to 3.0.2-RC2 + case '3.0.2-RC1': + break; + + // No changes from 3.0.2-RC2 to 3.0.2 + case '3.0.2-RC2': + break; + + // Changes from 3.0.2 to 3.0.3-RC1 + case '3.0.2': + set_config('enable_queue_trigger', '0'); + set_config('queue_trigger_posts', '3'); + + set_config('pm_max_recipients', '0'); + + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + _sql($sql, $errored, $error_ary); + + // 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); + + $no_updates = false; + break; + + // Changes from 3.0.3-RC1 to 3.0.3 + case '3.0.3-RC1': + if ($db->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); + } + + $no_updates = false; + break; + + // Changes from 3.0.3 to 3.0.4-RC1 + case '3.0.3': + // 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); + } + $no_updates = false; + + break; + + // Changes from 3.0.4-RC1 to 3.0.4 + case '3.0.4-RC1': + break; + + // Changes from 3.0.4 to 3.0.5-RC1 + case '3.0.4': + + // 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); + } + + $no_updates = false; + + break; + + // No changes from 3.0.5-RC1 to 3.0.5 + case '3.0.5-RC1': + break; + + // Changes from 3.0.5 to 3.0.6-RC1 + case '3.0.5': + // 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']); + } + + $no_updates = false; + break; + + // No changes from 3.0.6-RC1 to 3.0.6-RC2 + case '3.0.6-RC1': + break; + + // Changes from 3.0.6-RC2 to 3.0.6-RC3 + case '3.0.6-RC2': + + // 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); + $no_updates = false; + + break; + + // No changes from 3.0.6-RC3 to 3.0.6-RC4 + case '3.0.6-RC3': + break; + + // No changes from 3.0.6-RC4 to 3.0.6 + case '3.0.6-RC4': + break; + + // Changes from 3.0.6 to 3.0.7-RC1 + case '3.0.6': + + // 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); + + $no_updates = false; + break; + + // Changes from 3.0.7-RC1 to 3.0.7-RC2 + case '3.0.7-RC1': + + $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); + + $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); + + $no_updates = false; + + break; + + // No changes from 3.0.7-RC2 to 3.0.7 + case '3.0.7-RC2': + break; + + // No changes from 3.0.7 to 3.0.7-PL1 + case '3.0.7': + break; + + // Changes from 3.0.7-PL1 to 3.0.8-RC1 + case '3.0.7-PL1': + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $db->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' => 'UTC', + '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'); + } + + $no_updates = false; + break; + + // No changes from 3.0.8-RC1 to 3.0.8 + case '3.0.8-RC1': + break; + + // Changes from 3.0.8 to 3.0.9-RC1 + case '3.0.8': + 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); + } + } + } + + $no_updates = false; + break; + + // No changes from 3.0.9-RC1 to 3.0.9-RC2 + case '3.0.9-RC1': + break; + + // No changes from 3.0.9-RC2 to 3.0.9-RC3 + case '3.0.9-RC2': + break; + + // No changes from 3.0.9-RC3 to 3.0.9-RC4 + case '3.0.9-RC3': + break; + + // No changes from 3.0.9-RC4 to 3.0.9 + case '3.0.9-RC4': + break; + + // Changes from 3.0.9 to 3.0.10-RC1 + case '3.0.9': + if (!isset($config['email_max_chunk_size'])) + { + set_config('email_max_chunk_size', '50'); + } + + $no_updates = false; + break; + + // No changes from 3.0.10-RC1 to 3.0.10-RC2 + case '3.0.10-RC1': + break; + + // No changes from 3.0.10-RC2 to 3.0.10-RC3 + case '3.0.10-RC2': + break; + + // No changes from 3.0.10-RC3 to 3.0.10 + case '3.0.10-RC3': + break; + + // Changes from 3.0.10 to 3.0.11-RC1 + case '3.0.10': + // Updates users having current style a deactivated one + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_active = 0'; + $result = $db->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); + + $no_updates = false; + break; + + // No changes from 3.0.11-RC1 to 3.0.11-RC2 + case '3.0.11-RC1': + break; + + // No changes from 3.0.11-RC2 to 3.0.11 + case '3.0.11-RC2': + break; + + // Changes from 3.0.11 to 3.0.12-RC1 + case '3.0.11': + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_u_sig\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'signature\''; + _sql($sql, $errored, $error_ary); + + // Update bots + if (!function_exists('user_delete')) + { + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + + $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 = '" . $db->sql_escape(utf8_clean_string($bot_name)) . "'"; + $result = $db->sql_query($sql); + $bot_user_id = (int) $db->sql_fetchfield('user_id'); + $db->sql_freeresult($result); + + if ($bot_user_id) + { + if ($bot_agent === false) + { + $sql = 'DELETE FROM ' . BOTS_TABLE . " + WHERE user_id = $bot_user_id"; + _sql($sql, $errored, $error_ary); + + user_delete('remove', $bot_user_id); + } + else + { + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = '" . $db->sql_escape($bot_agent) . "' + WHERE user_id = $bot_user_id"; + _sql($sql, $errored, $error_ary); + } + } + } + + $no_updates = false; + break; + // Changes from 3.1.0-dev to 3.1.0-A1 case '3.1.0-dev':