|
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 |
|
14
|
|
|
{ |
|
15
|
|
|
public function effectively_installed() |
|
16
|
|
|
{ |
|
17
|
|
|
return !$this->config->offsetExists('similar_topics_hide') && !$this->config->offsetExists('similar_topics_ignore'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
static public 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
|
|
|
$forum_ids = explode(',', $this->config[$column]); |
|
49
|
|
|
|
|
50
|
|
|
if (!empty($forum_ids)) |
|
51
|
|
|
{ |
|
52
|
|
|
$sql = 'UPDATE ' . FORUMS_TABLE . " |
|
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; |
|
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 = '{$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
|
|
|
|