Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/11103

# By Nathan Guse (28) and others
# Via Andreas Fischer (9) and others
* 'develop' of https://github.com/phpbb/phpbb3: (90 commits)
  [ticket/11350] Do not pass $db by reference; typehint phpbb_db_driver
  [feature/migrations] Remove default values from necessary parameters
  [ticket/11201] Revert WLM dropping because it is still used in China.
  [ticket/11220] Improvement to the info pop-up from "list="
  [feature/migrations] Revert unrelated changes to functions.php
  [ticket/11233] prohibit selecting anonymous user as a PM recipient
  [ticket/11343] Remove spare parentheses.
  [ticket/11343] Remove spare space.
  [ticket/11343] Use === when checking stored user_actkey against user input.
  [ticket/11295] Correct cases: replace postgres with phpbb_db_driver_postgres.
  [ticket/10050] removing prosilver edits
  [ticket/9737] Fix some comments
  [ticket/11337] Abort setup-webserver.sh script when an error occurs.
  [ticket/11337] Only run functional tests on 5.3.19 or higher. No FPM otherwise.
  [ticket/11337] Silence nginx config file writing.
  [ticket/11337] php-fpm.conf is no longer owned by root.
  [ticket/11337] Run functional tests on travis using nginx and php-fpm.
  [ticket/11338] Travis CI: Install PHP extension for redis key-value store.
  [ticket/10050] adding .topicrow to template condition
  [ticket/9737] Fix a few minor things in migrations
  ...

Conflicts:
	phpBB/config/services.yml
	phpBB/config/tables.yml
This commit is contained in:
Nathaniel Guse 2013-02-11 21:37:15 -06:00
commit 54e9f7b50a
63 changed files with 4153 additions and 129 deletions

View file

@ -17,12 +17,14 @@ before_script:
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS phpbb_tests;' -U postgres; fi"
- sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database phpbb_tests;' -U postgres; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS phpbb_tests;'; fi"
- travis/install-php-extensions.sh
- pyrus set auto_discover 1
- pyrus install --force phpunit/DbUnit
- phpenv rehash
- cd phpBB
- php ../composer.phar install --dev
- cd ../
- cd ..
- sh -c "if [ `php -r "echo (int) version_compare(PHP_VERSION, '5.3.19', '>=');"` = "1" ]; then travis/setup-webserver.sh; fi"
script:
- phpunit --configuration travis/phpunit-$DB-travis.xml

49
phpBB/config/migrator.yml Normal file
View file

@ -0,0 +1,49 @@
services:
migrator:
class: phpbb_db_migrator
arguments:
- @config
- @dbal.conn
- @dbal.tools
- %tables.migrations%
- %core.root_path%
- %core.php_ext%
- %core.table_prefix%
- @migrator.tool_collection
migrator.tool_collection:
class: phpbb_di_service_collection
arguments:
- @service_container
tags:
- { name: service_collection, tag: migrator.tool }
migrator.tool.config:
class: phpbb_db_migration_tool_config
arguments:
- @config
tags:
- { name: migrator.tool }
migrator.tool.module:
class: phpbb_db_migration_tool_module
arguments:
- @dbal.conn
- @cache
- @user
- %core.root_path%
- %core.php_ext%
- %tables.modules%
tags:
- { name: migrator.tool }
migrator.tool.permission:
class: phpbb_db_migration_tool_permission
arguments:
- @dbal.conn
- @cache
- @auth
- %core.root_path%
- %core.php_ext%
tags:
- { name: migrator.tool }

View file

@ -2,6 +2,7 @@ imports:
- { resource: tables.yml }
- { resource: cron_tasks.yml }
- { resource: notifications.yml }
- { resource: migrator.yml }
services:
auth:
@ -95,6 +96,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:

View file

@ -5,3 +5,5 @@ parameters:
tables.notifications: %core.table_prefix%notifications
tables.user_notifications: %core.table_prefix%user_notifications
tables.users: %core.table_prefix%users
tables.migrations: %core.table_prefix%migrations
tables.modules: %core.table_prefix%modules

View file

@ -1273,6 +1273,19 @@ function get_schema_struct()
),
);
$schema_data['phpbb_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',
);
$schema_data['phpbb_modules'] = array(
'COLUMNS' => array(
'module_id' => array('UINT', NULL, 'auto_increment'),

View file

@ -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];

View file

@ -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('NOTIFICATION_TYPES_TABLE', $table_prefix . 'notification_types');

View file

@ -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;
@ -345,6 +345,17 @@ 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)
{
$this->return_statements = $return_statements;
}
/**
* Gets a list of tables in the database.
*
@ -674,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
@ -1817,6 +1830,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;

View file

@ -0,0 +1,55 @@
<?php
/**
*
* @package db
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* The migrator is responsible for applying new migrations in the correct order.
*
* @package db
*/
class phpbb_db_migration_exception extends \Exception
{
/**
* Extra parameters sent to exception to aid in debugging
* @var array
*/
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();
$message = array_shift($parameters);
parent::__construct($message);
$this->parameters = $parameters;
}
/**
* Output the error as a string
*
* @return string
*/
public function __toString()
{
return $this->message . ': ' . var_export($this->parameters, true);
}
}

View file

@ -0,0 +1,190 @@
<?php
/**
*
* @package db
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Abstract base class for database migrations
*
* Each migration consists of a set of schema and data changes to be implemented
* in a subclass. This class provides various utility methods to simplify editing
* a phpBB.
*
* @package db
*/
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;
/** @var array List of queries executed through $this->sql_query() */
protected $queries = array();
/**
* 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(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;
$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 migrations to be applied first
*
* @return array An array of migration class names
*/
static public function depends_on()
{
return array();
}
/**
* 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.
* 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
*
* @return array Array of schema changes (compatible with db_tools->perform_schema_changes())
*/
public function update_schema()
{
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
*
* @return array Array of data update instructions
*/
public function update_data()
{
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
*
* @param string $sql SQL query to run on the database
* @return mixed Query result from db->sql_query()
*/
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;
}
}

View file

@ -0,0 +1,150 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/**
* Migration config tool
*
* @package db
*/
class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interface
{
/** @var phpbb_config */
protected $config;
/**
* Constructor
*
* @param phpbb_config $config
*/
public function __construct(phpbb_config $config)
{
$this->config = $config;
}
/**
* {@inheritdoc}
*/
public function get_name()
{
return 'config';
}
/**
* 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)
{
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);
}
/**
* 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)
{
if (!isset($this->config[$config_name]))
{
throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name);
}
$this->config->set($config_name, $config_value);
}
/**
* Update a config setting if the first argument equal to the
* current config value
*
* @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)
{
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);
}
/**
* 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)
{
if (!isset($this->config[$config_name]))
{
throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name);
}
$this->config->delete($config_name);
}
/**
* {@inheritdoc}
*/
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);
}
}
}

View file

@ -0,0 +1,33 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/**
* Migration tool interface
*
* @package db
*/
interface phpbb_db_migration_tool_interface
{
/**
* Retrieve a short name used for commands in migrations.
*
* @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();
}

View file

@ -0,0 +1,513 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/**
* Migration module management tool
*
* @package db
*/
class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interface
{
/** @var phpbb_cache_service */
protected $cache;
/** @var dbal */
protected $db;
/** @var phpbb_user */
protected $user;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $php_ext;
/** @var string */
protected $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;
$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;
}
$parent_sql = '';
if ($parent !== false)
{
// Allows '' to be sent as 0
$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 = '" . $this->db->sql_escape($class) . "'";
$result = $this->db->sql_query($sql);
$module_id = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);
if (!$module_id)
{
return false;
}
$parent_sql = 'AND parent_id = ' . (int) $module_id;
}
else
{
$parent_sql = 'AND parent_id = ' . (int) $parent;
}
}
$sql = 'SELECT module_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'
$parent_sql
AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '" . $this->db->sql_escape($module) . "'");
$result = $this->db->sql_query($sql);
$module_id = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);
if ($module_id)
{
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
* @return null
*/
public function add($class, $parent = 0, $data = array(), $include_path = false)
{
// 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))
{
$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);
$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 . $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 . $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.
$this->add($class, $parent, $new_module);
}
}
return;
}
// The "manual" way
$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 = '" . $this->db->sql_escape($class) . "'";
$result = $this->db->sql_query($sql);
$module_id = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);
if (!$module_id)
{
throw new phpbb_db_migration_exception('MODULE_PARENT_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);
}
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 = '" . $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 = (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 = '" . $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 = '" . $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 = '" . $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 = (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 = '" . $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 = '" . $this->db->sql_escape($class) . "'
AND module_id = {$module_data['module_id']}";
$this->db->sql_query($sql);
}
}
// Clear the Modules Cache
$this->cache->destroy("_modules_$class");
}
/**
* 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
* @return null
*/
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);
$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 . $info_file))
{
throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file);
}
$classname = "{$basename}_info";
if (!class_exists($classname))
{
include($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']) . '<br />';
}
}
}
else
{
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;
if (!is_numeric($parent))
{
$sql = 'SELECT module_id
FROM ' . $this->modules_table . "
WHERE module_langname = '" . $this->db->sql_escape($parent) . "'
AND module_class = '" . $this->db->sql_escape($class) . "'";
$result = $this->db->sql_query($sql);
$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) $module_id;
}
else
{
$parent_sql = 'AND parent_id = ' . (int) $parent;
}
}
$module_ids = array();
if (!is_numeric($module))
{
$sql = 'SELECT module_id
FROM ' . $this->modules_table . "
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 ($module_id = $this->db->sql_fetchfield('module_id'))
{
$module_ids[] = (int) $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 = '" . $this->db->sql_escape($class) . "'
$parent_sql";
$result = $this->db->sql_query($sql);
$module_name = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);
$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");
}
}
/**
* {@inheritdoc}
*/
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);
}
}
}

