[ticket/11842] Use type map for updating avatar types in database

PHPBB3-11842
This commit is contained in:
Marc Alexander 2013-11-25 13:12:08 +01:00
parent b5e6d107ae
commit 0d4bf3ff45

View file

@ -11,6 +11,15 @@ namespace phpbb\db\migration\data\v310;
class avatar_types extends \phpbb\db\migration\migration class avatar_types extends \phpbb\db\migration\migration
{ {
/**
* @var avatar type map
*/
protected $avatar_type_map = array(
AVATAR_UPLOAD => 'avatar.driver.upload',
AVATAR_REMOTE => 'avatar.driver.remote',
AVATAR_GALLERY => 'avatar.driver.local',
);
static public function depends_on() static public function depends_on()
{ {
return array( return array(
@ -28,38 +37,24 @@ class avatar_types extends \phpbb\db\migration\migration
} }
public function update_user_avatar_type() public function update_user_avatar_type()
{
foreach ($this->avatar_type_map as $old => $new)
{ {
$sql = 'UPDATE ' . $this->table_prefix . "users $sql = 'UPDATE ' . $this->table_prefix . "users
SET user_avatar_type = 'avatar.driver.upload' SET user_avatar_type = '$new'
WHERE user_avatar_type = " . AVATAR_UPLOAD; WHERE user_avatar_type = $old";
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->table_prefix . "users
SET user_avatar_type = 'avatar.driver.remote'
WHERE user_avatar_type = " . AVATAR_REMOTE;
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->table_prefix . "users
SET user_avatar_type = 'avatar.driver.local'
WHERE user_avatar_type = " . AVATAR_GALLERY;
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
}
public function update_group_avatar_type() public function update_group_avatar_type()
{
foreach ($this->avatar_type_map as $old => $new)
{ {
$sql = 'UPDATE ' . $this->table_prefix . "groups $sql = 'UPDATE ' . $this->table_prefix . "groups
SET group_avatar_type = 'avatar.driver.upload' SET group_avatar_type = '$new'
WHERE group_avatar_type = " . AVATAR_UPLOAD; WHERE group_avatar_type = $old";
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->table_prefix . "groups
SET group_avatar_type = 'avatar.driver.remote'
WHERE group_avatar_type = " . AVATAR_REMOTE;
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->table_prefix . "groups
SET group_avatar_type = 'avatar.driver.local'
WHERE group_avatar_type = " . AVATAR_GALLERY;
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
}
} }