From: Chuck Scott Date: Mon, 11 May 2015 18:39:35 +0000 (-0400) Subject: Final testing of Connections import X-Git-Tag: v1.0.0~33 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=e5398e30770b43e2464c62840e8d083783e6674c;p=WP-Plugins%2Fglm-member-db.git Final testing of Connections import --- diff --git a/classes/data/dataCategoryMemberInfo.php b/classes/data/dataCategoryMemberInfo.php index 821a5769..b2d25479 100644 --- a/classes/data/dataCategoryMemberInfo.php +++ b/classes/data/dataCategoryMemberInfo.php @@ -269,19 +269,21 @@ class GlmDataCategoryMemberInfo extends GlmDataAbstract } // For any existing categories listed that aren't marked as selected, remove them - foreach ($current as $key => $val) { + if (is_array($current) && count($current) > 0) { + foreach ($current as $key => $val) { - if (!$val['selected']) { + if (!$val['selected']) { - // Delete the entry - // Add the category - $sql = " - DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info - WHERE member_info = $memberInfoID - AND id = ".$val['id']." - ;"; - $this->wpdb->query($sql); + // Delete the entry + // Add the category + $sql = " + DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info + WHERE member_info = $memberInfoID + AND id = ".$val['id']." + ;"; + $this->wpdb->query($sql); + } } } diff --git a/classes/glmMemberImportFromConnections.php b/classes/glmMemberImportFromConnections.php index 411f0259..047b6642 100644 --- a/classes/glmMemberImportFromConnections.php +++ b/classes/glmMemberImportFromConnections.php @@ -179,6 +179,7 @@ class GlmMemberImportFromConnections $queryError = $this->wpdb->last_error; if ($queryError) { glmMembersAdmin::addNotice('Error when adding the default member type: Check following message.
'.$queryError.'
', 'AdminError'); + return false; } /* @@ -204,6 +205,115 @@ class GlmMemberImportFromConnections $queryError = $this->wpdb->last_error; if ($queryError) { glmMembersAdmin::addNotice('Error when adding the default region: Check following message.
'.$queryError.'
', 'AdminError'); + return false; + } + + /* + * Get category names from Connections + */ + + // 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); + $queryError = $this->wpdb->last_error; + if ($queryError) { + glmMembersAdmin::addNotice('Error when reading cateory data from Connections.
'.$queryError.'
', 'AdminError'); + return false; + } + + // Start building a clean category table + $cats = array(); + foreach ($rawCats as $c) { + if ($c['taxonomy'] == 'category') { + $cats[$c['term_id']] = array( + 'id' => $c['term_taxonomy_id'], + 'term_id' => $c['term_id'], + 'descr' => $c['description'], + 'parent' => $c['parent'] + ); + } + } + + // get the category terms (names) from Connections + // 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); + $queryError = $this->wpdb->last_error; + if ($queryError) { + glmMembersAdmin::addNotice('Error when reading cateory terms from Connections.
'.$queryError.'
', 'AdminError'); + return false; + } + + // Add terms to category table + 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 + ( + '".$c['name']."', + '".$c['descr']."', + '', + 0 + ) + ;"; + $this->wpdb->query($sql); + $catID = $this->wpdb->insert_id; + $queryError = $this->wpdb->last_error; + if ($queryError) { + glmMembersAdmin::addNotice('Error when creating member: Check following message.
'.$queryError.'
', 'AdminError'); + } + $cats[$k]['new_id'] = $catID; + } + + // Re-scan categories and populate parents with updated id + reset($cats); + foreach ($cats as $c) { + + // If the category has a parent ID + 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); + $queryError = $this->wpdb->last_error; + if ($queryError) { + glmMembersAdmin::addNotice('Error when creating member: Check following message.
'.$queryError.'
', 'AdminError'); + } + } + } + + // Get member/category mapping + $sql = " + SELECT * + FROM ".$this->wpdb->prefix."connections_term_relationships + ;"; + $memberCats = $this->wpdb->get_results($sql, ARRAY_A); + $queryError = $this->wpdb->last_error; + if ($queryError) { + glmMembersAdmin::addNotice('Error when reading term relationships from Connections.
'.$queryError.'
', 'AdminError'); + return false; } /* @@ -216,9 +326,6 @@ class GlmMemberImportFromConnections // If we're not skipping this entry if (!isset($_REQUEST['skip'][$m['id']])) { - echo "123 ".$m['id']; - - /* * Create base Member Record */ @@ -378,6 +485,34 @@ class GlmMemberImportFromConnections glmMembersAdmin::addNotice('Error when creating member: Check following message.
'.$queryError.'
', 'AdminError'); } + // Scan member/category mapping array for any for this member + reset ($memberCats); + foreach ($memberCats as $mc) { + + // If there's a mapping for this member + if ($mc['entry_id'] == $m['id']) { + + // Add to category_member_info table + $sql = " + INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info + ( + category, + member_info + ) + VALUES + ( + ".$cats[$mc['term_taxonomy_id']]['new_id'].", + $membID + ) + ;"; + $this->wpdb->query($sql); + $queryError = $this->wpdb->last_error; + if ($queryError) { + glmMembersAdmin::addNotice('Error when creating member/category entry: Check following message.
'.$queryError.'
', 'AdminError'); + } + } + } + // Check for additional image /* $image = ''; diff --git a/models/admin/configure/development.php b/models/admin/configure/development.php index edf68dc9..1dd42a38 100644 --- a/models/admin/configure/development.php +++ b/models/admin/configure/development.php @@ -136,6 +136,9 @@ class GlmMembersAdmin_configure_development } glmMembersAdmin::addNotice('Database tables have been reset in preparation importing members.
', 'AdminNotice'); + // Delete Images +// unlink(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/*'); + $templateData['import'] = true; $templateData['membersImported'] = $Connections->doImport(); diff --git a/models/admin/member/memberInfo.php b/models/admin/member/memberInfo.php index 3361d899..48c7dd94 100644 --- a/models/admin/member/memberInfo.php +++ b/models/admin/member/memberInfo.php @@ -424,7 +424,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo $newCategory = true; - // Check if a parent is specied + // Check if a parent is specified $parent = 0; if ($_REQUEST['newCatParent'][$key] != '') { $parent = $_REQUEST['newCatParent'][$key] -0; @@ -449,6 +449,7 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo $selectedCategories[$key] = $key; } + // A zero index should never happen, but we ignore them anyway // If there's selected categories @@ -469,8 +470,8 @@ class GlmMembersAdmin_member_memberInfo extends GlmDataMemberInfo } // For each category being submitted - // Otherwise there's no categories submitted, so make sure there's none stored - } else { + // Otherwise if this is a submission and there's no categories submitted, so make sure there's none stored + } elseif (isset($_REQUEST['glm_action'])) { $CategoryMemberInfo->clearMemberInfoCategories($memberInfoID); }