Skip to content
Snippets Groups Projects
Commit 81f1e501 authored by Chris Gross's avatar Chris Gross
Browse files

auto-post solr schema on older sites

parent 2d0b44a5
No related branches found
No related tags found
No related merge requests found
<?php <?php
/* /**
* Implements hook_install(). * Implements hook_install().
*/ */
function ocio_search_install() { function ocio_search_install() {
// Post Pantheon Apache Solr schema and set variable. // Post Pantheon Apache Solr schema and set variable.
if (function_exists('pantheon_apachesolr_post_schema_exec')) { $posted = array(
$post = ocio_search_solr_post_schema(); 'dev' => FALSE,
$posted = array( 'test' => FALSE,
'dev' => !empty($post), 'live' => FALSE
'test' => FALSE, );
'live' => FALSE ocio_search_solr_post_schema($posted);
);
variable_set('pantheon_schema_posted', $posted);
}
} }
...@@ -10,26 +10,41 @@ include_once 'ocio_search.features.inc'; ...@@ -10,26 +10,41 @@ include_once 'ocio_search.features.inc';
* Implements hook_cron(). * Implements hook_cron().
*/ */
function ocio_search_cron() { function ocio_search_cron() {
$env = variable_get('pantheon_environment', 'dev'); $env = variable_get('pantheon_environment');
$posted = variable_get('pantheon_schema_posted'); $posted = variable_get('pantheon_schema_posted');
if (empty($posted) || !isset($posted[$env])) {
$posted[$env] = FALSE;
}
// If Solr schema has not been posted in the current environment, // If Solr schema has not been posted in the current environment,
// post schema and set variable to prevent posting on each cron run. // post schema and set variable to prevent posting on each cron run.
if (isset($posted[$env]) && !$posted[$env] && function_exists('pantheon_apachesolr_post_schema_exec')) { if (!$posted[$env]) {
$post = ocio_search_solr_post_schema(); ocio_search_solr_post_schema($posted, $env);
$posted[$env] = !empty($post);
variable_set('pantheon_schema_posted', $posted);
watchdog('ocio_search', 'ApacheSolr schema posted');
} }
} }
/** /**
* Posts Solr schema and returns schema status. * Posts Solr schema and returns schema status.
*/ */
function ocio_search_solr_post_schema() { function ocio_search_solr_post_schema($posted, $env = '') {
$schema = drupal_get_path('module', 'apachesolr') . '/solr-conf/solr-3.x/schema.xml';
return pantheon_apachesolr_post_schema_exec($schema); if (function_exists('pantheon_apachesolr_post_schema_exec')) {
$schema = drupal_get_path('module', 'apachesolr') . '/solr-conf/solr-3.x/schema.xml';
$post = pantheon_apachesolr_post_schema_exec($schema);
$result = !empty($post);
if ($result) {
watchdog('ocio_search', 'ApacheSolr schema posted');
}
if (empty($env)) {
$env = variable_get('pantheon_environment');
}
$posted[$env] = $result;
variable_set('pantheon_schema_posted', $posted);
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment