Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
acp_prune_users_module
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 effectively_installed
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
 depends_on
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update_data
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 move_prune_users_module
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\db\migration\data\v310;
15
16class acp_prune_users_module extends \phpbb\db\migration\container_aware_migration
17{
18    public function effectively_installed()
19    {
20        $sql = 'SELECT module_id
21            FROM ' . MODULES_TABLE . "
22            WHERE module_class = 'acp'
23                AND module_langname = 'ACP_CAT_USERS'";
24        $result = $this->db->sql_query($sql);
25        $acp_cat_users_id = (int) $this->db->sql_fetchfield('module_id');
26        $this->db->sql_freeresult($result);
27
28        $sql = 'SELECT parent_id
29            FROM ' . MODULES_TABLE . "
30            WHERE module_class = 'acp'
31                AND module_basename = 'acp_prune'
32                AND module_mode = 'users'";
33        $result = $this->db->sql_query($sql);
34        $acp_prune_users_parent = (int) $this->db->sql_fetchfield('parent_id');
35        $this->db->sql_freeresult($result);
36
37        // Skip migration if "Users" category has been deleted
38        // or the module has already been moved to that category
39        return !$acp_cat_users_id || $acp_cat_users_id === $acp_prune_users_parent;
40    }
41
42    public static function depends_on()
43    {
44        return array('\phpbb\db\migration\data\v310\beta1');
45    }
46
47    public function update_data()
48    {
49        return array(
50            array('custom', array(array($this, 'move_prune_users_module'))),
51        );
52    }
53
54    public function move_prune_users_module()
55    {
56        $sql = 'SELECT module_id
57            FROM ' . MODULES_TABLE . "
58            WHERE module_class = 'acp'
59                AND module_basename = 'acp_prune'
60                AND module_mode = 'users'";
61        $result = $this->db->sql_query($sql);
62        $acp_prune_users_id = (int) $this->db->sql_fetchfield('module_id');
63        $this->db->sql_freeresult($result);
64
65        $sql = 'SELECT module_id
66            FROM ' . MODULES_TABLE . "
67            WHERE module_class = 'acp'
68                AND module_langname = 'ACP_CAT_USERS'";
69        $result = $this->db->sql_query($sql);
70        $acp_cat_users_id = (int) $this->db->sql_fetchfield('module_id');
71        $this->db->sql_freeresult($result);
72
73        $module_manager = $this->container->get('module.manager');
74        $module_manager->move_module($acp_prune_users_id, $acp_cat_users_id, 'acp');
75    }
76}