Completed
Push — release-2.1 ( aa21c4...7040ad )
by Mathias
09:20
created

Sources/DbSearch-mysql.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * This file contains database functions specific to search related activity.
5
 *
6
 * Simple Machines Forum (SMF)
7
 *
8
 * @package SMF
9
 * @author Simple Machines http://www.simplemachines.org
10
 * @copyright 2017 Simple Machines and individual contributors
11
 * @license http://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1 Beta 4
14
 */
15
16
if (!defined('SMF'))
17
	die('No direct access...');
18
19
/**
20
 *  Add the file functions to the $smcFunc array.
21
 */
22
function db_search_init()
23
{
24
	global $smcFunc;
25
26 View Code Duplication
	if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query')
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
		$smcFunc += array(
28
			'db_search_query' => 'smf_db_query',
29
			'db_search_support' => 'smf_db_search_support',
30
			'db_create_word_search' => 'smf_db_create_word_search',
31
			'db_support_ignore' => true,
32
		);
33
}
34
35
/**
36
 * This function will tell you whether this database type supports this search type.
37
 *
38
 * @param string $search_type The search type.
39
 * @return boolean Whether or not the specified search type is supported by this db system
40
 */
41
function smf_db_search_support($search_type)
42
{
43
	$supported_types = array('fulltext');
44
45
	return in_array($search_type, $supported_types);
46
}
47
48
/**
49
 * Highly specific function, to create the custom word index table.
50
 *
51
 * @param string $size The size of the desired index.
52
 */
53
function smf_db_create_word_search($size)
0 ignored issues
show
The parameter $size is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
{
55
	global $smcFunc;
56
57
	if ($size == 'small')
58
		$size = 'smallint(5)';
59
	elseif ($size == 'medium')
60
		$size = 'mediumint(8)';
61
	else
62
		$size = 'int(10)';
63
64
	$smcFunc['db_query']('', '
65
		CREATE TABLE {db_prefix}log_search_words (
66
			id_word {raw:size} unsigned NOT NULL default {string:string_zero},
67
			id_msg int(10) unsigned NOT NULL default {string:string_zero},
68
			PRIMARY KEY (id_word, id_msg)
69
		) ENGINE=InnoDB',
70
		array(
71
			'string_zero' => '0',
72
			'size' => $size,
73
		)
74
	);
75
}
76
77
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...