1 | <?php |
||
12 | class c4_convert_primetime_data extends \phpbb\db\migration\migration |
||
13 | { |
||
14 | /** |
||
15 | * @inheritdoc |
||
16 | */ |
||
17 | public static function depends_on() |
||
18 | { |
||
19 | return array( |
||
20 | '\blitze\sitemaker\migrations\v20x\m1_initial_schema', |
||
21 | '\blitze\sitemaker\migrations\v20x\m2_initial_data', |
||
22 | ); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Skip this migration if the pt_blocks table does not exist |
||
27 | * |
||
28 | * @return bool True to skip this migration, false to run it |
||
29 | * @access public |
||
30 | */ |
||
31 | public function effectively_installed() |
||
32 | { |
||
33 | return !$this->db_tools->sql_table_exists($this->table_prefix . 'pt_blocks'); |
||
34 | } |
||
35 | |||
36 | public function update_data() |
||
37 | { |
||
38 | return array( |
||
39 | array('custom', array(array($this, 'import_block_routes'))), |
||
40 | array('custom', array(array($this, 'import_blocks'))), |
||
41 | array('custom', array(array($this, 'import_blocks_config'))), |
||
42 | array('custom', array(array($this, 'import_menus'))), |
||
43 | array('custom', array(array($this, 'import_menu_items'))), |
||
44 | array('custom', array(array($this, 'update_block_names'))), |
||
45 | array('custom', array(array($this, 'update_forum_names'))), |
||
46 | |||
47 | array('config.add', array('sitemaker_last_changed', $this->config['primetime_last_changed'])), |
||
48 | array('config.add', array('sitemaker_default_layout', $this->config['primetime_default_layout'])), |
||
49 | array('config.add', array('sitemaker_parent_forum_id', $this->config['primetime_parent_forum_id'])), |
||
50 | array('config.add', array('sitemaker_blocks_cleanup_gc', $this->config['primetime_blocks_cleanup_gc'])), |
||
51 | array('config.add', array('sitemaker_blocks_cleanup_last_gc', $this->config['primetime_blocks_cleanup_last_gc'], 1)), |
||
52 | array('config.add', array('sitemaker_startpage_controller', $this->config['primetime_startpage_controller'])), |
||
53 | array('config.add', array('sitemaker_startpage_method', $this->config['primetime_startpage_method'])), |
||
54 | array('config.add', array('sitemaker_startpage_params', $this->config['primetime_startpage_params'])), |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | public function import_block_routes() |
||
59 | { |
||
60 | $this->copy_table('pt_block_routes', 'sm_block_routes'); |
||
61 | } |
||
62 | |||
63 | public function import_blocks() |
||
64 | { |
||
65 | $this->copy_table('pt_blocks', 'sm_blocks'); |
||
66 | } |
||
67 | |||
68 | public function import_blocks_config() |
||
69 | { |
||
70 | $this->copy_table('pt_blocks_config', 'sm_blocks_config'); |
||
71 | } |
||
72 | |||
73 | public function import_menus() |
||
74 | { |
||
75 | $this->copy_table('pt_menus', 'sm_menus'); |
||
76 | } |
||
77 | |||
78 | public function import_menu_items() |
||
79 | { |
||
80 | $this->copy_table('pt_menu_items', 'sm_menu_items'); |
||
81 | } |
||
82 | |||
83 | public function update_block_names() |
||
84 | { |
||
85 | $result = $this->db->sql_query('SELECT bid, name FROM ' . $this->table_prefix . 'sm_blocks'); |
||
86 | |||
87 | while ($row = $this->db->sql_fetchrow($result)) |
||
88 | { |
||
89 | $name = str_replace('primetime.core', 'blitze.sitemaker', $row['name']); |
||
90 | $this->db->sql_query('UPDATE ' . $this->table_prefix . "sm_blocks SET name='" . $this->db->sql_escape($name) . "' WHERE bid = " . (int) $row['bid']); |
||
91 | } |
||
92 | $this->db->sql_freeresult($result); |
||
93 | } |
||
94 | |||
95 | public function update_forum_names() |
||
96 | { |
||
97 | if (!class_exists('acp_forums')) |
||
98 | { |
||
99 | include($this->phpbb_root_path . 'includes/acp/acp_forums.' . $this->php_ext); |
||
100 | } |
||
101 | |||
102 | $acp_forum = new \acp_forums(); |
||
103 | $errors = $acp_forum->delete_forum($this->config['sitemaker_parent_forum_id']); |
||
104 | |||
105 | if (!sizeof($errors) && !empty($this->config['primetime_parent_forum_id'])) |
||
106 | { |
||
107 | $this->db->sql_query('UPDATE ' . FORUMS_TABLE . " SET forum_name='phpBB Sitemaker Extensions' WHERE forum_id = " . (int) $this->config['primetime_parent_forum_id']); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | public function copy_table($old_table, $new_table) |
||
112 | { |
||
113 | // Load the insert buffer class to perform a buffered multi insert |
||
114 | $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . $new_table); |
||
115 | |||
116 | $result = $this->db->sql_query('SELECT * FROM ' . $this->table_prefix . $old_table); |
||
117 | |||
118 | while ($row = $this->db->sql_fetchrow($result)) |
||
119 | { |
||
120 | $insert_buffer->insert($row); |
||
121 | } |
||
122 | $this->db->sql_freeresult($result); |
||
123 | |||
124 | // Flush the buffer |
||
125 | $insert_buffer->flush(); |
||
126 | } |
||
127 | } |
||
128 |