| 1 |
<?php
|
| 2 |
// $Id: apachesolr.install,v 1.1.4.17 2009/05/12 21:20:34 pwolanin Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Install and related hooks for apachesolr_search.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function apachesolr_install() {
|
| 13 |
// Create tables.
|
| 14 |
drupal_install_schema('apachesolr');
|
| 15 |
// Create one MLT block.
|
| 16 |
require_once(drupal_get_path('module', 'apachesolr') .'/apachesolr.admin.inc');
|
| 17 |
apachesolr_mlt_save_block(array('name' => t('More like this')));
|
| 18 |
|
| 19 |
drupal_set_message(t('Search is enabled. You\'re site is <a href="!index_settings_link">currently 0% indexed</a>.', array('!index_settings_link' => url('admin/settings/apachesolr/index'))));
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_enable().
|
| 24 |
*/
|
| 25 |
function apachesolr_enable() {
|
| 26 |
// Make sure we don't have stale data.
|
| 27 |
variable_del('apachesolr_index_last');
|
| 28 |
db_query("DELETE FROM {apachesolr_search_node}");
|
| 29 |
// Populate table
|
| 30 |
db_query("INSERT INTO {apachesolr_search_node} (nid, status, changed)
|
| 31 |
SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed
|
| 32 |
FROM {node} n
|
| 33 |
INNER JOIN {node_comment_statistics} c ON n.nid = c.nid");
|
| 34 |
// Make sure no nodes end up with a timestamp that's in the future.
|
| 35 |
$time = time();
|
| 36 |
db_query("UPDATE {apachesolr_search_node} SET changed = %d WHERE changed > %d", $time, $time);
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Implementation of hook_schema().
|
| 41 |
*
|
| 42 |
* TODO: move all node indexing/seach code to apachesolr_search
|
| 43 |
*/
|
| 44 |
function apachesolr_schema() {
|
| 45 |
$schema['apachesolr_search_node'] = array(
|
| 46 |
'description' => t('Stores a record of when a node property changed to determine if it needs indexing by Solr.'),
|
| 47 |
'fields' => array(
|
| 48 |
'nid' => array(
|
| 49 |
'description' => t('The primary identifier for a node.'),
|
| 50 |
'type' => 'int',
|
| 51 |
'unsigned' => TRUE,
|
| 52 |
'not null' => TRUE),
|
| 53 |
'status' => array(
|
| 54 |
'description' => t('Boolean indicating whether the node is published (visible to non-administrators).'),
|
| 55 |
'type' => 'int',
|
| 56 |
'not null' => TRUE,
|
| 57 |
'default' => 1),
|
| 58 |
'changed' => array(
|
| 59 |
'description' => t('The Unix timestamp when a node property was changed.'),
|
| 60 |
'type' => 'int',
|
| 61 |
'not null' => TRUE,
|
| 62 |
'default' => 0),
|
| 63 |
),
|
| 64 |
'indexes' => array(
|
| 65 |
'changed' => array('changed', 'status'),
|
| 66 |
),
|
| 67 |
'primary key' => array('nid'),
|
| 68 |
);
|
| 69 |
|
| 70 |
return $schema;
|
| 71 |
}
|
| 72 |
|
| 73 |
/**
|
| 74 |
* Implementation of hook_uninstall()
|
| 75 |
*/
|
| 76 |
function apachesolr_uninstall() {
|
| 77 |
variable_del('apachesolr_host');
|
| 78 |
variable_del('apachesolr_port');
|
| 79 |
variable_del('apachesolr_path');
|
| 80 |
variable_del('apachesolr_rows');
|
| 81 |
variable_del('apachesolr_facet_query_limits');
|
| 82 |
variable_del('apachesolr_facet_query_limit_default');
|
| 83 |
variable_del('apachesolr_site_hash');
|
| 84 |
variable_del('apachesolr_index_last');
|
| 85 |
variable_del('apachesolr_mlt_blocks');
|
| 86 |
variable_del('apachesolr_cron_limit');
|
| 87 |
variable_del('apachesolr_enabled_facets');
|
| 88 |
// Remove tables.
|
| 89 |
drupal_uninstall_schema('apachesolr');
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Create node indexing table.
|
| 94 |
*/
|
| 95 |
function apachesolr_update_6000() {
|
| 96 |
// Create table.
|
| 97 |
$ret = array();
|
| 98 |
$schema['apachesolr_search_node'] = array(
|
| 99 |
'description' => t('Stores a record of when a node property changed to determine if it needs indexing by Solr.'),
|
| 100 |
'fields' => array(
|
| 101 |
'nid' => array(
|
| 102 |
'description' => t('The primary identifier for a node.'),
|
| 103 |
'type' => 'int',
|
| 104 |
'unsigned' => TRUE,
|
| 105 |
'not null' => TRUE),
|
| 106 |
'status' => array(
|
| 107 |
'description' => t('Boolean indicating whether the node is published (visible to non-administrators).'),
|
| 108 |
'type' => 'int',
|
| 109 |
'not null' => TRUE,
|
| 110 |
'default' => 1),
|
| 111 |
'changed' => array(
|
| 112 |
'description' => t('The Unix timestamp when a node property was changed.'),
|
| 113 |
'type' => 'int',
|
| 114 |
'not null' => TRUE,
|
| 115 |
'default' => 0),
|
| 116 |
),
|
| 117 |
'indexes' => array(
|
| 118 |
'changed' => array('changed', 'status'),
|
| 119 |
),
|
| 120 |
'primary key' => array('nid'),
|
| 121 |
);
|
| 122 |
db_create_table($ret, 'apachesolr_search_node', $schema['apachesolr_search_node']);
|
| 123 |
// Populate table
|
| 124 |
$ret[] = update_sql("INSERT INTO {apachesolr_search_node} (nid, status, changed)
|
| 125 |
SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed
|
| 126 |
FROM {node} n LEFT JOIN {apachesolr_search_node} asn ON n.nid = asn.nid
|
| 127 |
LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid
|
| 128 |
WHERE asn.changed IS NULL");
|
| 129 |
|
| 130 |
return $ret;
|
| 131 |
}
|
| 132 |
|
| 133 |
/**
|
| 134 |
* Fix block caching settings.
|
| 135 |
*
|
| 136 |
* Work-around for core bug: http://drupal.org/node/235673
|
| 137 |
*/
|
| 138 |
function apachesolr_update_6001() {
|
| 139 |
$ret = array();
|
| 140 |
|
| 141 |
$ret[] = update_sql("UPDATE {blocks} set cache = " . BLOCK_CACHE_PER_PAGE . " WHERE module LIKE 'apachesolr%'");
|
| 142 |
|
| 143 |
return $ret;
|
| 144 |
}
|
| 145 |
|
| 146 |
/**
|
| 147 |
* Make sure no nodes have a timestamp that's in the future
|
| 148 |
*/
|
| 149 |
function apachesolr_update_6002() {
|
| 150 |
$ret = array();
|
| 151 |
// Make sure no nodes end up with a timestamp that's in the future.
|
| 152 |
$time = (int) time();
|
| 153 |
$ret[] = update_sql("UPDATE {apachesolr_search_node} SET changed = $time WHERE changed > $time");
|
| 154 |
|
| 155 |
return $ret;
|
| 156 |
}
|
| 157 |
|
| 158 |
/**
|
| 159 |
* Re-index nodes in books.
|
| 160 |
*/
|
| 161 |
function apachesolr_update_6003() {
|
| 162 |
$ret = array();
|
| 163 |
if (module_exists('book')) {
|
| 164 |
$time = (int) time();
|
| 165 |
$ret[] = update_sql("UPDATE {apachesolr_search_node} SET changed = $time WHERE nid IN (SELECT nid from {book})");
|
| 166 |
}
|
| 167 |
return $ret;
|
| 168 |
}
|
| 169 |
|
| 170 |
/**
|
| 171 |
* Subsume MLT functionality..
|
| 172 |
*/
|
| 173 |
function apachesolr_update_6004() {
|
| 174 |
$ret = array();
|
| 175 |
if (db_table_exists("{apachesolr_mlt}")) {
|
| 176 |
require_once(drupal_get_path('module', 'apachesolr') .'/apachesolr.admin.inc');
|
| 177 |
$result = db_query('SELECT id, data FROM {apachesolr_mlt} ORDER BY id ASC');
|
| 178 |
while ($row = db_fetch_array($result)) {
|
| 179 |
$delta = sprintf('mlt-%03d', $row['id']);
|
| 180 |
apachesolr_mlt_save_block(unserialize($row['data']), $delta);
|
| 181 |
$ret[] = update_sql("UPDATE {blocks} SET module = 'apachesolr', delta = '". $delta ."' WHERE module = 'apachesolr_mlt' AND delta ='". $row['id'] ."'");
|
| 182 |
}
|
| 183 |
$ret[] = update_sql("DROP TABLE {apachesolr_mlt}");
|
| 184 |
}
|
| 185 |
$ret[] = update_sql("DELETE FROM {system} WHERE name = 'apachesolr_mlt'");
|
| 186 |
return $ret;
|
| 187 |
}
|