diff --git a/phpBB/phpbb/db/migration/data/v400/remove_jabber.php b/phpBB/phpbb/db/migration/data/v400/remove_jabber.php index 34c4c6a355..82b25b819f 100644 --- a/phpBB/phpbb/db/migration/data/v400/remove_jabber.php +++ b/phpBB/phpbb/db/migration/data/v400/remove_jabber.php @@ -34,6 +34,11 @@ class remove_jabber extends migration $this->table_prefix . 'users' => [ 'user_jabber', ], + ], + 'add_columns' => [ + $this->table_prefix . 'user_notifications' => [ + 'id' => ['ULINT', null, 'auto_increment'], + ], ] ]; } @@ -45,7 +50,12 @@ class remove_jabber extends migration $this->table_prefix . 'users' => [ 'user_jabber' => ['VCHAR_UNI', ''], ], - ] + ], + 'drop_columns' => [ + $this->table_prefix . 'user_notifications' => [ + 'id', + ], + ], ]; } @@ -101,11 +111,26 @@ class remove_jabber extends migration ]; } - public function move_jabber_to_email_notifications() + public function move_jabber_to_email_notifications(int|null $start) { - $sql = 'UPDATE ' . $this->tables['user_notifications'] . ' - SET ' . $this->db->sql_build_array('UPDATE', ['method' => 'notification.method.email']) . " - WHERE method = 'notification.method.jabber'"; - $this->db->sql_query($sql); + $limit = 1000; + + $sql = 'SELECT id FROM ' . $this->tables['user_notifications'] . " + WHERE method = 'notification.method.jabber' + ORDER BY id ASC"; + $result = $this->db->sql_query_limit($sql, $limit, $start ?: 0); + $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + $ids_array = array_column($rowset, 'id'); + + if (count($ids_array)) + { + $sql = 'UPDATE ' . $this->tables['user_notifications'] . ' + SET ' . $this->db->sql_build_array('UPDATE', ['method' => 'notification.method.email']) . ' + WHERE ' . $this->db->sql_in_set('id', $ids_array); + $this->db->sql_query($sql); + } + + return count($ids_array) < $limit ? true : $start + $limit; } }