Completed
Push — develop-3.2.x ( 86239d...17b6f9 )
by Matt
05:09 queued 02:36
created

release_1_3_0_fulltext::revert_fulltext_changes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
/**
3
*
4
* Precise Similar Topics
5
*
6
* @copyright (c) 2014 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_3_0_fulltext extends \phpbb\db\migration\migration
14
{
15
	public function effectively_installed()
16
	{
17
		return !isset($this->config['similar_topics_fulltext']);
18
	}
19
20
	static public function depends_on()
21
	{
22
		return array('\vse\similartopics\migrations\release_1_3_0_data');
23
	}
24
25
	public function revert_data()
26
	{
27
		return array(
28
			// Revert the storage engine back to the original setting if it was stored
29
			array('if', array(
30
				(!empty($this->config['similar_topics_fulltext'])),
31
				array('custom', array(array($this, 'revert_fulltext_changes'))),
32
			)),
33
34
			// Remove the config holding the original storage engine setting if it exists
35
			array('if', array(
36
				(isset($this->config['similar_topics_fulltext'])),
37
				array('config.remove', array('similar_topics_fulltext')),
38
			)),
39
		);
40
	}
41
42
	/**
43
	* Drop the FULLTEXT index on phpbb_topics.topic_title
44
	* Convert phpbb_topics back to the original storage engine
45
	*/
46
	public function revert_fulltext_changes()
47
	{
48
		$fulltext = new \vse\similartopics\core\fulltext_support($this->db);
49
50
		// Drop the FULLTEXT index
51
		if ($fulltext->index('topic_title'))
52
		{
53
			$sql = 'ALTER TABLE ' . TOPICS_TABLE . ' DROP INDEX topic_title';
54
			$this->db->sql_query($sql);
55
		}
56
57
		// Revert the storage engine back to its original setting
58
		$sql = 'ALTER TABLE ' . TOPICS_TABLE . ' ENGINE = ' . $this->db->sql_escape(strtoupper($this->config['similar_topics_fulltext']));
59
		$this->db->sql_query($sql);
60
	}
61
}
62