| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* Implementation of hook_install().
|
| 7 |
*/
|
| 8 |
|
| 9 |
function sphinx_install() {
|
| 10 |
switch ($GLOBALS['db_type']) {
|
| 11 |
case 'mysql':
|
| 12 |
case 'mysqli':
|
| 13 |
$sql1 = "
|
| 14 |
CREATE TABLE IF NOT EXISTS sphinx_indexes (
|
| 15 |
iid int(3) unsigned NOT NULL auto_increment,
|
| 16 |
index_name varchar(60) NOT NULL,
|
| 17 |
display_name varchar(60) NOT NULL,
|
| 18 |
path varchar(60) NOT NULL,
|
| 19 |
default_sort_key_fid int(3) unsigned NOT NULL,
|
| 20 |
default_sort_order varchar(10) NOT NULL,
|
| 21 |
server varchar(255) NOT NULL,
|
| 22 |
port int(5) NOT NULL,
|
| 23 |
excerpt int(1) unsigned NOT NULL,
|
| 24 |
multiquery int(1) unsigned NOT NULL,
|
| 25 |
active int(1) unsigned NOT NULL,
|
| 26 |
PRIMARY KEY (iid),
|
| 27 |
KEY url (path)
|
| 28 |
);";
|
| 29 |
|
| 30 |
$sql2 = "
|
| 31 |
CREATE TABLE IF NOT EXISTS sphinx_fields (
|
| 32 |
fid int(11) unsigned NOT NULL auto_increment,
|
| 33 |
iid int(11) unsigned NOT NULL,
|
| 34 |
field_name varchar(60) NOT NULL,
|
| 35 |
display_name varchar(60) NOT NULL,
|
| 36 |
active int(11) unsigned NOT NULL,
|
| 37 |
excerpt int(11) unsigned NOT NULL,
|
| 38 |
weight tinyint(4) NOT NULL,
|
| 39 |
PRIMARY KEY (fid),
|
| 40 |
KEY iid (iid)
|
| 41 |
);";
|
| 42 |
$sql3 = "
|
| 43 |
CREATE TABLE IF NOT EXISTS sphinx_attributes (
|
| 44 |
aid int(10) unsigned NOT NULL auto_increment,
|
| 45 |
iid int(3) unsigned NOT NULL,
|
| 46 |
attribute_name varchar(60) NOT NULL,
|
| 47 |
display_name varchar(60) NOT NULL,
|
| 48 |
type varchar(60) NOT NULL,
|
| 49 |
default_sort varchar(60) NOT NULL,
|
| 50 |
active int(1) unsigned NOT NULL,
|
| 51 |
facet int(1) unsigned NOT NULL,
|
| 52 |
PRIMARY KEY (aid),
|
| 53 |
KEY iid (iid)
|
| 54 |
);";
|
| 55 |
$res1 = db_query($sql1);
|
| 56 |
$res2 = db_query($sql2);
|
| 57 |
$res3 = db_query($sql3);
|
| 58 |
if($res1 && $res2 && $res3) {
|
| 59 |
drupal_set_message(t('The Sphinx module is now installed!'));
|
| 60 |
} else {
|
| 61 |
drupal_set_message(t('Installation errror'),'error');
|
| 62 |
}
|
| 63 |
break;
|
| 64 |
|
| 65 |
case 'pgsql':
|
| 66 |
drupal_set_message(t('No pg support at the moment'),'error' );
|
| 67 |
break;
|
| 68 |
}
|
| 69 |
}
|
| 70 |
|
| 71 |
|
| 72 |
/**
|
| 73 |
* Implementation of hook_uninstall().
|
| 74 |
*/
|
| 75 |
function sphinx_uninstall() {
|
| 76 |
drupal_set_message(t("The Sphinx module is now uninstalled!"));
|
| 77 |
}
|
| 78 |
|
| 79 |
/**
|
| 80 |
* Implementation of hook_requirements().
|
| 81 |
*/
|
| 82 |
function sphinx_requirements($phase) {
|
| 83 |
$t = get_t();
|
| 84 |
$path = './'. drupal_get_path('module', 'sphinx') ."/includes/api";
|
| 85 |
$api_file = $path ."/sphinxapi.php";
|
| 86 |
if (file_exists($api_file)) {
|
| 87 |
include_once ($api_file);
|
| 88 |
}
|
| 89 |
$api_exists = class_exists('SphinxClient');
|
| 90 |
$requirements['sphinx_api'] = array(
|
| 91 |
'title' => $t('Sphinx api'),
|
| 92 |
'value' => $api_exists ? 'Sphinx api installed correctly' : "Sphinx api NOT installed correctly! Download Sphinx (http://www.sphinxsearch.com/downloads.html) and find the file sphinxapi.php and place it in ". $path,
|
| 93 |
'severity' => $api_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
|
| 94 |
);
|
| 95 |
if ($api_exists) {
|
| 96 |
$cl = new SphinxClient();
|
| 97 |
$connect = $cl->_Connect();
|
| 98 |
$requirements['sphinx_daemon'] = array(
|
| 99 |
'title' => $t('Sphinx daemon'),
|
| 100 |
'value' => $connect ? 'Sphinx daemon running and connected' : 'Sphinx daemon NOT running',
|
| 101 |
'severity' => $connect ? REQUIREMENT_OK : REQUIREMENT_ERROR,
|
| 102 |
);
|
| 103 |
}
|
| 104 |
return $requirements;
|
| 105 |
}
|
| 106 |
|