From 648b0627de2b2dd91ae2da032b9c2e7f362ead05 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 18 Jul 2018 11:20:45 -0400 Subject: [PATCH] Updating the connections import Using Chuck's script. Fixing some issues and setting up per member process to 25. --- classes/glmMemberImportFromConnections.php | 501 +++++++++++---------- models/admin/management/development.php | 138 +++--- 2 files changed, 328 insertions(+), 311 deletions(-) diff --git a/classes/glmMemberImportFromConnections.php b/classes/glmMemberImportFromConnections.php index eb118714..086ef4ec 100644 --- a/classes/glmMemberImportFromConnections.php +++ b/classes/glmMemberImportFromConnections.php @@ -14,6 +14,8 @@ * @link http://dev.gaslightmedia.com/ */ +require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/imageUpload.php'; + /* * This class imports all data from the Connection Business Directory Plugin. * @@ -35,6 +37,8 @@ class GlmMemberImportFromConnections */ public $config; + const PROCESS_COUNT = 25; + /** * Constructor @@ -56,7 +60,7 @@ class GlmMemberImportFromConnections } - /* + /** * Check if Connections plugin is installed and active * * @return boolean @@ -86,21 +90,23 @@ class GlmMemberImportFromConnections } - /* + /** * Get list of base entries * * @return array * @access public */ - public function getList() + public function getList( $start = 0, $all = false ) { - - // Get6 List + // Get List $sql = " - SELECT * - FROM ".$this->wpdb->prefix."connections - ;"; + SELECT * + FROM ".$this->wpdb->prefix."connections + ORDER BY id"; + if ( !$all ) { + $sql .= " LIMIT " . self::PROCESS_COUNT . " OFFSET $start"; + } $list = $this->wpdb->get_results($sql, ARRAY_A); $queryError = $this->wpdb->last_error; @@ -125,7 +131,7 @@ class GlmMemberImportFromConnections // Social Meida $a = unserialize($v['social']); - $list[$k]['social_media'] = $a; + $list[$k]['social'] = $a; // Links $a = unserialize($v['links']); @@ -145,7 +151,7 @@ class GlmMemberImportFromConnections } - /* + /** * Import all members not marked as "Skip" * * Looks at "skip" POST parameter (array) for ID's that should be skipped. @@ -153,59 +159,52 @@ class GlmMemberImportFromConnections * @return boolean * @access public */ - public function doImport() + public function doImport( $start = 0 ) { + $ImageUpload = new GlmMembersAdmin_ajax_imageUpload( $this->wpdb, $this->config ); - $list = $this->getList(); + $list = $this->getList( $start ); - /* - * Create default member type - */ - $memberTypeName = sanitize_text_field($_REQUEST['memberType']); - $sql = " - INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_type - ( - name, - descr - ) - VALUES - ( - '".addslashes($memberTypeName)."', - '' - ) - ;"; - $this->wpdb->query($sql); - $membTypeID = $this->wpdb->insert_id; - $queryError = $this->wpdb->last_error; - if ($queryError) { - return false; - } + // If the import is just starting + // Don't do this if start is not 0 + if ( $start === 0 ) { - /* - * Create default region - */ - $regionName = sanitize_text_field($_REQUEST['region']); - $sql = " - INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."regions - ( - name, - descr, - short_descr - ) - VALUES - ( - '".addslashes($memberTypeName)."', - '', - '' - ) - ;"; - $this->wpdb->query($sql); - $regionID = $this->wpdb->insert_id; - $queryError = $this->wpdb->last_error; - if ($queryError) { - return false; - } + /* + * Create default member type + */ + $memberTypeName = sanitize_text_field( $_REQUEST['memberType'] ); + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_type + ( name, descr) + VALUES + ( '".addslashes($memberTypeName)."', '')"; + $this->wpdb->query($sql); + $membTypeID = $this->wpdb->insert_id; + $queryError = $this->wpdb->last_error; + if ($queryError) { + return false; + } + /* + * Create default region + */ + $regionName = sanitize_text_field( $_REQUEST['region'] ); + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."regions + ( name, descr, short_descr) + VALUES + ( '".addslashes( $regionName )."', '', '')"; + $this->wpdb->query( $sql ); + $regionID = $this->wpdb->insert_id; + $queryError = $this->wpdb->last_error; + if ( $queryError ) { + return false; + } + + } else { // END of if for $start === 0 + $regionID = 1; + $membTypeID = 1; + } /* * Get category names from Connections */ @@ -213,23 +212,22 @@ class GlmMemberImportFromConnections // Get the category items from the term taxonomy table in Connections $sql = " SELECT * - FROM ".$this->wpdb->prefix."connections_term_taxonomy; - ;"; - $rawCats = $this->wpdb->get_results($sql, ARRAY_A); + FROM ".$this->wpdb->prefix."connections_term_taxonomy"; + $rawCats = $this->wpdb->get_results( $sql, ARRAY_A ); $queryError = $this->wpdb->last_error; - if ($queryError) { + if ( $queryError ) { return false; } // Start building a clean category table $cats = array(); - foreach ($rawCats as $c) { - if ($c['taxonomy'] == 'category') { + foreach ( $rawCats as $c ) { + if ( $c['taxonomy'] == 'category' ) { $cats[$c['term_id']] = array( - 'id' => $c['term_taxonomy_id'], + 'id' => $c['term_taxonomy_id'], 'term_id' => $c['term_id'], - 'descr' => $c['description'], - 'parent' => $c['parent'] + 'descr' => $c['description'], + 'parent' => $c['parent'] ); } } @@ -238,63 +236,58 @@ class GlmMemberImportFromConnections // Get the category items from the term taxonomy table in Connections $sql = " SELECT * - FROM ".$this->wpdb->prefix."connections_terms; - ;"; - $rawTerms = $this->wpdb->get_results($sql, ARRAY_A); + FROM ".$this->wpdb->prefix."connections_terms"; + $rawTerms = $this->wpdb->get_results( $sql, ARRAY_A ); $queryError = $this->wpdb->last_error; - if ($queryError) { + if ( $queryError ) { return false; } + // Add terms to category table - foreach ($rawTerms as $t) { + foreach ( $rawTerms as $t ) { $cats[$t['term_id']]['name'] = $t['name']; } - // Store all categories and collect the new IDs - reset($cats); - while (list($k, $c) = each($cats)) { - $sql = " - INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories - ( - name, - descr, - short_descr, - parent - ) - VALUES - ( - '".addslashes($c['name'])."', - '".addslashes($c['descr'])."', - '', - 0 - ) - ;"; - $this->wpdb->query($sql); - $catID = $this->wpdb->insert_id; - $queryError = $this->wpdb->last_error; - if ($queryError) { - // not doing anything right now + if ( $start === 0 ) { + // Store all categories and collect the new IDs + reset( $cats ); + while ( list( $k, $c ) = each( $cats ) ) { + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories + ( name, descr, short_descr, parent) + VALUES + ( '".addslashes( $c['name'] )."', '".addslashes( $c['descr'] )."', '', 0)"; + $this->wpdb->query( $sql ); + $catID = $this->wpdb->insert_id; + $queryError = $this->wpdb->last_error; + if ( $queryError ) { + // not doing anything right now + } + $cats[$k]['new_id'] = $catID; + } + } else { + reset( $cats ); + while ( list( $k, $c ) = each( $cats ) ) { + $cats[$k]['new_id'] = $this->getCategoryIdByName( $c['name'] ); } - $cats[$k]['new_id'] = $catID; } // Re-scan categories and populate parents with updated id - reset($cats); - foreach ($cats as $c) { + reset( $cats ); + foreach ( $cats as $c ) { // If the category has a parent ID - if ($c['parent'] > 0) { + if ( $c['parent'] > 0 ) { $newParent = $cats[$c['parent']]['new_id']; $sql = " UPDATE ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories SET parent = $newParent - WHERE id = ".$c['new_id']." - ;"; - $this->wpdb->query($sql); + WHERE id = ".$c['new_id']; + $this->wpdb->query( $sql ); $queryError = $this->wpdb->last_error; - if ($queryError) { + if ( $queryError ) { // not doing anything right now } } @@ -303,11 +296,10 @@ class GlmMemberImportFromConnections // Get member/category mapping $sql = " SELECT * - FROM ".$this->wpdb->prefix."connections_term_relationships - ;"; - $memberCats = $this->wpdb->get_results($sql, ARRAY_A); + FROM ".$this->wpdb->prefix."connections_term_relationships"; + $memberCats = $this->wpdb->get_results( $sql, ARRAY_A ); $queryError = $this->wpdb->last_error; - if ($queryError) { + if ( $queryError ) { return false; } @@ -316,30 +308,22 @@ class GlmMemberImportFromConnections */ $membersImported = 0; $cities = array(); - foreach ($list as $m) { + foreach ( $list as $m ) { // If we're not skipping this entry - if (!isset($_REQUEST['skip'][$m['id']])) { + if ( !isset( $_REQUEST['skip'][$m['id']] ) && $m['organization'] ) { + + // echo '
$m: ' . print_r( $m, true ) . '
'; /* * Create base Member Record */ $sql = " INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members - ( - access, - member_type, - created, - name - ) + ( access, member_type, created, name, member_slug, old_member_id ) VALUES - ( - ".$this->config['access_numb']['Moderated'].", - $membTypeID, - '".$m['ts']."', - '".addslashes($m['organization'])."' - ) - ;"; + ( ".$this->config['access_numb']['Moderated'].", $membTypeID, '".$m['ts']."', + '".addslashes($m['organization'])."', '".sanitize_title($m['organization'])."', " . $m['id'] . ")"; $this->wpdb->query($sql); $membID = $this->wpdb->insert_id; $queryError = $this->wpdb->last_error; @@ -347,61 +331,93 @@ class GlmMemberImportFromConnections // Not doing anything right now } + // For social urls + // Mostly Facebook + if ( isset( $m['social'] ) && is_array( $m['social'] ) ) { + // Get the first one + reset( $m['social'] ); + $social = current( $m['social'] ); + if ( $social['visibility'] == 'public' && $social['url'] ) { + $this->wpdb->insert( + GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX . 'social_urls', + array( + 'ref_type' => 20, + 'ref_dest' => $membID, + 'url' => $social['url'], + 'social' => 1 + ), + array( + '%d', + '%d', + '%s', + '%d' + ) + ); + } + } + /* * Add a member information record */ // Get address data - reset($m['addresses']); - $addr = current($m['addresses']); - - // Check if city has been created yet - if (!isset($cities[$addr['city']])) { - - // Create City - /* - * Create default region - */ - $sql = " - INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities - ( - name - ) - VALUES - ( - '".$addr['city']."' - ) - ;"; - $this->wpdb->query($sql); - $cityID = $this->wpdb->insert_id; - $queryError = $this->wpdb->last_error; - if ($queryError) { - // Not doing anything right now - } - $cities[$addr['city']] = $cityID; - + if ( is_array( $m['addresses'] ) ) { + reset($m['addresses']); + $addr = current($m['addresses']); + } else { + $addr = array( + 'city' => '' + ); } + // // Check if city has been created yet + // if (!isset($cities[$addr['city']])) { + // + // // Create City + // /* + // * Create default region + // */ + // $sql = " + // INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities + // ( name) + // VALUES + // ( '".$addr['city']."')"; + // $this->wpdb->query($sql); + // $cityID = $this->wpdb->insert_id; + // $queryError = $this->wpdb->last_error; + // if ($queryError) { + // // Not doing anything right now + // } + // $cities[$addr['city']] = $cityID; + // + // } + // Get first link as URL - reset($m['links']); - $link = current($m['links']); - $url = $link['url']; + if ( is_array( $m['links'] ) ) { + reset($m['links']); + $link = current($m['links']); + $url = $link['url']; + } else { + $url = ''; + } // Get phone numbers $phone = ''; $toll_free = ''; - foreach ($m['phone_numbers'] as $ph) { - switch($ph['type']) { - case 'workphone': - $phone = $ph['number']; - break; - case 'homephone': - $toll_free = $ph['number']; - break; - case 'workfax': - case 'homefax': - case 'cellphone': - break; + if ( is_array( $m['phone_numbers'] ) ) { + foreach ($m['phone_numbers'] as $ph) { + switch($ph['type']) { + case 'workphone': + $phone = $ph['number']; + break; + case 'homephone': + $toll_free = $ph['number']; + break; + case 'workfax': + case 'homefax': + case 'cellphone': + break; + } } } @@ -409,19 +425,43 @@ class GlmMemberImportFromConnections $logo = ''; if (isset($m['options']['logo'])) { $logoPath = $m['options']['logo']['meta']['path']; - $logo = $this->storeImage($logoPath); - if ($logo === false) { + if ( is_file( $logoPath ) ) { + $logo = $ImageUpload->storeImage($logoPath); + if ($logo === false) { + $logo = ''; + } else { + $logo = $logo['newFileName']; + } + } else { $logo = ''; } } elseif (isset($m['options']['image'])) { $imagePath = $m['options']['image']['meta']['original']['path']; - $logo = $this->storeImage($imagePath); - if ($logo === false) { + if ( is_file( $imagePath ) ) { + $logo = $ImageUpload->storeImage($imagePath); + if ($logo === false) { + $logo = ''; + } else { + $logo = $logo['newFileName']; + } + } else { $logo = ''; } } $t = date('Y-m-d H:i:s', time()); + // Put the bio and notes together to make the desc and create a short descr + $descr = $short_descr = ''; + if ( trim( strip_tags( $m['bio'] ) ) != '' ) { + $descr .= $m['bio']; + } + if ( trim( strip_tags( $m['notes'] ) ) ) { + $descr .= $m['notes']; + } + if ( $descr ) { + $short_descr = substr( strip_tags( $descr ), 0, 120 ); + } + $cityID = $this->getCityIdByName( $addr['city'] ); $sql = " INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info ( @@ -458,12 +498,12 @@ class GlmMemberImportFromConnections $this->config['status_numb']['Inactive'] ).", 'Imported from Connections Business Listing', - '".addslashes($m['bio'])."', - '', + '".addslashes( $descr )."', + '".addslashes( $short_descr )."', '".addslashes($addr['line_1'])."', '".addslashes($addr['line_2'])."', - $cityID, - '".$addr['state']."', + ". ( $cityID ? $cityID : 0 ). ", + '".array_search( $addr['state'], $this->config['states'] )."', '".$addr['country']."', '".$addr['zipcode']."', ".($addr['latitude']!=''?$addr['latitude']:'null').", @@ -477,10 +517,9 @@ class GlmMemberImportFromConnections '', '$t', '$t' - ) - ;"; + )"; $this->wpdb->query($sql); - $membID = $this->wpdb->insert_id; + $membInfoID = $this->wpdb->insert_id; $queryError = $this->wpdb->last_error; if ($queryError) { // Not doing anything right now @@ -496,16 +535,9 @@ class GlmMemberImportFromConnections // Add to category_member_info table $sql = " INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info - ( - category, - member_info - ) + ( category, member_info) VALUES - ( - ".$cats[$mc['term_taxonomy_id']]['new_id'].", - $membID - ) - ;"; + ( ".$cats[$mc['term_taxonomy_id']]['new_id'].", $membInfoID)"; $this->wpdb->query($sql); $queryError = $this->wpdb->last_error; if ($queryError) { @@ -522,63 +554,66 @@ class GlmMemberImportFromConnections return $membersImported; } - /* - * Store image and return image name + /** + * Grab the city id with given name * - * @var string $image Source image location (not deleted) + * If the city doesn't exists then create it and return the id. * - * @return string Image name - * @access public + * @param $city_name City Name to search + * + * @return int City Id */ - - // If we have a good image - public function storeImage($image) + public function getCityIdByName( $city_name ) { - - // Get new image using temporary file name - $newImage = wp_get_image_editor($image); - - // If we have a good image - if ( ! is_wp_error( $newImage ) ) { - - // Get the desired file name and add a timestamp to it to ensure that it's unique - $fInfo = pathinfo($image); - $fInfo['filename'] = preg_replace('/([^a-zA-Z0-9-_\.]+)/','_', $fInfo['filename']); - $newFilename = $fInfo['filename'].'_'.time().'.'.$fInfo['extension']; - - // Try to store the image using that file name in the 'original' directory - $storedImage = $newImage->save( GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename ); - - // Now resize the images using $sizeArray - $sizes = $newImage->multi_resize($this->config['imageSizes']); - - // Finally, move the files to the various size directories and rename them back to the correct name - while (list($k, $v) = each($this->config['imageSizes'])) { - - // Check if size directory needs to be made - if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k)) { - mkdir(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k); - } - - // If there's an entry in the $sizes array, it means that the image resized to this size - if (isset($sizes[$k])) { - // Move resized file to desired direectory - rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$sizes[$k]['file'], GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename); - } else { - // Image didn't resize to this size, probably because it was smaller than the destination size (silly WP Image Editor class) - so just use the original - copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename); - } + if ( trim( $city_name ) == '' ) { + return 0; + } + $city_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE name = %s", + trim( $city_name ) + ) + ); + + if ( !$city_id ) { + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities', + array( 'name' => trim( $city_name ) ), + array( '%s' ) + ); + $city_id = $this->wpdb->insert_id; + $queryError = $this->wpdb->last_error; + if ($queryError) { + // Not doing anything right now } - - } else { - return false; } + return $city_id; - return $newFilename; + } + public function getCategoryIdByName( $category ) + { + $category_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories + WHERE name = %s", + $category + ) + ); + if ( !$category_id ) { + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'categories', + array( 'name' => $category, 'descr' => '', 'short_descr' => '', parent => 0 ), + array( '%s', '%s', '%s', '%d' ) + ); + } + return $category_id; } } -?> \ No newline at end of file +?> diff --git a/models/admin/management/development.php b/models/admin/management/development.php index c1de9fec..a6aa7721 100644 --- a/models/admin/management/development.php +++ b/models/admin/management/development.php @@ -13,7 +13,7 @@ * @version 0.1 */ -/* +/** * This class performs the work for the default action of the "Members" menu * option, which is to display the members dashboard. * @@ -36,16 +36,16 @@ class GlmMembersAdmin_management_development */ public $config; - /* + /** * Constructor * - * This contructor sets up this model. At this time that only includes + * This contractor sets up this model. At this time that only includes * storing away the WordPress data object. * * @return object Class object * */ - public function __construct ($wpdb, $config) + public function __construct ( $wpdb, $config ) { // Save WordPress Database object @@ -56,7 +56,7 @@ class GlmMembersAdmin_management_development } - /* + /** * Perform Model Action * * This method does the work for this model and returns any resulting data @@ -65,7 +65,7 @@ class GlmMembersAdmin_management_development * * 'status' * - * True if successfull and false if there was a fatal failure. + * True if successful and false if there was a fatal failure. * * 'menuItemRedirect' * @@ -80,7 +80,7 @@ class GlmMembersAdmin_management_development * * 'view' * - * A suggested view name that the contoller should use instead of the + * A suggested view name that the controller should use instead of the * default view for this model or false to indicate that the default view * should be used. * @@ -90,55 +90,60 @@ class GlmMembersAdmin_management_development * produce output. * */ - public function modelAction ($actionData = false) + public function modelAction ( $actionData = false ) { - $resultMessage = ''; - $success = false; - $haveMembers = false; - $import = false; - $importNotice = ''; + $resultMessage = ''; + $success = false; + $haveMembers = false; + $import = false; + $importNotice = ''; $haveDatabaseTableList = false; - $databaseList = false; + $databaseList = false; // Get current database version $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION; - settype($dbVersion, 'string'); + settype( $dbVersion, 'string' ); // Load database activation class to get access to database version information require_once GLM_MEMBERS_PLUGIN_PATH . '/activate.php'; - $activate = new glmMembersPluginActivate($this->wpdb, $this->config, true); + $activate = new glmMembersPluginActivate( $this->wpdb, $this->config, true ); $option = ''; - if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') { + if ( isset( $_REQUEST['option'] ) && $_REQUEST['option'] != '' ) { $option = $_REQUEST['option']; } - switch($option) { + switch( $option ) { case 'import_connections': // Load Member Info Data Class and get info data for later use - require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/glmMemberImportFromConnections.php'; - $Connections = new GlmMemberImportFromConnections($this->wpdb, $this->config); + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/glmMemberImportFromConnections.php'; + $Connections = new GlmMemberImportFromConnections( $this->wpdb, $this->config ); - if (isset($_REQUEST['import']) && $_REQUEST['import'] == 'now') { + $start = isset( $_REQUEST['start'] ) ? filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ): 0; - // Reset the database - $this->deleteDataTables($dbVersion); - $this->createDataTables($dbVersion); + if ( isset( $_REQUEST['import'] ) && $_REQUEST['import'] == 'now' ) { - // Delete Images - foreach( new RecursiveIteratorIterator( - new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_IMAGES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ), - RecursiveIteratorIterator::CHILD_FIRST ) as $value ) { - if ($value->isFile()) { - unlink( $value ); + if ( $start === 0 ) { + // Reset the database + $this->deleteDataTables( $dbVersion ); + $this->createDataTables( $dbVersion ); + + // Delete Images + foreach( new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( GLM_MEMBERS_PLUGIN_IMAGES_PATH, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS ), + RecursiveIteratorIterator::CHILD_FIRST ) as $value ) { + if ( $value->isFile() ) { + unlink( $value ); + } } - } + } $import = true; - $templateData['membersImported'] = $Connections->doImport(); + $templateData['membersImported'] = $Connections->doImport( $start ); + $templateData['start'] = $start + $Connections::PROCESS_COUNT; } else { @@ -148,59 +153,31 @@ class GlmMembersAdmin_management_development $importNotice .= 'Connections Business Directory plugin is active.
Number of businesses listed: '.$c.'
'; // Get the basic business data for review. - $templateData['members'] = $Connections->getList(); - if ($templateData['members'] === false) { - $importNotice .= 'No businesses were retieved.
'; + $templateData['members'] = $Connections->getList( 0, true ); + if ( $templateData['members'] === false ) { + $importNotice .= 'No businesses were retrieved.
'; break; } - $templateData['haveMembers'] = true; + $haveMembers = true; } break; -/* - case 'drop': - case 'reset': - - $del = $this->deleteDataTables($dbVersion); - if ($del) { - } else { - break; - } - - if ($option != 'reset') { - break; - } - - case 'create': - - $create = $this->createDataTables($dbVersion); - - // If there were no errors - if ($create) { - - // Save the version of the installed database - update_option('glmMembersDatabaseDbVersion', $dbVersion); - - } - - break; -*/ case 'list': $databaseList = array(); // For each plug-in in the registered add-on array (includes the main plugin) - Updated for plug-able database tables - foreach ($this->config['addOns'] as $a) { + foreach ( $this->config['addOns'] as $a ) { $databaseList[$a['name']] = array( 'addonName' => $a['name'], 'haveDatabase' => false ); - if ($a['database'] ) { + if ( $a['database'] ) { // Add add-on database info to list $databaseList[$a['name']] = array_merge_recursive($databaseList[$a['name']], $a['database']); @@ -260,27 +237,27 @@ class GlmMembersAdmin_management_development } - $templateData['resultMessage'] = $resultMessage; - $templateData['success'] = $success; - $templateData['haveMembers'] = $haveMembers; - $templateData['import'] = $import; - $templateData['importNotice'] = $importNotice; + $templateData['resultMessage'] = $resultMessage; + $templateData['success'] = $success; + $templateData['haveMembers'] = $haveMembers; + $templateData['import'] = $import; + $templateData['importNotice'] = $importNotice; $templateData['haveDatabaseTableList'] = $haveDatabaseTableList; - $templateData['databaseList'] = $databaseList; + $templateData['databaseList'] = $databaseList; // Return status, suggested view, and data to controller return array( - 'status' => true, + 'status' => true, 'menuItemRedirect' => false, - 'modelRedirect' => false, - 'view' => 'admin/management/development.html', - 'data' => $templateData + 'modelRedirect' => false, + 'view' => 'admin/management/development.html', + 'data' => $templateData ); } - /* + /** * Delete Members Database Tables * * @param string $dbVersion Current version of Members Database @@ -291,6 +268,11 @@ class GlmMembersAdmin_management_development public function deleteDataTables($dbVersion) { + // Empty social urls + $this->wpdb->query( + 'DELETE FROM ' . GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX . 'social_urls' + ); + // Read in Database deletion script - assumes the current db version. $dropSQL = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/drop_database_V'.$dbVersion.'.sql'; if (!is_file($dropSQL)) { @@ -315,7 +297,7 @@ class GlmMembersAdmin_management_development } - /* + /** * Create Members Database Tables * * @param string $dbVersion Current version of Members Database -- 2.17.1