View file

@ -0,0 +1,622 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
/**
* Migration permission management tool
*
* @package db
*/
class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_interface
{
/** @var phpbb_auth */
protected $auth;
/** @var phpbb_cache_service */
protected $cache;
/** @var dbal */
protected $db;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $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;
$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 null
*/
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 (!empty($sql_ary))
{
$this->db->sql_multi_insert($table, $sql_ary);
}
}
$auth_admin->acl_clear_prefetch();
}
}
/**
* 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 null
*/
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 = (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'])
{
$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
$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();
}
/**
* Add a new permission role
*
* @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 = '')
{
$sql = 'SELECT role_id
FROM ' . ACL_ROLES_TABLE . "
WHERE role_name = '" . $this->db->sql_escape($role_name) . "'";
$this->db->sql_query($sql);
$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_role_order
FROM ' . ACL_ROLES_TABLE . "
WHERE role_type = '" . $this->db->sql_escape($role_type) . "'";
$this->db->sql_query($sql);
$role_order = (int) $this->db->sql_fetchfield('max_role_order');
$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);
}
/**
* 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
* @return null
*/
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 = (int) $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);
}
/**
* Remove a permission role
*
* @param string $role_name The role name to remove
* @return null
*/
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 = (int) $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();
}
/**
* 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
* @return null
*/
public function permission_set($name, $auth_option, $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[] = (int) $row['auth_option_id'];
}
$this->db->sql_freeresult($result);
if (empty($new_auth))
{
return;
}
$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 = (int) $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 = (int) $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 = (int) $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();
}
/**
* 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)
* @return null
*/
public function permission_unset($name, $auth_option, $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[] = (int) $row['auth_option_id'];
}
$this->db->sql_freeresult($result);
if (empty($to_remove))
{
return;
}
$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 = (int) $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 = (int) $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 = (int) $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();
}
/**
* {@inheritdoc}
*/
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);
}
}
}

View file

