for ( $index = $start; $index < $ending; $index++ ) {
$photo = $photoData[$index];
$this->photosProcessed++;
- // echo '<pre>$photoUrl: ' . print_r( $photoUrl, true ) . '</pre>';
// 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
$photo['member_id']
)
);
- // echo '<pre>$memberId: ' . print_r( $memberId, true ) . '</pre>';
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 '<pre>$memberInfoId: ' . print_r( $memberInfoId, true ) . '</pre>';
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 '<pre>$newPhotoUrl: ' . print_r( $newPhotoUrl, true ) . '</pre>';
$res = $ImageUpload->storeImage(
'/tmp/' . $newPhotoUrl,
$refType,
$memberInfoId,
$caption
);
- // echo '<pre>$res: ' . print_r( $res, true ) . '</pre>';
if ( !$res ) {
$this->errors = true;
}
}
+ 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,
$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);
// Logo needs to be a complete url.
if ( isset( $data['logo'] ) ) {
$logo = filter_var( $data['logo'], FILTER_VALIDATE_URL );
+ // echo '<pre>$logo: ' . print_r( $logo, true ) . '</pre>';
if ( $logo ) {
// Transfer the image over to temp directory.
$logoImage = $this->fetchRemoteImage( $logo, '/tmp' );
$res = $ImageUpload->storeImage( '/tmp/'. $logoImage );
+ // echo '<pre>$res: ' . print_r( $res, true ) . '</pre>';
if ($res['newFileName']) {
$data['logo'] = $res['newFileName'];
}