Completed
Pull Request — master (#23)
by
unknown
02:00
created

release_postgres_support::depends_on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * Precise Similar Topics
5
 *
6
 * @copyright (c) 2018 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_postgres_support extends \phpbb\db\migration\migration
14
{
15
	public function effectively_installed()
16
	{
17
		return $this->config->offsetExists('similar_topics_postgres_ts_name');
18
	}
19
20
	static public function depends_on()
21
	{
22
		return array('\vse\similartopics\migrations\release_1_4_3_data');
23
	}
24
25
	public function update_data()
26
	{
27
		return array(
28
			array('config.add', array('similar_topics_postgres_ts_name',
29
				($this->config->offsetExists('fulltext_postgres_ts_name')? $this->config['fulltext_postgres_ts_name'] : 'simple')
30
			))
31
		);
32
	}
33
34
	public function revert_data()
35
	{
36
		return array(
37
			// Revert the storage engine back to the original setting if it was stored
38
			array('if', array(
39
				($this->db->get_sql_layer() === 'postgres'),
40
				array('custom', array(array($this, 'revert_postgres_changes'))),
41
			)),
42
43
		);
44
	}
45
46
	/**
47
	 * Drop the PostgreSQL FULLTEXT index on phpbb_topics.topic_title
48
	 *
49
	 */
50
	public function revert_postgres_changes()
51
	{
52
		$fulltext = new \vse\similartopics\core\fulltext_support($this->db);
53
		$indexes = $fulltext->get_pg_indexes();
54
55
		if ($fulltext->is_postgres() && !empty($indexes))
56
		{
57
			foreach($indexes as $index)
58
			{
59
				$sql = 'DROP INDEX ' . $index;
60
				$this->db->sql_query($sql);
61
			}
62
63
		}
64
65
	}
66
67
}
68