From a38ec5a62e09c8fbb8747d90eff45d783d5ad185 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 22 Jun 2017 16:54:35 -0400 Subject: [PATCH] Photos upload now working Need to break up like members for really huge files. --- models/admin/import/index.php | 94 +++++++++++++++++++++++++- views/admin/import/header.html | 2 +- views/admin/import/photosProcess.html | 23 +++++++ views/admin/import/photosValidate.html | 31 +++++++++ 4 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 views/admin/import/photosProcess.html create mode 100644 views/admin/import/photosValidate.html diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 5ec84a2b..357fad37 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -118,6 +118,22 @@ class GlmMembersAdmin_import_index */ public $totalMembers = 0; + /** + * totalPhotos + * + * @var float + * @access public + */ + public $totalPhotos = 0; + + /** + * photosProcessed + * + * @var float + * @access public + */ + public $photosProcessed = 0; + /** * processingComplete * @@ -187,6 +203,7 @@ class GlmMembersAdmin_import_index $option = 'default'; $clearData = false; $haveMembers = false; + $fileExists = false; // Check to see if they have members $haveMembers = $this->wpdb->get_var( "SELECT count(id) @@ -386,16 +403,83 @@ class GlmMembersAdmin_import_index if ( isset( $_FILES ) ) { move_uploaded_file( $_FILES['photos_file']['tmp_name'], $uploadPath . '/photoData.csv' ); } + if ( is_file( $uploadPath . '/photoData.csv' ) ) { + $fileExists = true; + } // validate the header line - $fData = $this->readCSVFileHeaders( $uploadPath . '/photoData.csv' ); - $isValid = ( $fData == array( 'member_id', 'image', 'caption' ) ); + $fData = $this->readCSVFileHeaders( $uploadPath . '/photoData.csv' ); + $validate = array( 'member_id', 'image', 'caption' ); + $isValid = ( $fData == $validate ); // If the file validates then we're ready to process $readyToProcess = $isValid; - $view= 'photos.html'; + $view= 'photosValidate.html'; $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; break; + case 'photosProcess': + // Setup the image processing + require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/imageUpload.php'; + $ImageUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config); + + // Setup the member_info class + require_once GLM_MEMBERS_PLUGIN_PATH . '/classes/data/dataMemberInfo.php'; + $memberInfoObj = new GlmDataMemberInfo( $this->wpdb, $this->config ); + + if ( is_file( $uploadPath . '/photoData.csv' ) ) { + // Get the entire photo file data + $photoData = $this->readCSVFile( $uploadPath . '/photoData.csv' ); + //echo '
$photoData: ' . print_r( $photoData, true ) . '
'; + $this->totalPhotos = count( $photoData ); + $this->photosProcessed = count( $photoData ); + + $refType = $this->config['ref_type_numb']['MemberInfo']; + $refTable = $this->config['ref_type_table'][$refType]; + + // Loop through the photoData array + foreach ( $photoData as $photo ) { + echo '
$photo: ' . print_r( $photo, true ) . '
'; + // If there's no url or the url is not valid then skip it. + if ( $photoUrl = filter_var( $photo['image'], FILTER_VALIDATE_URL ) ) { + echo '
$photoUrl: ' . print_r( $photoUrl, true ) . '
'; + // Need to first get the member id from the database + // It will match from the old_member_id field + $memberId = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE old_member_id = %d", + $photo['member_id'] + ) + ); + if ( !$memberId ) { + continue; + } + echo '
$memberId: ' . print_r( $memberId, true ) . '
'; + // Now that we have the member id we need to get the + // id for the active member info record + $memberInfoId = $memberInfoObj->getActiveInfoIdForMember( $memberId ); + if ( !$memberInfoId ) { + continue; + } + echo '
$memberInfoId: ' . print_r( $memberInfoId, true ) . '
'; + $res = $ImageUpload->storeImage( + $photoUrl, + $refType, + $refTable, + $memberInfoId, + $photo['caption'] + ); + } + + } + + $view= 'photosProcess.html'; + } else { + $view= 'photosValidate.html'; + } + break; + case 'photos': $view= 'photos.html'; break; @@ -421,10 +505,13 @@ class GlmMembersAdmin_import_index // Setup the template data array $templateData = array( + 'fileExists' => $fileExists, 'option' => $option, 'errors' => $this->errors, 'numberProcessed' => $this->numberProcessed, 'totalMembers' => $this->totalMembers, + 'totalPhotos' => $this->totalPhotos, + 'photosProcessed' => $this->photosProcessed, 'completed' => $this->processingComplete, 'data' => false, 'fileData' => $fileData, @@ -432,6 +519,7 @@ class GlmMembersAdmin_import_index 'csvData' => '
$fileData: ' . print_r( $fileData, true ) . '
', 'readyToProcess' => $readyToProcess, 'haveMembers' => $haveMembers, + 'isValid' => $isValid, ); // Return status, suggested view, and data to controller return array( diff --git a/views/admin/import/header.html b/views/admin/import/header.html index 64b09953..db8fc9e1 100644 --- a/views/admin/import/header.html +++ b/views/admin/import/header.html @@ -5,7 +5,7 @@ diff --git a/views/admin/import/photosProcess.html b/views/admin/import/photosProcess.html new file mode 100644 index 00000000..26a69363 --- /dev/null +++ b/views/admin/import/photosProcess.html @@ -0,0 +1,23 @@ +{include file='admin/import/header.html'} + +

Data Import Step 3: Process Members

+ + + + + + + + + + + + {if $errors} + {foreach $errors as $error} + {$error} + {/foreach} + {/if} + +
Total Photos{$totalPhotos}
Processed Photos{$photosProcessed}
+ +{include file='admin/footer.html'} diff --git a/views/admin/import/photosValidate.html b/views/admin/import/photosValidate.html new file mode 100644 index 00000000..e8c03e4f --- /dev/null +++ b/views/admin/import/photosValidate.html @@ -0,0 +1,31 @@ +{include file='admin/import/header.html'} + +

Data Import: Photos Validation

+ + + + + + + + {if $readyToProcess} + + + + {/if} + +
+ {if $fileExists} + photoData.csv + {/if} + + {if $isValid} + Is Valid + {else} + Not Valid + {/if} +
+ Process Photos +
+ +{include file='admin/footer.html'} -- 2.17.1