From 8f44498dc34462756af705e55077cd7f2923dd81 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 26 Jun 2017 15:40:57 -0400 Subject: [PATCH] Photos and Files for members now going in groups. Processing the member files and photos into groups now. --- models/admin/ajax/fileUpload.php | 12 ++- models/admin/import/index.php | 118 ++++++++++++++++++------- views/admin/import/filesProcess.html | 40 +++++++++ views/admin/import/filesValidate.html | 2 +- views/admin/import/header.html | 11 ++- views/admin/import/photosProcess.html | 18 +++- views/admin/import/process.html | 13 +-- views/admin/import/processMembers.html | 10 +-- 8 files changed, 176 insertions(+), 48 deletions(-) create mode 100644 views/admin/import/filesProcess.html diff --git a/models/admin/ajax/fileUpload.php b/models/admin/ajax/fileUpload.php index a91553c7..7e871f25 100644 --- a/models/admin/ajax/fileUpload.php +++ b/models/admin/ajax/fileUpload.php @@ -204,7 +204,17 @@ class GlmMembersAdmin_ajax_fileUpload extends GlmDataImages if ( isset( $_FILES['file'] ) ) { $fileUploaded = move_uploaded_file( $_FILES['file']['tmp_name'], GLM_MEMBERS_PLUGIN_FILES_PATH . '/'. $newFilename ); } else { - $fileUploaded = copy( $file['tmp_name'], GLM_MEMBERS_PLUGIN_FILES_PATH . '/'. $newFilename ); + // Use wordpress remote get method + $wp_response = wp_remote_get( $file['tmp_name'] ); + if ( is_array( $wp_response ) ) { + $fileContents = $wp_response['body']; + $fp = fopen( GLM_MEMBERS_PLUGIN_FILES_PATH . '/'. $newFilename, 'w' ); + fwrite( $fp, $fileContents ); + fclose( $fp ); + $fileUploaded = true; + } else { + $fileUploaded = false; + } } // If we have a good image diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 443560d8..edbfe471 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -102,6 +102,21 @@ class GlmMembersAdmin_import_index */ public $memberProcessCountPerRound = 20; + /** + * fileProcessCountPerRound + * + * @var float + * @access public + */ + public $fileProcessCountPerRound = 10; + /** + * photoProcessCountPerRound + * + * @var float + * @access public + */ + public $photoProcessCountPerRound = 10; + /** * numberProcessed * @@ -142,6 +157,14 @@ class GlmMembersAdmin_import_index */ public $photosProcessed = 0; + /** + * filesProcessed + * + * @var float + * @access public + */ + public $filesProcessed = 0; + /** * processingComplete * @@ -222,6 +245,12 @@ class GlmMembersAdmin_import_index if ( isset( $_REQUEST['numberProcessed'] ) ) { $this->numberProcessed = filter_var( $_REQUEST['numberProcessed'], FILTER_VALIDATE_INT ); } + if ( isset( $_REQUEST['photosProcessed'] ) ) { + $this->photosProcessed = filter_var( $_REQUEST['photosProcessed'], FILTER_VALIDATE_INT ); + } + if ( isset( $_REQUEST['filesProcessed'] ) ) { + $this->filesProcessed = filter_var( $_REQUEST['filesProcessed'], FILTER_VALIDATE_INT ); + } // $fileData - The main files needed for the member import // - field: input field name // - name: file name @@ -367,6 +396,8 @@ class GlmMembersAdmin_import_index $success = $this->processFile( $uploadPath . '/' . $file['name'], $file['type'] ); if ( $success ) { $fileData[$fileHeader]['results'] = "

$fileHeader file processed successfully.

"; + } else { + $fileData[$fileHeader]['results'] = "

$fileHeader failed.

"; } // Store the first files into wp options @@ -444,7 +475,7 @@ class GlmMembersAdmin_import_index // If the file validates then we're ready to process $readyToProcess = $isValid; // Set the view file - $view= 'photosValidate.html'; + $view = 'photosValidate.html'; $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; break; @@ -463,7 +494,7 @@ class GlmMembersAdmin_import_index // If the file validates then we're ready to process $readyToProcess = $isValid; // Set the view file - $view= 'filesValidate.html'; + $view = 'filesValidate.html'; $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; break; @@ -477,22 +508,31 @@ class GlmMembersAdmin_import_index require_once GLM_MEMBERS_PLUGIN_PATH . '/classes/data/dataMemberInfo.php'; $memberInfoObj = new GlmDataMemberInfo( $this->wpdb, $this->config ); + $start = 1; + if ( isset( $_REQUEST['start'] ) ) { + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + } + if ( is_file( $uploadPath . '/photoData.csv' ) ) { // Get the entire photo file data - $photoData = $this->readCSVFile( $uploadPath . '/photoData.csv' ); - //echo '
$photoData: ' . print_r( $photoData, true ) . '
'; + $photoData = $this->readCSVFile( $uploadPath . '/photoData.csv' ); $this->totalPhotos = count( $photoData ); - $this->photosProcessed = count( $photoData ); - $refType = $this->config['ref_type_numb']['MemberInfo']; + $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 ) . '
'; + // Find out how many are left to process. + $testEnd = $start + $this->photoProcessCountPerRound; + $ending = ( $testEnd <= $this->totalPhotos ) ? $testEnd : $this->totalPhotos; + + // We have to add one to $ending (array starts at 1 not 0). + $ending++; + for ( $index = $start; $index < $ending; $index++ ) { + //foreach ( $photoData as $photo ) { + $photo = $photoData[$index]; // 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( @@ -506,14 +546,12 @@ class GlmMembersAdmin_import_index 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, @@ -522,42 +560,56 @@ class GlmMembersAdmin_import_index $photo['caption'] ); } + $this->photosProcessed++; } // Set the view file - $view= 'photosProcess.html'; + $view = 'photosProcess.html'; } else { // Set the view file - $view= 'photosValidate.html'; + $view = 'photosValidate.html'; + } + // 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->photosProcessed == $this->totalPhotos ) { + $this->processingComplete = true; } break; case 'filesProcess': // Setup the file processing require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/fileUpload.php'; - $FileUpload = new GlmMembersAdmin_ajax_imageUpload($this->wpdb, $this->config); + $FileUpload = new GlmMembersAdmin_ajax_fileUpload($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 ); + $start = 1; + if ( isset( $_REQUEST['start'] ) ) { + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + } + if ( is_file( $uploadPath . '/filesData.csv' ) ) { // Get the entire files file data - $filesData = $this->readCSVFile( $uploadPath . '/filesData.csv' ); - //echo '
$filesData: ' . print_r( $filesData, true ) . '
'; - $this->totalFiles = count( $filesData ); - $this->filesProcessed = count( $filesData ); + $filesData = $this->readCSVFile( $uploadPath . '/filesData.csv' ); + $this->totalFiles = count( $filesData ); - $refType = $this->config['ref_type_numb']['MemberInfo']; + $refType = $this->config['ref_type_numb']['MemberInfo']; $refTable = $this->config['ref_type_table'][$refType]; // Loop through the filesData array - foreach ( $filesData as $file ) { - echo '
$file: ' . print_r( $file, true ) . '
'; + // Find out how many are left to process. + $testEnd = $start + $this->fileProcessCountPerRound; + $ending = ( $testEnd <= $this->totalFiles ) ? $testEnd : $this->totalFiles; + + // We have to add one to $ending (array starts at 1 not 0). + $ending++; + for ( $index = $start; $index < $ending; $index++ ) { + $file = $filesData[$index]; // If there's no url or the url is not valid then skip it. - if ( $fileUrl = filter_var( $file['image'], FILTER_VALIDATE_URL ) ) { - echo '
$fileUrl: ' . print_r( $fileUrl, true ) . '
'; + if ( $fileUrl = filter_var( $file['file_url'], FILTER_VALIDATE_URL ) ) { // Need to first get the member id from the database // It will match from the old_member_id field $memberId = $this->wpdb->get_var( @@ -571,37 +623,40 @@ class GlmMembersAdmin_import_index 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 = $FileUpload->storeFile( $fileUrl, $refType, $refTable, $memberInfoId, - $file['caption'] + $file['file_name'] ); } + $this->filesProcessed++; } // Set the view file - $view= 'filesProcess.html'; + $view = 'filesProcess.html'; } else { // Set the view file - $view= 'filesValidate.html'; + $view = 'filesValidate.html'; + } + // 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->filesProcessed == $this->totalFiles ) { + $this->processingComplete = true; } - $view= 'filesValidate.html'; break; case 'photos': // Set the view file - $view= 'photos.html'; + $view = 'photos.html'; unset( $fileData ); if ( is_file( $uploadPath . '/photoData.csv' ) ) { $fileExists = true; @@ -667,6 +722,7 @@ class GlmMembersAdmin_import_index 'totalPhotos' => $this->totalPhotos, 'totalFiles' => $this->totalFiles, 'photosProcessed' => $this->photosProcessed, + 'filesProcessed' => $this->filesProcessed, 'completed' => $this->processingComplete, 'data' => false, 'fileData' => $fileData, @@ -1028,7 +1084,7 @@ class GlmMembersAdmin_import_index // create truncated short_descr from descriptions - less tags, html encoded characters, newlines, tabs, etc. $stripped = str_replace( - php_eol, + PHP_EOL, '', preg_replace( '/\t+/', '', preg_replace( "/&#?[a-z0-9]{2,8};/i", "", strip_tags( $data['descr'] ) ) ) ); diff --git a/views/admin/import/filesProcess.html b/views/admin/import/filesProcess.html new file mode 100644 index 00000000..fc1d22da --- /dev/null +++ b/views/admin/import/filesProcess.html @@ -0,0 +1,40 @@ +{include file='admin/import/header.html'} + +

Data Import Step 3: Process Member Files

+ + + + + + + + + + + {if !$completed} + {$newStart = 1 + $filesProcessed} + + + + {/if} + + + {if $errors} + {foreach $errors as $error} + {$error} + {/foreach} + {/if} + +
Total Files{$totalFiles}
Processed Files{$filesProcessed}
+ Please wait - Loading ... +
+ + {if !$completed} + {$newStart = 1 + $filesProcessed} + + {/if} + +{include file='admin/footer.html'} diff --git a/views/admin/import/filesValidate.html b/views/admin/import/filesValidate.html index 1e2f502e..a340f3ec 100644 --- a/views/admin/import/filesValidate.html +++ b/views/admin/import/filesValidate.html @@ -1,6 +1,6 @@ {include file='admin/import/header.html'} -

Data Import: Photos Validation

+

Data Import: Files Validation

diff --git a/views/admin/import/header.html b/views/admin/import/header.html index db8fc9e1..4e38c07c 100644 --- a/views/admin/import/header.html +++ b/views/admin/import/header.html @@ -3,10 +3,15 @@

{$glmPluginName} CSV Import

diff --git a/views/admin/import/photosProcess.html b/views/admin/import/photosProcess.html index 26a69363..4127b08c 100644 --- a/views/admin/import/photosProcess.html +++ b/views/admin/import/photosProcess.html @@ -1,6 +1,6 @@ {include file='admin/import/header.html'} -

Data Import Step 3: Process Members

+

Data Import Step 3: Process Member Photos

@@ -11,6 +11,14 @@ + {if !$completed} + {$newStart = 1 + $photosProcessed} + + + + {/if} {if $errors} {foreach $errors as $error} @@ -20,4 +28,12 @@
Processed Photos {$photosProcessed}
+ Please wait - Loading ... +
+ {if !$completed} + {$newStart = 1 + $photosProcessed} + + {/if} + {include file='admin/footer.html'} diff --git a/views/admin/import/process.html b/views/admin/import/process.html index 1237fd02..9a4f3695 100644 --- a/views/admin/import/process.html +++ b/views/admin/import/process.html @@ -1,14 +1,15 @@ {include file='admin/import/header.html'}

Data Import Step 3: Process Files

- {foreach $fileData as $fileHeader => $file} - - - + {if isset($file.results)} + + + + {/if} {/foreach} {if $errors} diff --git a/views/admin/import/processMembers.html b/views/admin/import/processMembers.html index 63052c73..477d2da1 100644 --- a/views/admin/import/processMembers.html +++ b/views/admin/import/processMembers.html @@ -13,11 +13,11 @@ {if !$completed} {$newStart = 1 + $numberProcessed} - - - + + + {/if} {if $errors} -- 2.17.1
- {$file.results} -
+ {$file.results} +
- Process Next Count Members -
+ Please wait - Loading ... +