From e38c8db4f7739f6c363adeba178bf81906a06b01 Mon Sep 17 00:00:00 2001
From: Chris Gross <gross.364@osu.edu>
Date: Wed, 3 Jun 2015 13:10:46 -0400
Subject: [PATCH] daily build

---
 .../custom/ocio_search/ocio_search.install    |  8 +++---
 .../custom/ocio_search/ocio_search.module     | 26 +++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/profiles/wcm_base/modules/custom/ocio_search/ocio_search.install b/profiles/wcm_base/modules/custom/ocio_search/ocio_search.install
index 71ef4a68..b36bad34 100644
--- a/profiles/wcm_base/modules/custom/ocio_search/ocio_search.install
+++ b/profiles/wcm_base/modules/custom/ocio_search/ocio_search.install
@@ -4,10 +4,10 @@
  * Implements hook_install().
  */
 function ocio_search_install() {
-  // Post Pantheon Apache Solr schema
+  // Post Pantheon Apache Solr schema and set variable.
   if (function_exists('pantheon_apachesolr_post_schema_exec')) {
-    $schema = drupal_get_path('module', 'apachesolr') . '/solr-conf/solr-3.x/schema.xml';
-    variable_set('pantheon_apachesolr_schema', $schema);
-    pantheon_apachesolr_post_schema_exec($schema);
+    $post = ocio_search_solr_post_schema();
+    $posted = array('dev' => !empty($post));
+    variable_set('pantheon_schema_posted', $posted);
   }
 }
diff --git a/profiles/wcm_base/modules/custom/ocio_search/ocio_search.module b/profiles/wcm_base/modules/custom/ocio_search/ocio_search.module
index cfcd8cc8..9f47b9a7 100644
--- a/profiles/wcm_base/modules/custom/ocio_search/ocio_search.module
+++ b/profiles/wcm_base/modules/custom/ocio_search/ocio_search.module
@@ -5,3 +5,29 @@
  */
 
 include_once 'ocio_search.features.inc';
+
+/*
+ * Implements hook_cron().
+ */
+function ocio_search_cron() {
+  $env = variable_get('pantheon_environment', 'dev');
+  $posted = variable_get('pantheon_schema_posted');
+
+  // If Solr schema has not been posted in the current environment,
+  // 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')) {
+    $post = ocio_search_solr_post_schema();
+
+    $posted[$env] = !empty($post);
+    variable_set('pantheon_schema_posted', $posted);
+    watchdog('ocio_search', 'ApacheSolr schema posted');
+  }
+}
+
+/*
+ * Posts Solr schema and returns schema status.
+ */
+function ocio_search_solr_post_schema() {
+  $schema = drupal_get_path('module', 'apachesolr') . '/solr-conf/solr-3.x/schema.xml';
+  return pantheon_apachesolr_post_schema_exec($schema);
+}
-- 
GitLab