Updated import and fixed issues with resetting database
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 26 Jan 2016 19:11:46 +0000 (14:11 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 26 Jan 2016 19:11:46 +0000 (14:11 -0500)
models/admin/management/import.php
setup/databaseScripts/drop_database_V1.0.43.sql
views/admin/management/import/readDatabase.html

index 20f15ab..31503cd 100644 (file)
@@ -390,6 +390,8 @@ class GlmMembersAdmin_management_import
 
 
                 // Read in all member categories
+                $haveCatImportIssues = false;
+                $catImportIssues = '';
                 if (!$failure) {
                     $sql = "
                             SELECT *
@@ -418,31 +420,59 @@ class GlmMembersAdmin_management_import
                             // Process top level categories first
                             foreach ($tmp as $x) {
 
-                                // If this is a top level category
-                                if ($x['parent_id'] == 0) {
+                                // If this is a top level category - parent = 0 or points to itself
+                                if ($x['parent_id'] == 0 || $x['parent_id'] == $x['category_id']) {
+
+                                    foreach ($category as $y) {
+                                        if ($y['name'] == $x['name']) {
+                                            $haveCatImportIssues = true;
+                                            $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') has the same name as another category at the same level. Added as duplicate.</li>';
+                                        }
+                                    }
+                                    reset($category);
+
                                     $category[$x['category_id']] = $x;
                                     $category[$x['category_id']]['subcat'] = array();
+
+                                    if ($x['parent_id'] == $x['category_id']) {
+                                        $haveCatImportIssues = true;
+                                        $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') was pointing to itself as a parent. Now a top level category.</li>';
+                                    }
                                 }
 
                             }
 
-                            // Now process all sub-categories
+                            // Now look for sub-categories with bad parents and add them as a main category
                             reset($tmp);
                             foreach ($tmp as $x) {
 
-                                // If this is NOT a top level category
-                                if ($x['parent_id'] > 0) {
+                                // If this is NOT a top level category - Parent not 0 and not pointing to itself
+                                if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
 
-                                    // Check if we have the requested parent as a top-level category
-                                    if (isset($category[$x['parent_id']])) {
-                                        $category[$x['parent_id']]['subcat'][$x['category_id']] = $x;
-                                    } else {
+                                    // Check if we don't have the requested parent as a top-level category
+                                    if (!isset($category[$x['parent_id']])) {
                                         // Since the parent doesn't exist, we're just going to make this one a parent.
+                                        $haveCatImportIssues = true;
+                                        $catImportIssues .= '<li>Category <b>'.$x['name'].'</b> ('.$x['category_id'].') had a bad parent ID ('.$x['parent_id'].'). Now a top level category.</li>';
                                         $category[$x['category_id']] = $x;
                                         $category[$x['category_id']]['subcat'] = array();
                                     }
                                 }
                             }
+
+                            // Now process all supposedly good sub-categories
+                            reset($tmp);
+                            foreach ($tmp as $x) {
+
+                                // If this is NOT a top level category - Parent not 0 and not pointing to itself
+                                if ($x['parent_id'] > 0 && $x['parent_id'] != $x['category_id']) {
+
+                                    // Check if we have the requested parent as a top-level category
+                                    if (isset($category[$x['parent_id']])) {
+                                        $category[$x['parent_id']]['subcat'][$x['category_id']] = $x;
+                                    }
+                                }
+                            }
                         }
                     }
                 }
@@ -1019,6 +1049,8 @@ class GlmMembersAdmin_management_import
                     $templateData['numbMembersActive'] = $numbMembersActive;
                     $templateData['numbMembersInactive'] = $numbMembersInactive;
                     $templateData['numbCategories'] = count($catTrans);
+                    $templateData['haveCatImportIssues'] = $haveCatImportIssues;
+                    $templateData['catImportIssues'] = $catImportIssues;
                     $templateData['numbCategoryMembers'] = count($membCat);
                     $templateData['numbAmenities'] = count($amenity);
                     $templateData['numbAmenityMembers'] = $numbAmenityMembers;
index 553101a..d77cfee 100644 (file)
@@ -8,11 +8,10 @@ DROP TABLE IF EXISTS
     {prefix}accommodation_types,
     {prefix}accommodations,
     {prefix}accounts,
-    {prefix}activties,
+    {prefix}activities,
     {prefix}amenities,
     {prefix}amenity_ref,
     {prefix}category_member_info,
-    {prefix}categories,
     {prefix}cities,
     {prefix}contacts,
     {prefix}facilities,
@@ -30,6 +29,7 @@ DROP TABLE IF EXISTS
     {prefix}settings_general,
     {prefix}settings_terms,
     {prefix}social_media,
-    {prefix}social_media_ref
+    {prefix}social_media_ref,
+    {prefix}categories
 ;
 
index bce2721..898a11a 100644 (file)
         <tr><th>Members Active:</th><td>{$numbMembersActive}</td></tr>
         <tr><th>Members Inactive:</th><td>{$numbMembersInactive}</td></tr>
         <tr><th>Categories:</th><td>{$numbCategories}</td></tr>
-        <tr><th>Member Category Entires:</th><td>{$numbCategoryMembers}</td></tr>
+        <tr>
+            <th>Member Category Entries:</th>
+            <td>
+                {$numbCategoryMembers}
+                {if $haveCatImportIssues}
+                    <ul>{$catImportIssues}</ul>
+                {/if}
+            </td>
+        </tr>
         <tr><th>Amenities:</th><td>{$numbAmenities}</td></tr>
         <tr><th>Member Amenity Entries:</th><td>{$numbAmenityMembers}</td></tr>
         <tr><th>Credit Card Types:</th><td>{$numbCcards}</td></tr>