@ -0,0 +1,762 @@
<?php
/**
*
* @package db
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* The migrator is responsible for applying new migrations in the correct order.
*
* @package db
*/
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;
/**
* State of all migrations
*
* (SELECT * FROM migrations table)
*
* @var array
*/
protected $migration_state = array();
/**
* Array of all migrations available to be run
*
* @var array
*/
protected $migrations = array();
/**
* 'name' and 'class' of the last migration run
*
* @var array
*/
public $last_run_migration = false;
/**
* Constructor of the database migrator
*/
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;
$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();
}
/**
* Loads all migrations and their application state from the database.
*
* @return null
*/
public function load_migration_state()
{
$this->migration_state = array();
$sql = "SELECT *
FROM " . $this->migrations_table;
$result = $this->db->sql_query($sql);
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);
}
/**
* Sets the list of available migration class names to the given array.
*
* @param array $class_names An array of migration class names
* @return null
*/
public function set_migrations($class_names)
{
$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
*
* 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).
* @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, $recursive = true)
{
if (!is_dir($path))
{
throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path);
}
$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.
$declared_classes = get_declared_classes();
include ($path . $file);
$added_classes = array_diff(get_declared_classes(), $declared_classes);
if (
// 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
)
{
throw new phpbb_db_migration_exception('MIGRATION DATA FILE INVALID', $path . $file);
}
$name = array_pop($added_classes);
if (!in_array($name, $this->migrations))
{
$this->migrations[] = $name;
}
}
}
if ($check_fulfillable)
{
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()
{
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
*/
protected function try_apply($name)
{
if (!class_exists($name))
{
return false;
}
$migration = $this->get_migration($name);
$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,
);
foreach ($state['migration_depends_on'] 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);
}
}
$this->last_run_migration = array(
'name' => $name,
'class' => $migration,
);
if ($migration->effectively_installed())
{
$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'])
{
$this->apply_schema_changes($migration->update_schema());
$state['migration_schema_done'] = true;
}
else if (!$state['migration_data_done'])
{
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);
// 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', $insert) . "
WHERE migration_name = '" . $this->db->sql_escape($name) . "'";
$this->db->sql_query($sql);
$this->migration_state[$name] = $state;
return true;
}
/**
* 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_state() 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[$migration]))
{
// Not installed
return;
}
foreach ($this->migration_state as $name => $state)
{
if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on']))
{
$this->revert($name);
}
}
$this->try_revert($migration);
}
/**
* 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
*/
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,
);
if ($state['migration_data_done'])
{
if ($state['migration_data_state'] !== 'revert_data')
{
$result = $this->process_data_step($migration->update_data(), $state['migration_data_state'], 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;
}
$insert = $state;
$insert['migration_depends_on'] = serialize($state['migration_depends_on']);
$sql = 'UPDATE ' . $this->migrations_table . '
SET ' . $this->db->sql_build_array('UPDATE', $insert) . "
WHERE migration_name = '" . $this->db->sql_escape($name) . "'";
$this->db->sql_query($sql);
$this->migration_state[$name] = $state;
}
else
{
$this->apply_schema_changes($migration->revert_schema());
$sql = 'DELETE FROM ' . $this->migrations_table . "
WHERE migration_name = '" . $this->db->sql_escape($name) . "'";
$this->db->sql_query($sql);
unset($this->migration_state[$name]);
}
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 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($steps, $state, $revert = false)
{
$state = ($state) ? unserialize($state) : false;
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_identifier)
{
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, $last_result, $revert);
if ($result !== null && $result !== true)
{
return serialize(array(
'result' => $result,
'step' => $step_identifier,
));
}
}
catch (phpbb_db_migration_exception $e)
{
// We should try rolling back here
foreach ($steps as $reverse_step_identifier => $reverse_step)
{
// If we've reached the current step we can break because we reversed everything that was run
if ($reverse_step_identifier == $step_identifier)
{
break;
}
// Reverse the step that was run
$result = $this->run_step($reverse_step, false, !$revert);
}
// rethrow the exception
throw $e;
}
}
return true;
}
/**
* Run a single step
*
* An exception should be thrown if an error occurs
*
* @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, $reverse = false)
{
$callable_and_parameters = $this->get_callable_from_step($step, $last_result, $reverse);
if ($callable_and_parameters === false)
{
return;
}
$callable = $callable_and_parameters[0];
$parameters = $callable_and_parameters[1];
return call_user_func_array($callable, $parameters);
}
/**
* Get a callable statement from a data step
*
* @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(array $step, $last_result = false, $reverse = false)
{
$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];
if (!$condition)
{
return false;
}
$step = $parameters[1];
return $this->get_callable_from_step($step);
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($last_result),
);
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);
}
// Attempt to reverse operations
if ($reverse)
{
array_unshift($parameters, $method);
return array(
array($this->tools[$class], 'reverse'),
$parameters,
);
}
return array(
array($this->tools[$class], $method),
$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;
$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);
$this->db->sql_query($sql);
$this->migration_state[$name] = $state;
}
/**
* 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
*/
public function unfulfillable($name)
{
if (isset($this->migration_state[$name]))
{
return false;
}
if (!class_exists($name))
{
return true;
}
$migration = $this->get_migration($name);
$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
*/
public 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;
}
/**
* 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|array False if the migration has not at all been installed, array
*/
public function migration_state($migration)
{
if (!isset($this->migration_state[$migration]))
{
return false;
}
return $this->migration_state[$migration];
}
/**
* 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);
}
}

View file

@ -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);
}
@ -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,69 @@ 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
$avatar_options = array('user_avatar', 'user_avatar_type', 'user_avatar_height', 'user_avatar_width');
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);
while ($row = $db->sql_fetchrow($result))
$avatar_sql_ary = array();
foreach ($avatar_options as $avatar_option)
{
avatar_delete('user', $row);
}
$db->sql_freeresult($result);
}
else
{
unset($sql_ary['user_avatar_type']);
unset($sql_ary['user_avatar_height']);
unset($sql_ary['user_avatar_width']);
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', $avatar_sql_ary) . "
WHERE user_avatar = ''
AND " . $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);
// Remove the avatar options, as we already updated them
foreach ($avatar_options as $avatar_option)
{
unset($sql_ary[$avatar_option]);
}
if (!empty($sql_ary))
{
$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 +3585,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
*

View file

@ -50,7 +50,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');
}

View file

@ -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];

View file

@ -353,7 +353,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';
}

View file

@ -586,6 +586,20 @@ CREATE TABLE phpbb_moderator_cache (
CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache(display_on_index);;
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache(forum_id);;
# Table: 'phpbb_migrations'
CREATE TABLE phpbb_migrations (
migration_name VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
migration_depends_on BLOB SUB_TYPE TEXT CHARACTER SET NONE DEFAULT '' NOT NULL,
migration_schema_done INTEGER DEFAULT 0 NOT NULL,
migration_data_done INTEGER DEFAULT 0 NOT NULL,
migration_data_state BLOB SUB_TYPE TEXT CHARACTER SET NONE DEFAULT '' NOT NULL,
migration_start_time INTEGER DEFAULT 0 NOT NULL,
migration_end_time INTEGER DEFAULT 0 NOT NULL
);;
ALTER TABLE phpbb_migrations ADD PRIMARY KEY (migration_name);;
# Table: 'phpbb_modules'
CREATE TABLE phpbb_modules (
module_id INTEGER NOT NULL,

View file

@ -716,6 +716,28 @@ CREATE INDEX [forum_id] ON [phpbb_moderator_cache]([forum_id]) ON [PRIMARY]
GO
/*
Table: 'phpbb_migrations'
*/
CREATE TABLE [phpbb_migrations] (
[migration_name] [varchar] (255) DEFAULT ('') NOT NULL ,
[migration_depends_on] [varchar] (8000) DEFAULT ('') NOT NULL ,
[migration_schema_done] [int] DEFAULT (0) NOT NULL ,
[migration_data_done] [int] DEFAULT (0) NOT NULL ,
[migration_data_state] [varchar] (8000) DEFAULT ('') NOT NULL ,
[migration_start_time] [int] DEFAULT (0) NOT NULL ,
[migration_end_time] [int] DEFAULT (0) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [phpbb_migrations] WITH NOCHECK ADD
CONSTRAINT [PK_phpbb_migrations] PRIMARY KEY CLUSTERED
(
[migration_name]
) ON [PRIMARY]
GO
/*
Table: 'phpbb_modules'
*/

View file

@ -410,6 +410,19 @@ CREATE TABLE phpbb_moderator_cache (
);
# Table: 'phpbb_migrations'
CREATE TABLE phpbb_migrations (
migration_name varbinary(255) DEFAULT '' NOT NULL,
migration_depends_on blob NOT NULL,
migration_schema_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
migration_data_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
migration_data_state blob NOT NULL,
migration_start_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
migration_end_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (migration_name)
);
# Table: 'phpbb_modules'
CREATE TABLE phpbb_modules (
module_id mediumint(8) UNSIGNED NOT NULL auto_increment,

View file

@ -410,6 +410,19 @@ CREATE TABLE phpbb_moderator_cache (
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
# Table: 'phpbb_migrations'
CREATE TABLE phpbb_migrations (
migration_name varchar(255) DEFAULT '' NOT NULL,
migration_depends_on text NOT NULL,
migration_schema_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
migration_data_done tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
migration_data_state text NOT NULL,
migration_start_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
migration_end_time int(11) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (migration_name)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
# Table: 'phpbb_modules'
CREATE TABLE phpbb_modules (
module_id mediumint(8) UNSIGNED NOT NULL auto_increment,

View file

@ -798,6 +798,22 @@ CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache (display_on
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache (forum_id)
/
/*
Table: 'phpbb_migrations'
*/
CREATE TABLE phpbb_migrations (
migration_name varchar2(255) DEFAULT '' ,
migration_depends_on clob DEFAULT '' ,
migration_schema_done number(1) DEFAULT '0' NOT NULL,
migration_data_done number(1) DEFAULT '0' NOT NULL,
migration_data_state clob DEFAULT '' ,
migration_start_time number(11) DEFAULT '0' NOT NULL,
migration_end_time number(11) DEFAULT '0' NOT NULL,
CONSTRAINT pk_phpbb_migrations PRIMARY KEY (migration_name)
)
/
/*
Table: 'phpbb_modules'
*/

View file

@ -572,6 +572,21 @@ CREATE TABLE phpbb_moderator_cache (
CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache (display_on_index);
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache (forum_id);
/*
Table: 'phpbb_migrations'
*/
CREATE TABLE phpbb_migrations (
migration_name varchar(255) DEFAULT '' NOT NULL,
migration_depends_on varchar(8000) DEFAULT '' NOT NULL,
migration_schema_done INT2 DEFAULT '0' NOT NULL CHECK (migration_schema_done >= 0),
migration_data_done INT2 DEFAULT '0' NOT NULL CHECK (migration_data_done >= 0),
migration_data_state varchar(8000) DEFAULT '' NOT NULL,
migration_start_time INT4 DEFAULT '0' NOT NULL CHECK (migration_start_time >= 0),
migration_end_time INT4 DEFAULT '0' NOT NULL CHECK (migration_end_time >= 0),
PRIMARY KEY (migration_name)
);
/*
Table: 'phpbb_modules'
*/

View file

@ -398,6 +398,19 @@ CREATE TABLE phpbb_moderator_cache (
CREATE INDEX phpbb_moderator_cache_disp_idx ON phpbb_moderator_cache (display_on_index);
CREATE INDEX phpbb_moderator_cache_forum_id ON phpbb_moderator_cache (forum_id);
# Table: 'phpbb_migrations'
CREATE TABLE phpbb_migrations (
migration_name varchar(255) NOT NULL DEFAULT '',
migration_depends_on text(65535) NOT NULL DEFAULT '',
migration_schema_done INTEGER UNSIGNED NOT NULL DEFAULT '0',
migration_data_done INTEGER UNSIGNED NOT NULL DEFAULT '0',
migration_data_state text(65535) NOT NULL DEFAULT '',
migration_start_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
migration_end_time INTEGER UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (migration_name)
);
# Table: 'phpbb_modules'
CREATE TABLE phpbb_modules (
module_id INTEGER PRIMARY KEY NOT NULL ,

View file

@ -119,6 +119,17 @@ $lang = array_merge($lang, array(
1 => 'Users browsing this forum: %2$s and %1$d guest',
2 => 'Users browsing this forum: %2$s and %1$d guests',
),
'BUTTON_EDIT' => 'Edit',
'BUTTON_FORUM_LOCKED' => 'Locked',
'BUTTON_NEW_TOPIC' => 'New Topic',
'BUTTON_PM' => 'PM',
'BUTTON_PM_FORWARD' => 'Forward',
'BUTTON_PM_NEW' => 'New PM',
'BUTTON_PM_REPLY' => 'Send Reply',
'BUTTON_PM_REPLY_ALL' => 'Reply All',
'BUTTON_POST_REPLY' => 'Post Reply',
'BUTTON_QUOTE' => 'Quote',
'BUTTON_TOPIC_LOCKED' => 'Locked',
'BYTES' => 'Bytes',
'CANCEL' => 'Cancel',

View file

@ -53,9 +53,9 @@ $lang = array_merge($lang, array(
'BBCODE_IS_OFF' => '%sBBCode%s is <em>OFF</em>',
'BBCODE_IS_ON' => '%sBBCode%s is <em>ON</em>',
'BBCODE_I_HELP' => 'Italic text: [i]text[/i]',
'BBCODE_L_HELP' => 'List: [list]text[/list]',
'BBCODE_LISTITEM_HELP' => 'List item: [*]text[/*]',
'BBCODE_O_HELP' => 'Ordered list: [list=]text[/list]',
'BBCODE_L_HELP' => 'List: [list][*]text[/list]',
'BBCODE_LISTITEM_HELP' => 'List item: [*]text',
'BBCODE_O_HELP' => 'Ordered list: e.g. [list=1][*]First point[/list] or [list=a][*]Point a[/list]',
'BBCODE_P_HELP' => 'Insert image: [img]http://image_url[/img]',
'BBCODE_Q_HELP' => 'Quote text: [quote]text[/quote]',
'BBCODE_S_HELP' => 'Font colour: [color=red]text[/color] Tip: you can also use color=#FF0000',

View file

@ -1033,7 +1033,7 @@ switch ($mode)
// We validate form and field here, only id/class allowed
$form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
$field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
if (($mode == 'searchuser' || sizeof(array_intersect($request->variable_names(phpbb_request_interface::GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
if ((($mode == '' || $mode == 'searchuser') || sizeof(array_intersect($request->variable_names(phpbb_request_interface::GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
{
$username = request_var('username', '', true);
$email = strtolower(request_var('email', ''));
@ -1388,7 +1388,7 @@ switch ($mode)
}
// Some search user specific data
if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
if (($mode == '' || $mode == 'searchuser') && ($config['load_search'] || $auth->acl_get('a_')))
{
$group_selected = request_var('search_group_id', 0);
$s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
@ -1459,7 +1459,7 @@ switch ($mode)
'S_IP_SEARCH_ALLOWED' => ($auth->acl_getf_global('m_info')) ? true : false,
'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
'S_IN_SEARCH_POPUP' => ($form && $field) ? true : false,
'S_SEARCH_USER' => true,
'S_SEARCH_USER' => ($mode == 'searchuser' || ($mode == '' && $submit)),
'S_FORM_NAME' => $form,
'S_FIELD_NAME' => $field,
'S_SELECT_SINGLE' => $select_single,
@ -1611,7 +1611,7 @@ switch ($mode)
'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
'U_FIND_MEMBER' => ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser' . (($start) ? "&amp;start=$start" : '') . (!empty($params) ? '&amp;' . implode('&amp;', $params) : '')) : '',
'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser') ? $u_hide_find_member : '',
'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser' || ($mode == '' && $submit)) ? $u_hide_find_member : '',
'U_SORT_USERNAME' => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
'U_SORT_FROM' => $sort_url . '&amp;sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
'U_SORT_JOINED' => $sort_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),

View file

@ -190,6 +190,21 @@ $('#quick-mod-select').change(function () {
$('#quickmodform').submit();
});
/**
* Toggle the member search panel in memberlist.php.
*
* If user returns to search page after viewing results the search panel is automatically displayed.
* In any case the link will toggle the display status of the search panel and link text will be
* appropriately changed based on the status of the search panel.
*/
$('#member_search').click(function () {
$('#memberlist_search').slideToggle('fast');
phpbb.ajax_callbacks['alt_text'].call(this);
// Focus on the username textbox if it's available and displayed
if ($('#memberlist_search').is(':visible')) {
$('#username').focus();
}
return false;
});
})(jQuery); // Avoid conflicts with other libraries

View file

@ -3,13 +3,11 @@
<!-- INCLUDE memberlist_search.html -->
<form method="post" id="results" action="{S_MODE_ACTION}" onsubmit="insert_marked(this.user); return false">
<!-- ELSEIF S_SEARCH_USER -->
<!-- INCLUDE overall_header.html -->
<!-- INCLUDE memberlist_search.html -->
<form method="post" action="{S_MODE_ACTION}">
<!-- ELSE -->
<!-- INCLUDE overall_header.html -->
<div class="panel" id="memberlist_search"<!-- IF not S_SEARCH_USER --> style="display: none;"<!-- ENDIF -->>
<!-- INCLUDE memberlist_search.html -->
</div>
<form method="post" action="{S_MODE_ACTION}">
<!-- ENDIF -->
@ -32,8 +30,7 @@
<ul class="linklist">
<li>
<!-- IF U_FIND_MEMBER and not S_SEARCH_USER --><a href="{U_FIND_MEMBER}">{L_FIND_USERNAME}</a> &bull; <!-- ELSEIF S_SEARCH_USER and U_HIDE_FIND_MEMBER and not S_IN_SEARCH_POPUP --><a href="{U_HIDE_FIND_MEMBER}">{L_HIDE_MEMBER_SEARCH}</a> &bull; <!-- ENDIF -->
<!-- IF U_FIND_MEMBER and not S_SEARCH_USER --><a href="{U_FIND_MEMBER}" id="member_search" data-alt-text="{LA_HIDE_MEMBER_SEARCH}">{L_FIND_USERNAME}</a> &bull; <!-- ELSEIF S_SEARCH_USER and U_HIDE_FIND_MEMBER and not S_IN_SEARCH_POPUP --><a href="{U_HIDE_FIND_MEMBER}" id="member_search" data-alt-text="{LA_FIND_USERNAME}">{L_HIDE_MEMBER_SEARCH}</a> &bull; <!-- ENDIF -->
<strong style="font-size: 0.95em;">
<!-- BEGIN first_char -->
<a href="{first_char.U_SORT}">{first_char.DESC}</a>&nbsp;

View file

@ -37,9 +37,8 @@ function insert_single(user)
}
// ]]>
</script>
<script type="text/javascript" src="{T_SUPER_TEMPLATE_PATH}/forum_fn.js"></script>
<!-- ENDIF -->
<!-- INCLUDEJS template/forum_fn.js -->
<h2 class="solo">{L_FIND_USERNAME}</h2>
<form method="post" action="{S_MODE_ACTION}" id="search_memberlist">

View file

@ -8,10 +8,10 @@
<!-- IF FOLDER_STATUS and FOLDER_MAX_MESSAGES neq 0 --><p>{FOLDER_STATUS}</p><!-- ENDIF -->
<!-- IF U_POST_REPLY_PM or U_POST_NEW_TOPIC or U_FORWARD_PM -->
<div class="buttons">
<!-- IF U_POST_REPLY_PM --><div class="pmreply-icon"><a title="{L_POST_REPLY_PM}" href="{U_POST_REPLY_PM}"><span></span>{L_POST_REPLY_PM}</a></div>
<!-- ELSEIF U_POST_NEW_TOPIC --><div class="newpm-icon"><a href="{U_POST_NEW_TOPIC}" accesskey="n" title="{L_UCP_PM_COMPOSE}"><span></span>{L_UCP_PM_COMPOSE}</a></div><!-- ENDIF -->
<!-- IF U_FORWARD_PM --><div class="forwardpm-icon"><a title="{L_POST_FORWARD_PM}" href="{U_FORWARD_PM}"><span></span>{L_FORWARD_PM}</a></div><!-- ENDIF -->
<!-- IF U_POST_REPLY_PM and S_PM_RECIPIENTS gt 1 --><div class="reply-all"><a class="left" title="{L_REPLY_TO_ALL}" href="{U_POST_REPLY_ALL}">{L_REPLY_TO_ALL}</a></div><!-- ENDIF -->
<!-- IF U_POST_REPLY_PM --><div class="pmreply-icon"><a title="{L_POST_REPLY_PM}" href="{U_POST_REPLY_PM}"><span></span>{L_BUTTON_PM_REPLY}</a></div>
<!-- ELSEIF U_POST_NEW_TOPIC --><div class="newpm-icon"><a href="{U_POST_NEW_TOPIC}" accesskey="n" title="{L_UCP_PM_COMPOSE}"><span></span>{L_BUTTON_PM_NEW}</a></div><!-- ENDIF -->
<!-- IF U_FORWARD_PM --><div class="forwardpm-icon"><a title="{L_POST_FORWARD_PM}" href="{U_FORWARD_PM}"><span></span>{L_BUTTON_PM_FORWARD}</a></div><!-- ENDIF -->
<!-- IF U_POST_REPLY_PM and S_PM_RECIPIENTS gt 1 --><div class="reply-all"><a title="{L_REPLY_TO_ALL}" href="{U_POST_REPLY_ALL}">{L_BUTTON_PM_REPLY_ALL}</a></div><!-- ENDIF -->
</div>
<!-- ENDIF -->

View file

@ -39,7 +39,7 @@
<!-- IF not S_IS_BOT and S_DISPLAY_POST_INFO -->
<div class="buttons">
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->post-icon<!-- ENDIF -->" title="<!-- IF S_IS_LOCKED -->{L_FORUM_LOCKED}<!-- ELSE -->{L_POST_TOPIC}<!-- ENDIF -->"><a href="{U_POST_NEW_TOPIC}"><span></span><!-- IF S_IS_LOCKED -->{L_FORUM_LOCKED}<!-- ELSE -->{L_POST_TOPIC}<!-- ENDIF --></a></div>
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->post-icon<!-- ENDIF -->" title="<!-- IF S_IS_LOCKED -->{L_FORUM_LOCKED}<!-- ELSE -->{L_POST_TOPIC}<!-- ENDIF -->"><a href="{U_POST_NEW_TOPIC}"><span></span><!-- IF S_IS_LOCKED -->{L_BUTTON_FORUM_LOCKED}<!-- ELSE -->{L_BUTTON_NEW_TOPIC}<!-- ENDIF --></a></div>
</div>
<!-- ENDIF -->
@ -205,7 +205,7 @@
<div class="topic-actions">
<!-- IF not S_IS_BOT and S_DISPLAY_POST_INFO -->
<div class="buttons">
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->post-icon<!-- ENDIF -->" title="<!-- IF S_IS_LOCKED -->{L_FORUM_LOCKED}<!-- ELSE -->{L_POST_TOPIC}<!-- ENDIF -->"><a href="{U_POST_NEW_TOPIC}"><span></span><!-- IF S_IS_LOCKED -->{L_FORUM_LOCKED}<!-- ELSE -->{L_POST_TOPIC}<!-- ENDIF --></a></div>
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->post-icon<!-- ENDIF -->" title="<!-- IF S_IS_LOCKED -->{L_FORUM_LOCKED}<!-- ELSE -->{L_POST_TOPIC}<!-- ENDIF -->"><a href="{U_POST_NEW_TOPIC}"><span></span><!-- IF S_IS_LOCKED -->{L_BUTTON_FORUM_LOCKED}<!-- ELSE -->{L_BUTTON_NEW_TOPIC}<!-- ENDIF --></a></div>
</div>
<!-- ENDIF -->

View file

@ -29,7 +29,7 @@
<div class="buttons">
<!-- IF not S_IS_BOT and S_DISPLAY_REPLY_INFO -->
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->reply-icon<!-- ENDIF -->"><a href="{U_POST_REPLY_TOPIC}" title="<!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF -->"><span></span><!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED_SHORT}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF --></a></div>
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->reply-icon<!-- ENDIF -->"><a href="{U_POST_REPLY_TOPIC}" title="<!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF -->"><span></span><!-- IF S_IS_LOCKED -->{L_BUTTON_TOPIC_LOCKED}<!-- ELSE -->{L_BUTTON_POST_REPLY}<!-- ENDIF --></a></div>
<!-- ENDIF -->
</div>
@ -264,7 +264,7 @@
<div class="topic-actions">
<div class="buttons">
<!-- IF not S_IS_BOT and S_DISPLAY_REPLY_INFO -->
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->reply-icon<!-- ENDIF -->"><a href="{U_POST_REPLY_TOPIC}" title="<!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF -->"><span></span><!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED_SHORT}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF --></a></div>
<div class="<!-- IF S_IS_LOCKED -->locked-icon<!-- ELSE -->reply-icon<!-- ENDIF -->"><a href="{U_POST_REPLY_TOPIC}" title="<!-- IF S_IS_LOCKED -->{L_TOPIC_LOCKED}<!-- ELSE -->{L_POST_REPLY}<!-- ENDIF -->"><span></span><!-- IF S_IS_LOCKED -->{L_BUTTON_TOPIC_LOCKED}<!-- ELSE -->{L_BUTTON_POST_REPLY}<!-- ENDIF --></a></div>
<!-- ENDIF -->
</div>

View file

@ -14,40 +14,57 @@
.buttons div {
float: left;
margin: 0 5px 0 0;
background-position: 0 100%;
}
/* Rolloff state */
.buttons div a {
display: block;
width: 100%;
height: 100%;
background-position: 0 0;
display: inline-block;
line-height: 17.5px;
height: 18px;
font-size: 13px;
white-space: nowrap;
border: 1px solid transparent;
border-radius: 4px;
background: transparent none 0 0 repeat-x;
padding: 2px 22px 2px 8px;
font-family: Verdana, Arial, Helvetica;
position: relative;
overflow: hidden;
text-decoration: none !important;
outline-style: none !important;
vertical-align: bottom;
*padding-right: 8px;
}
/* Hide <a> text and hide off-state image when rolling over (prevents flicker in IE) */
/*.buttons div span { display: none; }*/
/*.buttons div a:hover { background-image: none; }*/
.buttons div span { position: absolute; width: 100%; height: 100%; cursor: pointer;}
.buttons div a:hover span { background-position: 0 100%; }
.buttons div span { display: none; }
.buttons div a:after {
content: '';
display: block;
position: absolute;
top: 50%;
right: 6px;
width: 12px;
height: 12px;
margin-top: -6px;
background: transparent 0 0 no-repeat;
}
.buttons div a:hover:after {
background-position: 0 -20px;
}
/* Big button images */
.reply-icon span { background: transparent none 0 0 no-repeat; }
.post-icon span { background: transparent none 0 0 no-repeat; }
.locked-icon span { background: transparent none 0 0 no-repeat; }
.pmreply-icon span { background: none 0 0 no-repeat; }
.newpm-icon span { background: none 0 0 no-repeat; }
.forwardpm-icon span { background: none 0 0 no-repeat; }
.buttons div.reply-icon a:after, .buttons div.pmreply-icon a:after { background-position: -20px 0; }
.buttons div.reply-icon a:hover:after, .buttons div.pmreply-icon a:hover:after { background-position: -20px -20px; }
/* Set big button dimensions */
.buttons div.reply-icon { width: 96px; height: 25px; }
.buttons div.post-icon { width: 96px; height: 25px; }
.buttons div.locked-icon { width: 88px; height: 25px; }
.buttons div.pmreply-icon { width: 96px; height: 25px; }
.buttons div.newpm-icon { width: 84px; height: 25px; }
.buttons div.forwardpm-icon { width: 96px; height: 25px; }
.buttons div.post-icon a:after, .buttons div.newpm-icon a:after { background-position: 0 0; }
.buttons div.post-icon a:hover:after, .buttons div.newpm-icon a:hover:after { background-position: 0 -20px; }
.buttons div.locked-icon a:after { background-position: -60px 0; }
.buttons div.locked-icon a:hover:after { background-position: -60px -20px; }
.buttons div.forwardpm-icon a:after { background-position: -40px 0; }
.buttons div.forwardpm-icon a:hover:after { background-position: -40px -20px; }
/* Sub-header (navigation bar)
--------------------------------------------- */

View file

@ -649,14 +649,6 @@ fieldset.polls dd div {
Colours and backgrounds for buttons.css
-------------------------------------------------------------- */
/* Big button images */
.reply-icon span { background-image: url("./en/button_topic_reply.gif"); }
.post-icon span { background-image: url("./en/button_topic_new.gif"); }
.locked-icon span { background-image: url("./en/button_topic_locked.gif"); }
.pmreply-icon span { background-image: url("./en/button_pm_reply.gif") ;}
.newpm-icon span { background-image: url("./en/button_pm_new.gif") ;}
.forwardpm-icon span { background-image: url("./en/button_pm_forward.gif") ;}
a.print {
background-image: url("./images/icon_print.gif");
}
@ -665,6 +657,33 @@ a.sendemail {
background-image: url("./images/icon_sendemail.gif");
}
.buttons div a {
border-color: #C7C3BF;
background-color: #FFFFFF;
background-image: -moz-linear-gradient(top, #FFFFFF, #E9E9E9);
background-image: -webkit-linear-gradient(top, #FFFFFF, #E9E9E9);
background-image: -o-linear-gradient(top, #FFFFFF, #E9E9E9);
background-image: linear-gradient(to bottom, #FFFFFF, #E9E9E9);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#FFFFFF', EndColorStr='#E9E9E9')";
box-shadow: 0 0 0 1px #FFFFFF inset;
-webkit-box-shadow: 0 0 0 1px #FFFFFF inset;
color: #BC2A4D !important;
}
.buttons div a:hover {
border-color: #0a8ed0;
background-image: -moz-linear-gradient(top, #E9E9E9, #FFFFFF);
background-image: -webkit-linear-gradient(top, #E9E9E9, #FFFFFF);
background-image: -o-linear-gradient(top, #E9E9E9, #FFFFFF);
background-image: linear-gradient(to bottom, #E9E9E9, #FFFFFF);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#E9E9E9', EndColorStr='#FFFFFF')";
text-shadow: 1px 1px 0 #FFFFFF, -1px -1px 0 #FFFFFF, -1px -1px 0 rgba(188, 42, 77, 0.2);
}
.buttons div a:after {
background-image: url("images/buttons.png");
}
/* Icon images
---------------------------------------- */
.sitehome { background-image: url("./images/icon_home.gif"); }

View file

@ -287,20 +287,6 @@ dl.mini dd {
line-height: 2.5em;
}
/* PM panel adjustments */
.reply-all a.left {
background-position: 3px 60%;
}
.reply-all a.left:hover {
background-position: 0px 60%;
}
.reply-all {
font-size: 11px;
padding-top: 5px;
}
/* Defined rules list for PM options */
ol.def-rules {
padding-left: 0;

View file

@ -1,11 +1,3 @@
/* Set big button dimensions */
.buttons div.reply-icon { width: 96px; height: 25px; }
.buttons div.post-icon { width: 96px; height: 25px; }
.buttons div.locked-icon { width: 88px; height: 25px; }
.buttons div.pmreply-icon { width: 96px; height: 25px; }
.buttons div.newpm-icon { width: 84px; height: 25px; }
.buttons div.forwardpm-icon { width: 96px; height: 25px; }
/* Set profile icon dimensions */
ul.profile-icons li.pm-icon { width: 28px; height: 20px; }
ul.profile-icons li.quote-icon { width: 54px; height: 20px; }
@ -14,14 +6,6 @@ ul.profile-icons li.edit-icon { width: 42px; height: 20px; }
/* Online image */
.online { background-image: url("./icon_user_online.gif"); }
/* Big button images */
.reply-icon span { background-image: url("./button_topic_reply.gif"); }
.post-icon span { background-image: url("./button_topic_new.gif"); }
.locked-icon span { background-image: url("./button_topic_locked.gif"); }
.pmreply-icon span { background-image: url("./button_pm_reply.gif") ;}
.newpm-icon span { background-image: url("./button_pm_new.gif") ;}
.forwardpm-icon span { background-image: url("./button_pm_forward.gif") ;}
/* Icon images */
.pm-icon, .pm-icon a { background-image: url("./icon_contact_pm.gif"); }
.quote-icon, .quote-icon a { background-image: url("./icon_post_quote.gif"); }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -164,7 +164,7 @@
<table width="100%" cellspacing="0">
<tr class="nav">
<td valign="middle">&nbsp;<!-- IF U_WATCH_FORUM_LINK and not S_IS_BOT --><a href="{U_WATCH_FORUM_LINK}">{S_WATCH_FORUM_TITLE}</a><!-- ENDIF --></td>
<td align="{S_CONTENT_FLOW_END}" valign="middle"><!-- IF not S_IS_BOT and U_MARK_TOPICS --><a href="{U_MARK_TOPICS}">{L_MARK_TOPICS_READ}</a><!-- ENDIF -->&nbsp;</td>
<td align="{S_CONTENT_FLOW_END}" valign="middle"><!-- IF not S_IS_BOT and U_MARK_TOPICS and .topicrow --><a href="{U_MARK_TOPICS}">{L_MARK_TOPICS_READ}</a><!-- ENDIF -->&nbsp;</td>
</tr>
</table>
</td>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_migrations">
<column>migration_name</column>
<column>migration_depends_on</column>
<column>migration_schema_done</column>
<column>migration_data_done</column>
<column>migration_data_state</column>
<column>migration_start_time</column>
<column>migration_end_time</column>
<row>
<value>installed_migration</value>
<value></value>
<value>1</value>
<value>1</value>
<value></value>
<value>1234</value>
<value>5678</value>
</row>
</table>
<table name="phpbb_config">
<column>config_name</column>
<column>config_value</column>
<row>
<value>foo</value>
<value>bar</value>
</row>
</table>
</dataset>

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_modules">
<column>module_id</column>
<column>module_enabled</column>
<column>module_display</column>
<column>module_basename</column>
<column>module_class</column>
<column>parent_id</column>
<column>left_id</column>
<column>right_id</column>
<column>module_langname</column>
<column>module_mode</column>
<column>module_auth</column>
<row>
<value>1</value>
<value>1</value>
<value>1</value>
<value></value>
<value>acp</value>
<value>0</value>
<value>1</value>
<value>4</value>
<value>ACP_CAT</value>
<value></value>
<value></value>
</row>
<row>
<value>2</value>
<value>1</value>
<value>1</value>
<value>acp_test</value>
<value>acp</value>
<value>1</value>
<value>2</value>
<value>3</value>
<value>ACP_MODULE</value>
<value>test</value>
<value></value>
</row>
</table>
</dataset>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_acl_options">
<column>auth_option_id</column>
<column>auth_option</column>
<column>is_global</column>
<column>is_local</column>
<column>founder_only</column>
<row>
<value>1</value>
<value>global</value>
<value>1</value>
<value>0</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>local</value>
<value>0</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>both</value>
<value>1</value>
<value>1</value>
<value>0</value>
</row>
</table>
</dataset>

View file

@ -0,0 +1,27 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_dummy extends phpbb_db_migration
{
static public function depends_on()
{
return array('installed_migration');
}
function update_schema()
{
return array(
'add_columns' => array(
'phpbb_config' => array(
'extra_column' => array('UINT', 1),
),
),
);
}
}

View file

@ -0,0 +1,41 @@
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
*
*/
class phpbb_dbal_migration_fail extends phpbb_db_migration
{
function update_schema()
{
return array(
'add_columns' => array(
$this->table_prefix . 'config' => array(
'test_column' => array('BOOL', 1),
),
),
);
}
function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'config' => array(
'test_column',
),
),
);
}
function update_data()
{
return array(
array('config.add', array('foobar3', true)),
array('config.update', array('does_not_exist', true)),
);
}
}

View file

@ -0,0 +1,44 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_if extends phpbb_db_migration
{
function update_schema()
{
return array();
}
function update_data()
{
return array(
array('if', array(
true,
array('custom', array(array(&$this, 'test_true'))),
)),
array('if', array(
false,
array('custom', array(array(&$this, 'test_false'))),
)),
);
}
function test_true()
{
global $migrator_test_if_true_failed;
$migrator_test_if_true_failed = false;
}
function test_false()
{
global $migrator_test_if_false_failed;
$migrator_test_if_false_failed = true;
}
}

View file

@ -0,0 +1,30 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_installed extends phpbb_db_migration
{
function effectively_installed()
{
return true;
}
function update_data()
{
return array(
array('custom', array(array(&$this, 'test'))),
);
}
function test()
{
global $migrator_test_installed_failed;
$migrator_test_installed_failed = true;
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_recall extends phpbb_db_migration
{
function update_schema()
{
return array();
}
function update_data()
{
return array(
array('custom', array(array(&$this, 'test_call'))),
);
}
// This function should be called 10 times
function test_call($input)
{
global $migrator_test_call_input;
$migrator_test_call_input = (int) $input;
if ($migrator_test_call_input < 10)
{
return ($migrator_test_call_input + 1);
}
return;
}
}

View file

@ -0,0 +1,40 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_revert extends phpbb_db_migration
{
function update_schema()
{
return array(
'add_columns' => array(
'phpbb_config' => array(
'bar_column' => array('UINT', 1),
),
),
);
}
function revert_schema()
{
return array(
'drop_columns' => array(
'phpbb_config' => array(
'bar_column',
),
),
);
}
function update_data()
{
return array(
array('config.add', array('foobartest', 0)),
);
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration
{
static public function depends_on()
{
return array('phpbb_dbal_migration_revert');
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration
{
static public function depends_on()
{
return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration');
}
function update_schema()
{
trigger_error('Schema update of migration with unfulfillable dependency was run!');
}
function update_data()
{
trigger_error('Data update of migration with unfulfillable dependency was run!');
}
}

View file

@ -0,0 +1,257 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
require_once dirname(__FILE__) . '/migration/dummy.php';
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
require_once dirname(__FILE__) . '/migration/if.php';
require_once dirname(__FILE__) . '/migration/recall.php';
require_once dirname(__FILE__) . '/migration/revert.php';
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
require_once dirname(__FILE__) . '/migration/fail.php';
require_once dirname(__FILE__) . '/migration/installed.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
protected $db;
protected $db_tools;
protected $migrator;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
}
public function setUp()
{
parent::setUp();
$this->db = $this->new_dbal();
$this->db_tools = new phpbb_db_tools($this->db);
$this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config');
$tools = array(
new phpbb_db_migration_tool_config($this->config),
);
$this->migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools);
}
public function test_update()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
// schema
$this->migrator->update();
$this->assertFalse($this->migrator->finished());
$this->assertSqlResultEquals(
array(array('success' => '1')),
"SELECT 1 as success
FROM phpbb_migrations
WHERE migration_name = 'phpbb_dbal_migration_dummy'
AND migration_start_time >= " . (time() - 1) . "
AND migration_start_time <= " . (time() + 1),
'Start time set correctly'
);
// data
$this->migrator->update();
$this->assertTrue($this->migrator->finished());
$this->assertSqlResultEquals(
array(array('extra_column' => '1')),
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
'Dummy migration created extra_column with value 1 in all rows.'
);
$this->assertSqlResultEquals(
array(array('success' => '1')),
"SELECT 1 as success
FROM phpbb_migrations
WHERE migration_name = 'phpbb_dbal_migration_dummy'
AND migration_start_time <= migration_end_time
AND migration_end_time >= " . (time() - 1) . "
AND migration_end_time <= " . (time() + 1),
'End time set correctly'
);
// cleanup
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
}
public function test_unfulfillable()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'));
while (!$this->migrator->finished())
{
$this->migrator->update();
}
$this->assertTrue($this->migrator->finished());
$this->assertSqlResultEquals(
array(array('extra_column' => '1')),
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
'Dummy migration was run, even though an unfulfillable migration was found.'
);
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
}
public function test_if()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_if'));
// Don't like this, but I'm not sure there is any other way to do this
global $migrator_test_if_true_failed, $migrator_test_if_false_failed;
$migrator_test_if_true_failed = true;
$migrator_test_if_false_failed = false;
while (!$this->migrator->finished())
{
$this->migrator->update();
}
if ($migrator_test_if_true_failed)
{
$this->fail('True test failed');
}
if ($migrator_test_if_false_failed)
{
$this->fail('False test failed');
}
}
public function test_recall()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_recall'));
global $migrator_test_call_input;
// Run the schema first
$this->migrator->update();
$i = 0;
while (!$this->migrator->finished())
{
$this->migrator->update();
$this->assertSame($i, $migrator_test_call_input);
$i++;
}
$this->assertSame(10, $migrator_test_call_input);
}
public function test_revert()
{
// Make sure there are no other migrations in the db, this could cause issues
$this->db->sql_query("DELETE FROM phpbb_migrations");
$this->migrator->load_migration_state();
$this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency'));
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
// Install the migration first
while (!$this->migrator->finished())
{
$this->migrator->update();
}
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false);
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false);
$this->assertSqlResultEquals(
array(array('bar_column' => '1')),
"SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'",
'Installing revert migration failed to create bar_column.'
);
$this->assertTrue(isset($this->config['foobartest']));
while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false)
{
$this->migrator->revert('phpbb_dbal_migration_revert');
}
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
$this->assertFalse(isset($this->config['foobartest']));
$sql = 'SELECT * FROM phpbb_config';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (isset($row['bar_column']))
{
$this->fail('Revert did not remove test_column.');
}
}
public function test_fail()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
$this->assertFalse(isset($this->config['foobar3']));
try
{
while (!$this->migrator->finished())
{
$this->migrator->update();
}
}
catch (phpbb_db_migration_exception $e) {}
// Failure should have caused an automatic roll-back, so this should not exist.
$this->assertFalse(isset($this->config['foobar3']));
$sql = 'SELECT * FROM phpbb_config';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (isset($row['test_column']))
{
$this->fail('Revert did not remove test_column.');
}
}
public function test_installed()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_installed'));
global $migrator_test_installed_failed;
$migrator_test_installed_failed = false;
while (!$this->migrator->finished())
{
$this->migrator->update();
}
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false);
if ($migrator_test_installed_failed)
{
$this->fail('Installed test failed');
}
}
}

View file

@ -0,0 +1,124 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case
{
public function setup()
{
$this->config = new phpbb_config(array());
$this->tool = new phpbb_db_migration_tool_config($this->config);
parent::setup();
}
public function test_add()
{
try
{
$this->tool->add('foo', 'bar');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals('bar', $this->config['foo']);
try
{
$this->tool->add('foo', 'bar');
$this->fail('Exception not thrown');
}
catch (Exception $e) {}
}
public function test_update()
{
$this->config->set('foo', 'bar');
try
{
$this->tool->update('foo', 'bar2');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals('bar2', $this->config['foo']);
}
public function test_update_if_equals()
{
$this->config->set('foo', 'bar');
try
{
$this->tool->update_if_equals('', 'foo', 'bar2');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals('bar', $this->config['foo']);
try
{
$this->tool->update_if_equals('bar', 'foo', 'bar2');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals('bar2', $this->config['foo']);
}
public function test_remove()
{
$this->config->set('foo', 'bar');
try
{
$this->tool->remove('foo');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertFalse(isset($this->config['foo']));
}
public function test_reverse()
{
$this->config->set('foo', 'bar');
try
{
$this->tool->reverse('add', 'foo');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertFalse(isset($this->config['foo']));
$this->config->set('foo', 'bar');
try
{
$this->tool->reverse('update_if_equals', 'test', 'foo', 'bar');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals('test', $this->config['foo']);
}
}

View file

@ -0,0 +1,150 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml');
}
public function setup()
{
// Need global $db, $user for delete_module function in acp_modules
global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user;
parent::setup();
// Force add_log function to not be used
$skip_add_log = true;
$db = $this->db = $this->new_dbal();
$this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx);
$user = $this->user = new phpbb_user();
$this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules');
}
public function exists_data()
{
return array(
// Test the category
array(
'',
'ACP_CAT',
true,
),
array(
0,
'ACP_CAT',
true,
),
// Test the module
array(
'',
'ACP_MODULE',
false,
),
array(
false,
'ACP_MODULE',
true,
),
array(
'ACP_CAT',
'ACP_MODULE',
true,
),
);
}
/**
* @dataProvider exists_data
*/
public function test_exists($parent, $module, $expected)
{
$this->assertEquals($expected, $this->tool->exists('acp', $parent, $module));
}
public function test_add()
{
try
{
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
// Should throw an exception when trying to add a module that already exists
try
{
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
$this->fail('Exception not thrown');
}
catch (Exception $e) {}
try
{
$this->tool->add('acp', 'ACP_NEW_CAT', array(
'module_basename' => 'acp_new_module',
'module_langname' => 'ACP_NEW_MODULE',
'module_mode' => 'test',
'module_auth' => '',
));
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE'));
}
public function test_remove()
{
try
{
$this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE'));
}
public function test_reverse()
{
try
{
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
}
catch (Exception $e)
{
$this->fail($e);
}
try
{
$this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT');
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
}
}

View file

@ -0,0 +1,159 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
}
public function setup()
{
// Global $db and $cache are needed in acp/auth.php constructor
global $phpbb_root_path, $phpEx, $db, $cache;
parent::setup();
$db = $this->db = $this->new_dbal();
$cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx);
$this->auth = new phpbb_auth();
$this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
}
public function exists_data()
{
return array(
array(
'global',
true,
true,
),
array(
'local',
false,
true,
),
array(
'both',
true,
true,
),
array(
'both',
false,
true,
),
array(
'does_not_exist',
true,
false,
),
);
}
/**
* @dataProvider exists_data
*/
public function test_exists($auth_option, $global, $expected)
{
$this->assertEquals($expected, $this->tool->exists($auth_option, $global));
}
public function test_add()
{
try
{
$this->tool->add('new', true);
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('new', true));
$this->assertEquals(false, $this->tool->exists('new', false));
try
{
$this->tool->add('new', false);
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('new', false));
// Should fail (duplicate)
try
{
$this->tool->add('new', true);
$this->fail('Did not throw exception on duplicate');
}
catch (Exception $e) {}
}
public function test_remove()
{
try
{
$this->tool->remove('global', true);
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(false, $this->tool->exists('global', true));
try
{
$this->tool->remove('both', false);
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertEquals(false, $this->tool->exists('both', false));
// Should fail (does not exist)
try
{
$this->tool->remove('new', true);
$this->fail('Did not throw exception on duplicate');
}
catch (Exception $e) {}
}
public function test_reverse()
{
try
{
$this->tool->reverse('remove', 'global_test', true);
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertTrue($this->tool->exists('global_test', true));
try
{
$this->tool->reverse('add', 'global_test', true);
}
catch (Exception $e)
{
$this->fail($e);
}
$this->assertFalse($this->tool->exists('global_test', true));
}
}

View file

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_groups">
<column>group_id</column>
<column>group_avatar</column>
<column>group_rank</column>
<column>group_desc</column>
<row>
<value>1</value>
<value>default</value>
<value>1</value>
<value></value>
</row>
<row>
<value>2</value>
<value></value>
<value>0</value>
<value></value>
</row>
<row>
<value>3</value>
<value>default2</value>
<value>3</value>
<value></value>
</row>
</table>
<table name="phpbb_users">
<column>user_id</column>
<column>group_id</column>
<column>user_avatar</column>
<column>user_rank</column>
<column>username_clean</column>
<column>user_permissions</column>
<column>user_sig</column>
<column>user_occ</column>
<column>user_interests</column>
<row>
<value>1</value>
<value>1</value>
<value></value>
<value>0</value>
<value>barfoo</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
<row>
<value>2</value>
<value>1</value>
<value>default</value>
<value>1</value>
<value>foobar</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
<row>
<value>3</value>
<value>1</value>
<value>custom</value>
<value>2</value>
<value>bertie</value>
<value></value>
<value></value>
<value></value>
<value></value>
</row>
</table>
<table name="phpbb_user_group">
<column>user_id</column>
<column>group_id</column>
<column>user_pending</column>
<row>
<value>1</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>1</value>
<value>2</value>
<value>0</value>
</row>
<row>
<value>1</value>
<value>3</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>2</value>
<value>0</value>
</row>
<row>
<value>2</value>
<value>3</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>1</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>2</value>
<value>0</value>
</row>
<row>
<value>3</value>
<value>3</value>
<value>0</value>
</row>
</table>
</dataset>

View file

@ -0,0 +1,156 @@
<?php
/**
*
* @package testing
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/group_user_attributes.xml');
}
public function group_user_attributes_data()
{
return array(
array(
'Setting new default group without settings for user with no settings - no change',
1,
2,
array(
'group_avatar' => '',
'group_avatar_type' => 0,
'group_avatar_height' => 0,
'group_avatar_width' => 0,
'group_rank' => 0,
),
array(
'user_avatar' => '',
'user_rank' => 0,
),
),
array(
'Setting new default group without settings for user with default settings - user settings overwritten',
2,
2,
array(
'group_avatar' => '',
'group_avatar_type' => 0,
'group_avatar_height' => 0,
'group_avatar_width' => 0,
'group_rank' => 0,
),
array(
'user_avatar' => '',
'user_rank' => 0,
),
),
array(
'Setting new default group without settings for user with custom settings - no change',
3,
2,
array(
'group_avatar' => '',
'group_avatar_type' => 0,
'group_avatar_height' => 0,
'group_avatar_width' => 0,
'group_rank' => 0,
),
array(
'user_avatar' => 'custom',
'user_rank' => 2,
),
),
array(
'Setting new default group with settings for user with no settings - user settings overwritten',
1,
3,
array(
'group_avatar' => 'default2',
'group_avatar_type' => 1,
'group_avatar_height' => 1,
'group_avatar_width' => 1,
'group_rank' => 3,
),
array(
'user_avatar' => 'default2',
'user_rank' => 3,
),
),
array(
'Setting new default group with settings for user with default settings - user settings overwritten',
2,
3,
array(
'group_avatar' => 'default2',
'group_avatar_type' => 1,
'group_avatar_height' => 1,
'group_avatar_width' => 1,
'group_rank' => 3,
),
array(
'user_avatar' => 'default2',
'user_rank' => 3,
),
),
array(
'Setting new default group with settings for user with custom settings - no change',
3,
3,
array(
'group_avatar' => 'default2',
'group_avatar_type' => 1,
'group_avatar_height' => 1,
'group_avatar_width' => 1,
'group_rank' => 3,
),
array(
'user_avatar' => 'custom',
'user_rank' => 2,
),
),
);
}
/**
* @dataProvider group_user_attributes_data
*/
public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected)
{
global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container;
$user->ip = '';
$cache = new phpbb_mock_cache;
$db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$auth = $this->getMock('phpbb_auth');
$auth->expects($this->any())
->method('acl_clear_prefetch');
$cache_driver = new phpbb_cache_driver_null();
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$phpbb_container
->expects($this->any())
->method('get')
->with('cache.driver')
->will($this->returnValue($cache_driver));
group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row);
$sql = 'SELECT user_avatar, user_rank
FROM ' . USERS_TABLE . '
WHERE user_id = ' . $user_id;
$result = $db->sql_query($sql);
$this->assertEquals(array($expected), $db->sql_fetchrowset($result));
$db->sql_freeresult($result);
}
}

View file

@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
case 'phpbb_db_driver_postgres':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
{
$this->pdo->exec('DROP TABLE ' . $table . ' CASCADE');
}
$this->purge_extras();
break;
default:
$this->connect(false);
@ -418,6 +428,19 @@ class phpbb_database_test_connection_manager
$queries[] = 'DROP SEQUENCE ' . current($row);
}
break;
case 'phpbb_db_driver_postgres':
$sql = 'SELECT sequence_name
FROM information_schema.sequences';
$result = $this->pdo->query($sql);
while ($row = $result->fetch(PDO::FETCH_NUM))
{
$queries[] = 'DROP SEQUENCE ' . current($row);
}
$queries[] = 'DROP TYPE IF EXISTS varchar_ci CASCADE';
break;
}
foreach ($queries as $query)

View file

@ -0,0 +1,21 @@
#!/bin/bash
#
# @copyright (c) 2013 phpBB Group
# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
#
set -e
function add_ext_to_php_ini
{
echo "extension=$1.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
}
# redis
git clone git://github.com/nicolasff/phpredis.git
cd phpredis
phpize
./configure
make
make install
cd ..
add_ext_to_php_ini 'redis'

View file

@ -17,7 +17,7 @@
<exclude>tests/functional</exclude>
</testsuite>
<testsuite name="phpBB Functional Tests">
<directory suffix="_test.php" phpVersion="5.3.0" phpVersionOperator=">=">../tests/functional</directory>
<directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory>
</testsuite>
</testsuites>
@ -34,6 +34,8 @@
<server name="PHPBB_TEST_DBNAME" value="phpbb_tests" />
<server name="PHPBB_TEST_DBUSER" value="root" />
<server name="PHPBB_TEST_DBPASSWD" value="" />
<server name="PHPBB_TEST_REDIS_HOST" value="localhost" />
<server name="PHPBB_TEST_TABLE_PREFIX" value="phpbb_"/>
<server name="PHPBB_FUNCTIONAL_URL" value="http://localhost/" />
</php>
</phpunit>

View file

@ -17,7 +17,7 @@
<exclude>tests/functional</exclude>
</testsuite>
<testsuite name="phpBB Functional Tests">
<directory suffix="_test.php" phpVersion="5.3.0" phpVersionOperator=">=">../tests/functional</directory>
<directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">../tests/functional</directory>
</testsuite>
</testsuites>
@ -36,6 +36,8 @@
<server name="PHPBB_TEST_DBNAME" value="phpbb_tests" />
<server name="PHPBB_TEST_DBUSER" value="postgres" />
<server name="PHPBB_TEST_DBPASSWD" value="" />
<server name="PHPBB_TEST_REDIS_HOST" value="localhost" />
<server name="PHPBB_TEST_TABLE_PREFIX" value="phpbb_"/>
<server name="PHPBB_FUNCTIONAL_URL" value="http://localhost/" />
</php>
</phpunit>

54
travis/setup-webserver.sh Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
#
# @copyright (c) 2013 phpBB Group
# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
#
set -e
sudo apt-get update -qq
sudo apt-get install -qq nginx realpath
sudo service nginx stop
DIR=$(dirname "$0")
PHPBB_ROOT_PATH=$(realpath "$DIR/../phpBB")
NGINX_CONF="/etc/nginx/sites-enabled/default"
PHP_FPM_BIN="$HOME/.phpenv/versions/$TRAVIS_PHP_VERSION/sbin/php-fpm"
PHP_FPM_CONF="$DIR/php-fpm.conf"
PHP_FPM_SOCK=$(realpath "$DIR")/php-fpm.sock
USER=$(whoami)
# php-fpm configuration
echo "
[global]
[travis]
user = $USER
group = $USER
listen = $PHP_FPM_SOCK
pm = static
pm.max_children = 2
php_admin_value[memory_limit] = 128M
" > $PHP_FPM_CONF
# nginx configuration
echo "
server {
listen 80;
root $PHPBB_ROOT_PATH/;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:$PHP_FPM_SOCK;
include fastcgi_params;
}
}
" | sudo tee $NGINX_CONF > /dev/null
# Start daemons
sudo $PHP_FPM_BIN --fpm-config "$DIR/php-fpm.conf"
sudo service nginx start