From: Steve Sutton Date: Tue, 5 Mar 2019 15:51:56 +0000 (-0500) Subject: Update csv importer X-Git-Tag: v2.12.0^2~14 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=373f6e61c703e17b07a603958daa1ac404cfc094;p=WP-Plugins%2Fglm-member-db.git Update csv importer Update to not insert photos that are already there. --- diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 061db1a9..37695dca 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -651,7 +651,6 @@ class GlmMembersAdmin_import_index for ( $index = $start; $index < $ending; $index++ ) { $photo = $photoData[$index]; $this->photosProcessed++; - // echo '
$photoUrl: ' . print_r( $photoUrl, true ) . '
'; // If there's no url or the url is not valid then skip it. if ( $photoUrl = filter_var( $photo['image'], FILTER_VALIDATE_URL ) ) { // Need to first get the member id from the database @@ -664,24 +663,46 @@ class GlmMembersAdmin_import_index $photo['member_id'] ) ); - // echo '
$memberId: ' . print_r( $memberId, true ) . '
'; if ( !$memberId ) { - // var_dump( 'no member id' ); continue; } // Now that we have the member id we need to get the // id for the active member info record $memberInfoId = $memberInfoObj->getActiveInfoIdForMember( $memberId ); - // echo '
$memberInfoId: ' . print_r( $memberInfoId, true ) . '
'; if ( !$memberInfoId ) { - // var_dump( 'no member info id' ); continue; } + // Get any current photos for this member info record + $memberInfoPhotos = $this->wpdb->get_results( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "images + WHERE ref_dest = %d", + $memberInfoId + ), + ARRAY_A + ); + + $photoExists = false; + + $fileBaseName = basename( $photoUrl ); + + foreach ( $memberInfoPhotos as $memberPhotos ) { + $checkFileName = preg_replace( '%/tmp/%', '', $memberPhotos['name'] ); + if ( $checkFileName == $fileBaseName ) { + $photoExists = true; + } + } + + // Test if the member info image is already stored + if ( $photoExists ) { + continue; + } + // There's a character limit on the photo caption field // of 255 (mysql TINYTEXT) $caption = substr( $photo['caption'], 0, 250 ); $newPhotoUrl = $this->fetchRemoteImage( $photoUrl, '/tmp' ); - // echo '
$newPhotoUrl: ' . print_r( $newPhotoUrl, true ) . '
'; $res = $ImageUpload->storeImage( '/tmp/' . $newPhotoUrl, $refType, @@ -689,7 +710,6 @@ class GlmMembersAdmin_import_index $memberInfoId, $caption ); - // echo '
$res: ' . print_r( $res, true ) . '
'; if ( !$res ) { $this->errors = true; } @@ -871,6 +891,27 @@ class GlmMembersAdmin_import_index } + if ( $this->numberProcessed ) { + $current_stats = get_option( 'glm-import-stats', false ); + if ( $current_stats ) { + $glm_import_stats = unserialize( $current_stats ); + $addedMembers = $glm_import_stats['addedMembers'] + $this->addedMembers; + $updatedMembers = $glm_import_stats['updatedMembers'] + $this->updatedMembers; + $totalMembers = $this->totalMembers; + } else { + $addedMembers = $this->addedMembers; + $updatedMembers = $this->updatedMembers; + $totalMembers = $this->totalMembers; + } + $glm_import_stats = serialize( array( + 'numberProcessed' => $this->numberProcessed, + 'addedMembers' => $addedMembers, + 'updatedMembers' => $updatedMembers, + 'totalMembers' => $totalMembers, + ) ); + update_option( 'glm-import-stats', $glm_import_stats ); + } + // Setup the template data array $templateData = array( //'addOnTabs' => $addOnTabs, @@ -971,6 +1012,7 @@ class GlmMembersAdmin_import_index $ch = curl_init($file); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $imgData = curl_exec($ch); $httpCode = curl_getinfo($ch); @@ -1326,10 +1368,12 @@ class GlmMembersAdmin_import_index // Logo needs to be a complete url. if ( isset( $data['logo'] ) ) { $logo = filter_var( $data['logo'], FILTER_VALIDATE_URL ); + // echo '
$logo: ' . print_r( $logo, true ) . '
'; if ( $logo ) { // Transfer the image over to temp directory. $logoImage = $this->fetchRemoteImage( $logo, '/tmp' ); $res = $ImageUpload->storeImage( '/tmp/'. $logoImage ); + // echo '
$res: ' . print_r( $res, true ) . '
'; if ($res['newFileName']) { $data['logo'] = $res['newFileName']; }