Completed
Branch release-3.2.0 (10f575)
by Daniel
03:11
created

m7_update_settings_data   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 51
rs 10
wmc 6
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\migrations\v20x;
11
12
/**
13
 * Initial schema changes needed for Extension installation
14
 */
15
class m7_update_settings_data extends \phpbb\db\migration\migration
16
{
17
	/**
18
	 * @inheritdoc
19
	 */
20
	public static function depends_on()
21
	{
22
		return array(
23
			'\blitze\sitemaker\migrations\v20x\m1_initial_schema',
24
			'\blitze\sitemaker\migrations\v20x\m6_add_block_settings_field',
25
		);
26
	}
27
28
	/**
29
	 * Skip this migration if the module_dir column does not exist
30
	 *
31
	 * @return bool True to skip this migration, false to run it
32
	 * @access public
33
	 */
34
	public function effectively_installed()
35
	{
36
		return !$this->db_tools->sql_table_exists($this->table_prefix . 'sm_blocks_config');
37
	}
38
39
	/**
40
	 * @inheritdoc
41
	 */
42
	public function update_data()
43
	{
44
		return array(
45
			array('custom', array(array($this, 'update_blocks_settings'))),
46
		);
47
	}
48
49
	public function update_blocks_settings()
50
	{
51
		$result = $this->db->sql_query('SELECT * FROM ' . $this->table_prefix . 'sm_blocks_config');
52
53
		$bconfig = array();
54
		while ($row = $this->db->sql_fetchrow($result))
55
		{
56
			$bconfig[$row['bid']][$row['bvar']] = $row['bval'];
57
		}
58
		$this->db->sql_freeresult($result);
59
60
		foreach ($bconfig as $bid => $settings)
61
		{
62
			$sql_data = array(
63
				'settings'	=> serialize($settings)
64
			);
65
			$this->db->sql_query('UPDATE ' . $this->table_prefix . 'sm_blocks SET ' . $this->db->sql_build_array('UPDATE', $sql_data) .' WHERE bid = ' . (int) $bid);
66
		}
67
	}
68
}
69