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

m14_update_settings_data   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 4
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 m14_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\m7_update_settings_data',
24
		);
25
	}
26
27
	/**
28
	 * @inheritdoc
29
	 */
30
	public function update_data()
31
	{
32
		return array(
33
			array('custom', array(array($this, 'update_blocks_settings'))),
34
		);
35
	}
36
37
	public function update_blocks_settings()
38
	{
39
		$result = $this->db->sql_query('SELECT bid, settings FROM ' . $this->table_prefix . "sm_blocks WHERE settings <> ''");
40
41
		while ($row = $this->db->sql_fetchrow($result))
42
		{
43
			$settings = json_encode(unserialize($row['settings']));
44
			$sql_data = array(
45
				'settings'	=> $settings,
46
				'hash' => md5($settings),
47
			);
48
			$this->db->sql_query('UPDATE ' . $this->table_prefix . 'sm_blocks SET ' . $this->db->sql_build_array('UPDATE', $sql_data) .' WHERE bid = ' . (int) $row['bid']);
49
		}
50
		$this->db->sql_freeresult($result);
51
	}
52
}
53