release_1_4_0_data   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 30
c 2
b 0
f 0
dl 0
loc 70
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A convert_similar_topic_forums() 0 20 3
A migrate_config_data() 0 17 3
A effectively_installed() 0 3 2
A depends_on() 0 3 1
A update_data() 0 8 1
1
<?php
2
/**
3
 *
4
 * Precise Similar Topics
5
 *
6
 * @copyright (c) 2016 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\similartopics\migrations;
12
13
class release_1_4_0_data extends \phpbb\db\migration\migration
0 ignored issues
show
Bug introduced by
The type phpbb\db\migration\migration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
{
15
	public function effectively_installed()
16
	{
17
		return !$this->config->offsetExists('similar_topics_hide') && !$this->config->offsetExists('similar_topics_ignore');
18
	}
19
20
	public static function depends_on()
21
	{
22
		return array('\vse\similartopics\migrations\release_1_4_0_schema');
23
	}
24
25
	public function update_data()
26
	{
27
		return array(
28
			array('custom', array(array($this, 'migrate_config_data'))),
29
			array('custom', array(array($this, 'convert_similar_topic_forums'))),
30
31
			array('config.remove', array('similar_topics_hide')),
32
			array('config.remove', array('similar_topics_ignore')),
33
		);
34
	}
35
36
	/**
37
	 * Convert data stored in configs to new columns in the forum table
38
	 */
39
	public function migrate_config_data()
40
	{
41
		$old_configs = array(
42
			'similar_topics_hide',
43
			'similar_topics_ignore',
44
		);
45
46
		foreach ($old_configs as $column)
47
		{
48
			if (!empty($this->config[$column]))
49
			{
50
				$forum_ids = explode(',', $this->config[$column]);
51
52
				$sql = 'UPDATE ' . FORUMS_TABLE . "
0 ignored issues
show
Bug introduced by
The constant vse\similartopics\migrations\FORUMS_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
					SET $column = 1
54
					WHERE " . $this->db->sql_in_set('forum_id', $forum_ids);
55
				$this->db->sql_query($sql);
56
			}
57
		}
58
	}
59
60
	/**
61
	 * Convert imploded string data into json encoded data
62
	 */
63
	public function convert_similar_topic_forums()
64
	{
65
		$sql = 'SELECT forum_id, similar_topic_forums
66
			FROM ' . FORUMS_TABLE;
0 ignored issues
show
Bug introduced by
The constant vse\similartopics\migrations\FORUMS_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
67
		$result = $this->db->sql_query($sql);
68
69
		while ($row = $this->db->sql_fetchrow($result))
70
		{
71
			if (!empty($row['similar_topic_forums']))
72
			{
73
				$forum_ids = explode(',', $row['similar_topic_forums']);
74
				$forum_ids = json_encode($forum_ids, JSON_NUMERIC_CHECK);
75
76
				$sql = 'UPDATE ' . FORUMS_TABLE . "
77
					SET similar_topic_forums = '" . $this->db->sql_escape($forum_ids) . "'
78
					WHERE forum_id = " . (int) $row['forum_id'];
79
				$this->db->sql_query($sql);
80
			}
81
		}
82
		$this->db->sql_freeresult($result);
83
	}
84
}
85