From 5e0e3d299acf607165d2fd862685cdb854aaad47 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 23 Jun 2017 09:34:42 -0400 Subject: [PATCH] Making notes Adding comments. --- models/admin/import/index.php | 39 ++++++++++++++++++++++++++++++----- views/admin/import/index.html | 18 ++++++++++++---- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 357fad37..cf374eb2 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -198,6 +198,7 @@ class GlmMembersAdmin_import_index */ public function modelAction ($actionData = false) { + // Set the view file $view = 'index.html'; $failure = false; $option = 'default'; @@ -212,6 +213,12 @@ class GlmMembersAdmin_import_index if ( isset( $_REQUEST['numberProcessed'] ) ) { $this->numberProcessed = filter_var( $_REQUEST['numberProcessed'], FILTER_VALIDATE_INT ); } + // $fileData - The main files needed for the member import + // - field: input field name + // - name: file name + // - exists: Does file exists. Set to false at first. + // - validate: Validation array. Header line must match this. + // - type: Type of file. Used in the processing function. $fileData = array( 'Amenity' => array( 'field' => 'amenity_file', @@ -264,19 +271,29 @@ class GlmMembersAdmin_import_index ); $readyToProcess = false; + // Set the $option if found in $_REQUEST array if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') { $option = $_REQUEST['option']; } + // Set the $option2 if found in $_REQUEST array if (isset($_REQUEST['option2']) && $_REQUEST['option2'] != '') { $option2 = $_REQUEST['option2']; } + // Set variable for the upload directory $wpUploadDir = wp_get_upload_dir(); - $uploadPath = $wpUploadDir['basedir'] . '/' . 'glm-member-import'; + + // Set the $uploadPath for import files + $uploadPath = $wpUploadDir['basedir'] . '/' . 'glm-member-import'; + + // If the folder for the upload import files doesn't exists create one. if ( !is_dir( $uploadPath ) ) { + // Get old umask $oldMask = umask(0); + // Set folder permission mkdir( $uploadPath, 0770 ); + // reset old umask umask( $oldMask ); } @@ -284,6 +301,7 @@ class GlmMembersAdmin_import_index case 'validate'; $validFiles = 0; + // Set the view file $view = 'validate.html'; $fileCount = count( $fileData ); // Move any files uploaded @@ -315,7 +333,8 @@ class GlmMembersAdmin_import_index case 'process': $clearData = ( filter_var( $_REQUEST['clear_data'], FILTER_VALIDATE_BOOLEAN ) ); if ( $clearData ) { - // empty tables + // Empty the tables for the member data. + // Not including the management options. $this->wpdb->query('DELETE FROM ' . GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenity_ref'); $this->wpdb->query('DELETE FROM ' . GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenities'); $this->wpdb->query('DELETE FROM ' . GLM_MEMBERS_PLUGIN_DB_PREFIX . 'amenity_groups'); @@ -331,10 +350,11 @@ class GlmMembersAdmin_import_index $this->wpdb->query('DELETE FROM ' . GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_info'); $this->wpdb->query('DELETE FROM ' . GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members'); } - //exit; + + // Loop through the $fileData array. + // This will setup the wordpress options for each file. foreach ( $fileData as $fileHeader => $file ) { if ( is_file( $uploadPath . '/' . $file['name'] ) && $fileHeader != 'Member' ) { - //$fileData[$fileHeader]['results'] $success = $this->processFile( $uploadPath . '/' . $file['name'], $file['type'] ); if ( $success ) { $fileData[$fileHeader]['results'] = "

$fileHeader file processed successfully.

"; @@ -363,6 +383,7 @@ class GlmMembersAdmin_import_index if ( count( $this->errors ) == 0 ) { $readyToProcess = true; } + // Set the view file $view = 'process.html'; break; @@ -396,6 +417,7 @@ class GlmMembersAdmin_import_index if ( $this->numberProcessed == $this->totalMembers ) { $this->processingComplete = true; } + // Set the view file $view = 'processMembers.html'; break; @@ -412,6 +434,7 @@ class GlmMembersAdmin_import_index $isValid = ( $fData == $validate ); // If the file validates then we're ready to process $readyToProcess = $isValid; + // Set the view file $view= 'photosValidate.html'; $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; @@ -474,22 +497,27 @@ class GlmMembersAdmin_import_index } + // Set the view file $view= 'photosProcess.html'; } else { + // Set the view file $view= 'photosValidate.html'; } break; case 'photos': + // Set the view file $view= 'photos.html'; break; case 'files': + // Set the view file $view = 'files.html'; break; case 'default': default: + // Set the view file $view = 'index.html'; // check upload dir to see if they have any files in yet foreach ( $fileData as $fileHeader => $file ) { @@ -521,6 +549,7 @@ class GlmMembersAdmin_import_index 'haveMembers' => $haveMembers, 'isValid' => $isValid, ); + // Return status, suggested view, and data to controller return array( 'status' => true, @@ -593,7 +622,7 @@ class GlmMembersAdmin_import_index * Report errors in the $this->errors array. * * @param mixed $fileName File name for the csv file. - * @param mixed $type Type (category,amenity,city) + * @param mixed $type Type (category,amenity,city...) * @access public * @return void diff --git a/views/admin/import/index.html b/views/admin/import/index.html index 0c6e8608..18212bcd 100644 --- a/views/admin/import/index.html +++ b/views/admin/import/index.html @@ -6,10 +6,19 @@ - - {foreach $fileData as $fileHeader => $file} +
- + + + + + + {$count = 0} + {foreach $fileData as $fileHeader => $file} + + @@ -24,10 +33,11 @@ {/if} + {$count = $count + 1} {/foreach} - -- 2.17.1
{$fileHeader}File TypeNew FileCurrent FileUpdated
+ {$fileHeader} +
Clear Data +