Check for table before trying to get data
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Aug 2016 17:49:48 +0000 (13:49 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Aug 2016 17:49:48 +0000 (13:49 -0400)
Should be checking for the table to exists before getting data from it.

activate.php

index 5d1ed58..d460936 100644 (file)
@@ -31,7 +31,6 @@ if (!defined('ABSPATH')) {
     die("Please do not call this code directly!");
 }
 
-require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataFeedImport.php';
 /*
  * This class performs all necessary additional work when this
  * plugin is activated.
@@ -90,12 +89,22 @@ class glmMembersEventsPluginActivate
 
     public function create_cron_schedules()
     {
-        $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config );
-        $import_feeds = $importFeeds->getList();
-        if ( $import_feeds ) {
-            foreach ( $import_feeds as $key => &$feed ) {
-                // check the next run time
-                wp_schedule_event( time(), GLM_MEMBERS_EVENTS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( (int)$feed['id'] ) );
+        // See if tables exists first
+        $result = $this->wpdb->get_results(
+            $this->wpdb->prepare(
+                "SHOW TABLES LIKE %s",
+                GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'feed_import'
+            )
+        );
+        if ( $result ) {
+            require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataFeedImport.php';
+            $importFeeds = new GlmDataFeedImport( $this->wpdb, $this->config );
+            $import_feeds = $importFeeds->getList();
+            if ( $import_feeds ) {
+                foreach ( $import_feeds as $key => &$feed ) {
+                    // check the next run time
+                    wp_schedule_event( time(), GLM_MEMBERS_EVENTS_PLUGIN_CRON_RECURRANCE, GLM_MEMBERS_EVENTS_PLUGIN_CRON_EVENT, array( (int)$feed['id'] ) );
+                }
             }
         }
     }