Import script now updating members.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Feb 2019 21:23:48 +0000 (16:23 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Feb 2019 21:23:48 +0000 (16:23 -0500)
Testing to make sure it is updating.
Putting member update into transaction.

models/admin/import/index.php
views/admin/import/processMembers.html

index 72d44ef..061db1a 100644 (file)
@@ -126,6 +126,20 @@ class GlmMembersAdmin_import_index
      * @access public
      */
     public $numberProcessed = 0;
+    /**
+     * updatedMembers
+     *
+     * @var float
+     * @access public
+     */
+    public $updatedMembers = 0;
+    /**
+     * addedMembers
+     *
+     * @var float
+     * @access public
+     */
+    public $addedMembers = 0;
 
     /**
      * totalMembers
@@ -482,7 +496,7 @@ class GlmMembersAdmin_import_index
             }
             // Here we need to check to see if we processed all members.
             // Also the counter has to increment the total processed so far.
-            if ( $this->numberProcessed == $this->totalMembers ) {
+            if ( $this->numberProcessed >= $this->totalMembers ) {
                 $this->processingComplete = true;
             }
             // Set the view file
@@ -864,6 +878,8 @@ class GlmMembersAdmin_import_index
             'option'          => $option,
             'errors'          => $this->errors,
             'numberProcessed' => $this->numberProcessed,
+            'updatedMembers'  => $this->updatedMembers,
+            'addedMembers'    => $this->addedMembers,
             'totalMembers'    => $this->totalMembers,
             'totalPhotos'     => $this->totalPhotos,
             'totalFiles'      => $this->totalFiles,
@@ -1203,6 +1219,13 @@ class GlmMembersAdmin_import_index
             return ( $errorCount == 0 );
             break;
         case 'member':
+            require_once GLM_MEMBERS_PLUGIN_PATH .  '/classes/data/dataMemberInfo.php';
+            $memberInfoObj = new GlmDataMemberInfo( $this->wpdb, $this->config );
+
+            // Turn on wpdb errors
+            $this->wpdb->show_errors();
+            $this->wpdb->query( 'START TRANSACTION' );
+
             // Setup the image processing
             require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/imageUpload.php';
             $ImageUpload = new GlmMembersAdmin_ajax_imageUpload( $this->wpdb, $this->config );
@@ -1227,9 +1250,6 @@ class GlmMembersAdmin_import_index
             $testEnd = $start + $this->memberProcessCountPerRound;
             $ending  = ( $testEnd <= $this->totalMembers ) ? $testEnd : $this->totalMembers;
 
-            // Turn on wpdb errors
-            $this->wpdb->show_errors();
-
             // We have to add one to $ending (array starts at 1 not 0).
             $ending++;
             // Starting iterating over memberData
@@ -1438,6 +1458,13 @@ class GlmMembersAdmin_import_index
                 }
                 // get last id for member_info table to use for profile id
                 // Setup the categories for this profile record
+                if ( $memberNeedsUpdate ) {
+                    $this->wpdb->delete(
+                        GLM_MEMBERS_PLUGIN_DB_PREFIX . 'category_member_info',
+                        array( 'member_info' => $profileId ),
+                        array( '%d' )
+                    );
+                }
                 if ( $data['categories'] ) {
                     $categories = explode( ',', $data['categories'] );
                     foreach ( $categories as $catData ) {
@@ -1459,6 +1486,13 @@ class GlmMembersAdmin_import_index
                         }
                     }
                 }
+                if ( $memberNeedsUpdate ) {
+                    $this->wpdb->delete(
+                        GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenity_ref',
+                        array( 'ref_dest' => $profileId ),
+                        array( '%d' )
+                    );
+                }
                 // Setup the amenities for this profile record
                 if ( $data['amenities'] ) {
                     $amenities = explode( ',', $data['amenities'] );
@@ -1485,9 +1519,20 @@ class GlmMembersAdmin_import_index
                 }
                 // Add this record to the processed counter.
                 $this->numberProcessed++;
+                if ( $memberNeedsUpdate ) {
+                    $this->updatedMembers++;
+                } else {
+                    $this->addedMembers++;
+                }
 
                 // Ending iterating over memberData
             }
+
+            // ROLLBACK
+            // $this->wpdb->query( 'ROLLBACK' );
+            // Commit
+            $this->wpdb->query( 'COMMIT' );
+
             //$ret .= '<pre>$this->members: ' . print_r( $this->members, true ) . '</pre>';
             $ret .= '<p>...</p>';
             break;
index 477d2da..7f73ec2 100644 (file)
             <th>Processed Member</th>
             <td>{$numberProcessed}</td>
         </tr>
+        <tr>
+            <th>Updated Member</th>
+            <td>{$updatedMembers}</td>
+        </tr>
+        <tr>
+            <th>Added Member</th>
+            <td>{$addedMembers}</td>
+        </tr>
         {if !$completed}
             {$newStart = 1 + $numberProcessed}
             <tr>
     </table>
 
     {if !$completed}
-            {$newStart = 1 + $numberProcessed}
-    <script>
-    var test = '{$thisUrl}?page={$thisPage}&glm_action=index&option=processMembers&start={$newStart}&numberProcessed={$numberProcessed}';
-    window.location.href = test;
-    </script>
+        {$newStart = 1 + $numberProcessed}
+        <script>
+        var test = '{$thisUrl}?page={$thisPage}&glm_action=index&option=processMembers&start={$newStart}&numberProcessed={$numberProcessed}';
+        window.location.href = test;
+        </script>
     {/if}
 
 {include file='admin/footer.html'}