Mercurial > hg > MPIWG-drupal-modules
comparison sites/all/modules/custom/solrsearch/solrsearch_search.install @ 0:015d06b10d37 default tip
initial
| author | dwinter |
|---|---|
| date | Wed, 31 Jul 2013 13:49:13 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:015d06b10d37 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 /** | |
| 4 * @file | |
| 5 * Install and related hooks for solrsearch_search. | |
| 6 */ | |
| 7 | |
| 8 /** | |
| 9 * Implements hook_install(). | |
| 10 */ | |
| 11 function solrsearch_search_install() { | |
| 12 // Add a taxonomy search page to the database | |
| 13 $settings = array( | |
| 14 'solrsearch_search_search_type' => 'tid', | |
| 15 'solrsearch_search_per_page' => 10, | |
| 16 'solrsearch_search_browse' => 'results', | |
| 17 'solrsearch_search_spellcheck' => FALSE, | |
| 18 'solrsearch_search_search_box' => FALSE, | |
| 19 ); | |
| 20 $settings = serialize($settings); | |
| 21 | |
| 22 $fields = array( | |
| 23 'page_id' => 'taxonomy_search', | |
| 24 'label' => 'Taxonomy Search', | |
| 25 'description' => 'Search all items with given term', | |
| 26 'search_path' => 'taxonomy/term/%', | |
| 27 'env_id' => '', | |
| 28 'page_title' => '%value', | |
| 29 'settings' => $settings, | |
| 30 ); | |
| 31 db_insert('solrsearch_search_page')->fields($fields)->execute(); | |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * Implements hook_enable(). | |
| 36 */ | |
| 37 function solrsearch_search_enable() { | |
| 38 // Make sure the default core search page is installed. | |
| 39 //dpm("ENABLE"); | |
| 40 $search_page = solrsearch_search_page_load('core_solr_search'); | |
| 41 //dpm($search_page); | |
| 42 if (empty($search_page)) { | |
| 43 // Add Default search page (core search) | |
| 44 // This is a duplication from update_7004 but it is intended | |
| 45 // so future changes are possible without breaking the update | |
| 46 $settings = array( | |
| 47 'solrsearch_search_search_type' => 'custom', | |
| 48 'solrsearch_search_per_page' => 10, | |
| 49 'solrsearch_search_browse' => 'browse', | |
| 50 'solrsearch_search_spellcheck' => TRUE, | |
| 51 'solrsearch_search_not_removable' => TRUE, | |
| 52 'solrsearch_search_search_box' => TRUE, | |
| 53 ); | |
| 54 $settings = serialize($settings); | |
| 55 | |
| 56 $fields = array( | |
| 57 'page_id' => 'core_solr_search', | |
| 58 'label' => 'Core Solr Search', | |
| 59 'description' => 'Core SolrSearch', | |
| 60 'search_path' => 'solrsearch/site', | |
| 61 'env_id' => 'searchecho', | |
| 62 'page_title' => 'echo', | |
| 63 'settings' => $settings, | |
| 64 ); | |
| 65 db_insert('solrsearch_search_page')->fields($fields)->execute(); | |
| 66 } | |
| 67 | |
| 68 | |
| 69 #$active = variable_get('search_active_modules', array('node', 'user')); | |
| 70 #$active[] = 'solrsearch_search'; | |
| 71 #variable_set('search_active_modules', array_unique($active)); | |
| 72 } | |
| 73 | |
| 74 /** | |
| 75 * Implements hook_schema(). | |
| 76 */ | |
| 77 function solrsearch_search_schema() { | |
| 78 $schema = array(); | |
| 79 | |
| 80 $schema['solrsearch_search_page'] = array( | |
| 81 'description' => 'Apache Solr Search search page settings.', | |
| 82 'export' => array( | |
| 83 // Environment machine name. | |
| 84 'key' => 'page_id', | |
| 85 // Description of key. | |
| 86 'key name' => 'search page machine name', | |
| 87 // Variable name to use in exported code. | |
| 88 'identifier' => 'searcher', | |
| 89 // Use the same hook as the API name below. | |
| 90 'default hook' => 'solrsearch_search_default_searchers', | |
| 91 'status' => 'solrsearch_search_page_status', | |
| 92 // CTools API implementation. | |
| 93 'api' => array( | |
| 94 'owner' => 'solrsearch_search', | |
| 95 'api' => 'solrsearch_search_defaults', | |
| 96 'minimum_version' => 3, | |
| 97 'current_version' => 3, | |
| 98 ), | |
| 99 // Includes all search page specific configurations. | |
| 100 'export callback' => 'solrsearch_search_page_settings_export', | |
| 101 ), | |
| 102 'fields' => array( | |
| 103 'page_id' => array( | |
| 104 'description' => 'The machine readable name of the search page.', | |
| 105 'type' => 'varchar', | |
| 106 'length' => 32, | |
| 107 'not null' => TRUE, | |
| 108 'default' => '', | |
| 109 ), | |
| 110 'label' => array( | |
| 111 'description' => 'The human readable name of the search page.', | |
| 112 'type' => 'varchar', | |
| 113 'length' => 32, | |
| 114 'not null' => TRUE, | |
| 115 'default' => '', | |
| 116 ), | |
| 117 'description' => array( | |
| 118 'description' => 'The description of the search page.', | |
| 119 'type' => 'varchar', | |
| 120 'length' => 255, | |
| 121 'not null' => TRUE, | |
| 122 'default' => '', | |
| 123 ), | |
| 124 'search_path' => array( | |
| 125 'description' => 'The path to the search page.', | |
| 126 'type' => 'varchar', | |
| 127 'length' => 255, | |
| 128 'not null' => TRUE, | |
| 129 'default' => '', | |
| 130 ), | |
| 131 'page_title' => array( | |
| 132 'description' => 'The title of the search page.', | |
| 133 'type' => 'varchar', | |
| 134 'length' => 255, | |
| 135 'not null' => TRUE, | |
| 136 'default' => '', | |
| 137 ), | |
| 138 'env_id' => array( | |
| 139 'description' => 'The machine name of the search environment.', | |
| 140 'type' => 'varchar', | |
| 141 'length' => 64, | |
| 142 'not null' => TRUE, | |
| 143 'default' => '', | |
| 144 ), | |
| 145 'settings' => array( | |
| 146 'description' => 'Serialized storage of general settings.', | |
| 147 'type' => 'text', | |
| 148 'serialize' => TRUE, | |
| 149 ), | |
| 150 ), | |
| 151 'primary key' => array('page_id'), | |
| 152 'indexes' => array( | |
| 153 'env_id' => array('env_id'), | |
| 154 ), | |
| 155 ); | |
| 156 | |
| 157 return $schema; | |
| 158 } | |
| 159 | |
| 160 /** | |
| 161 * Implements hook_uninstall(). | |
| 162 */ | |
| 163 function solrsearch_search_uninstall() { | |
| 164 $stored = variable_get('solrsearch_index_last', array()); | |
| 165 unset($stored['solrsearch_search']); | |
| 166 variable_set('solrsearch_index_last', $stored); | |
| 167 | |
| 168 $active = variable_get('search_active_modules', array('node', 'user')); | |
| 169 $idx = array_search('solrsearch_search', $active); | |
| 170 if ($idx !== FALSE) { | |
| 171 unset($active[$idx]); | |
| 172 variable_set('search_active_modules', $active); | |
| 173 } | |
| 174 // Remove variables. | |
| 175 variable_del('solrsearch_search_spellcheck'); | |
| 176 variable_del('solrsearch_search_mlt_blocks'); | |
| 177 variable_del('solrsearch_search_default_search_page'); | |
| 178 // Remove blocks. | |
| 179 db_delete('block')->condition('module', 'solrsearch_search')->execute(); | |
| 180 } | |
| 181 | |
| 182 /** | |
| 183 * Various updates for Drupal 7. | |
| 184 */ | |
| 185 function solrsearch_search_update_7000() { | |
| 186 $taxo_links = variable_get('solrsearch_search_taxonomy_links', 0); | |
| 187 // TODO - enable the new contrib module? | |
| 188 variable_del('solrsearch_search_taxonomy_links'); | |
| 189 // TODO - possibly rename block deltas, etc. | |
| 190 $active = variable_get('search_active_modules', array('node', 'user')); | |
| 191 $active[] = 'solrsearch_search'; | |
| 192 variable_set('search_active_modules', array_unique($active)); | |
| 193 if (variable_get('solrsearch_search_make_default', 0)) { | |
| 194 variable_set('search_default_module', 'solrsearch_search'); | |
| 195 } | |
| 196 variable_del('solrsearch_search_make_default'); | |
| 197 } | |
| 198 | |
| 199 /** | |
| 200 * Add solrsearch_search_page table. | |
| 201 */ | |
| 202 function solrsearch_search_update_7001() { | |
| 203 // Moved to 7002 | |
| 204 } | |
| 205 | |
| 206 /** | |
| 207 * Add solrsearch_search_page table for real. | |
| 208 */ | |
| 209 function solrsearch_search_update_7002() { | |
| 210 | |
| 211 $schema['solrsearch_search_page'] = array( | |
| 212 'description' => 'Apache Solr Search search page settings.', | |
| 213 'export' => array( | |
| 214 'key' => 'page_id', | |
| 215 'identifier' => 'searcher', | |
| 216 'default hook' => 'solrsearch_search_default_searchers', | |
| 217 'status' => 'solrsearch_search_page_status', | |
| 218 'api' => array( | |
| 219 'owner' => 'solrsearch_search', | |
| 220 'api' => 'solrsearch_search_defaults', | |
| 221 'minimum_version' => 3, | |
| 222 'current_version' => 3, | |
| 223 ), | |
| 224 'export callback' => 'solrsearch_search_page_settings_export', | |
| 225 ), | |
| 226 'fields' => array( | |
| 227 'page_id' => array( | |
| 228 'description' => 'The machine readable name of the search page.', | |
| 229 'type' => 'varchar', | |
| 230 'length' => 32, | |
| 231 'not null' => TRUE, | |
| 232 'default' => '', | |
| 233 ), | |
| 234 'label' => array( | |
| 235 'description' => 'The human readable name of the search page.', | |
| 236 'type' => 'varchar', | |
| 237 'length' => 32, | |
| 238 'not null' => TRUE, | |
| 239 'default' => '', | |
| 240 ), | |
| 241 'description' => array( | |
| 242 'description' => 'The description of the search page.', | |
| 243 'type' => 'varchar', | |
| 244 'length' => 255, | |
| 245 'not null' => TRUE, | |
| 246 'default' => '', | |
| 247 ), | |
| 248 'search_path' => array( | |
| 249 'description' => 'The path to the search page.', | |
| 250 'type' => 'varchar', | |
| 251 'length' => 255, | |
| 252 'not null' => TRUE, | |
| 253 'default' => '', | |
| 254 ), | |
| 255 'page_title' => array( | |
| 256 'description' => 'The title of the search page.', | |
| 257 'type' => 'varchar', | |
| 258 'length' => 255, | |
| 259 'not null' => TRUE, | |
| 260 'default' => '', | |
| 261 ), | |
| 262 'env_id' => array( | |
| 263 'description' => 'The machine name of the search environment.', | |
| 264 'type' => 'varchar', | |
| 265 'length' => 32, | |
| 266 'not null' => TRUE, | |
| 267 'default' => '', | |
| 268 ), | |
| 269 'settings' => array( | |
| 270 'description' => 'Serialized storage of general settings.', | |
| 271 'type' => 'text', | |
| 272 'serialize' => TRUE, | |
| 273 ), | |
| 274 ), | |
| 275 'primary key' => array('page_id'), | |
| 276 'indexes' => array( | |
| 277 'env_id' => array('env_id'), | |
| 278 ), | |
| 279 ); | |
| 280 if (db_table_exists('solrsearch_search_page')) { | |
| 281 // Just in case you are chasing HEAD. | |
| 282 db_drop_table('solrsearch_search_page'); | |
| 283 } | |
| 284 db_create_table('solrsearch_search_page', $schema['solrsearch_search_page']); | |
| 285 } | |
| 286 | |
| 287 | |
| 288 /** | |
| 289 * Delete all Apache Solr Search blocks - they moved to Facet API. | |
| 290 */ | |
| 291 function solrsearch_search_update_7003() { | |
| 292 // Remove blocks. | |
| 293 db_delete('block')->condition('module', 'solrsearch_search')->execute(); | |
| 294 } | |
| 295 | |
| 296 /** | |
| 297 * Add a default search page for core | |
| 298 * Add a taxonomy page if the taxonomy module was ever active | |
| 299 */ | |
| 300 function solrsearch_search_update_7004() { | |
| 301 // Add Default search page (core search) | |
| 302 $settings = array( | |
| 303 'solrsearch_search_search_type' => 'custom', | |
| 304 'solrsearch_search_per_page' => variable_get('solrsearch_rows', 10), | |
| 305 'solrsearch_search_browse' => variable_get('solrsearch_search_browse', 'browse'), | |
| 306 'solrsearch_search_spellcheck' => variable_get('solrsearch_search_spellcheck', TRUE), | |
| 307 'solrsearch_search_not_removable' => TRUE, | |
| 308 'solrsearch_search_search_box' => TRUE, | |
| 309 ); | |
| 310 $settings = serialize($settings); | |
| 311 | |
| 312 $fields = array( | |
| 313 | |
| 314 'page_id' => 'core_solr_search', | |
| 315 'label' => 'Core Solr Search', | |
| 316 'description' => 'Core SolrSearch', | |
| 317 'search_path' => 'solrsearch/site', | |
| 318 'env_id' => 'searchecho', | |
| 319 'page_title' => 'echo', | |
| 320 'settings' => $settings, | |
| 321 ); | |
| 322 db_insert('solrsearch_search_page')->fields($fields)->execute(); | |
| 323 // Remove variables. | |
| 324 variable_del('solrsearch_search_spellcheck'); | |
| 325 variable_del('solrsearch_search_browse'); | |
| 326 | |
| 327 // Add this taxonomy search page to the database | |
| 328 $settings = array( | |
| 329 'solrsearch_search_search_type' => 'tid', | |
| 330 'solrsearch_search_per_page' => 10, | |
| 331 'solrsearch_search_browse' => 'results', | |
| 332 'solrsearch_search_spellcheck' => FALSE, | |
| 333 'solrsearch_search_search_box' => FALSE, | |
| 334 ); | |
| 335 $settings = serialize($settings); | |
| 336 | |
| 337 $fields = array( | |
| 338 'page_id' => 'taxonomy_search', | |
| 339 'label' => 'Taxonomy Search', | |
| 340 'description' => 'Search all items with given term', | |
| 341 'search_path' => 'taxonomy/term/%', | |
| 342 'env_id' => '', | |
| 343 'page_title' => '%value', | |
| 344 'settings' => $settings, | |
| 345 ); | |
| 346 db_insert('solrsearch_search_page')->fields($fields)->execute(); | |
| 347 | |
| 348 // Check if the taxonomy module was ever present | |
| 349 $status = db_query("SELECT 1 FROM {system} WHERE name = 'solrsearch_taxonomy'")->fetchField(); | |
| 350 if ($status) { | |
| 351 $message = t('If you had the solrsearch_taxonomy module enabled please go to the !link and enable the Taxonomy Term page', array('!link' => l('Apache Solr custom pages', 'admin/config/search/solrsearch/search-pages'))); | |
| 352 drupal_set_message($message, 'warning'); | |
| 353 } | |
| 354 } | |
| 355 | |
| 356 /** | |
| 357 * Make the env_id length on the solrsearch_search_page table 64 characters | |
| 358 * to match the length of the env_id on all other tables | |
| 359 */ | |
| 360 function solrsearch_search_update_7005(&$sandbox) { | |
| 361 db_drop_index('solrsearch_search_page', 'env_id'); | |
| 362 db_change_field('solrsearch_search_page', 'env_id', 'env_id', | |
| 363 array( | |
| 364 'description' => 'The machine name of the search environment.', | |
| 365 'type' => 'varchar', | |
| 366 'length' => 64, | |
| 367 'not null' => TRUE, | |
| 368 'default' => '', | |
| 369 ), | |
| 370 array( | |
| 371 'indexes' => array( | |
| 372 'env_id' => array('env_id'), | |
| 373 ) | |
| 374 ) | |
| 375 ); | |
| 376 } | |
| 377 | |
| 378 /** | |
| 379 * Remove all solrsearch_search env variables for show_facets if it is zero | |
| 380 */ | |
| 381 function solrsearch_search_update_7006() { | |
| 382 module_load_include('module', 'solrsearch'); | |
| 383 $environments = solrsearch_load_all_environments(); | |
| 384 foreach ($environments as $environment) { | |
| 385 $show_facets = solrsearch_environment_variable_get($environment['env_id'], 'solrsearch_search_show_facets', 0); | |
| 386 if ($show_facets === 0) { | |
| 387 solrsearch_environment_variable_del($environment['env_id'], 'solrsearch_search_show_facets'); | |
| 388 } | |
| 389 } | |
| 390 } |
