Updating the photos import
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 29 Jun 2017 18:33:30 +0000 (14:33 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 29 Jun 2017 18:33:30 +0000 (14:33 -0400)
Bumping up the per process count to 40 for photos and files.

models/admin/ajax/imageUpload.php
models/admin/import/index.php
views/admin/import/photosProcess.html

index fd2ba6a..96ec13d 100644 (file)
@@ -217,6 +217,7 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages
 
             // Finally, move the files to the various size directories and rename them back to the correct name
             reset ($this->config['imageSizes']);
+
             while (list($k, $v) = each($this->config['imageSizes'])) {
 
                 // Check if size directory needs to be made
@@ -226,14 +227,19 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages
 
                 // If there's an entry in the $sizes array, it means that the image resized to this size
                 if (isset($sizes[$k])) {
-                        // Move resized file to desired direectory
-                    rename(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$sizes[$k]['file'], GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
+                    // Copy resized file to desired directory
+                    copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$sizes[$k]['file'], GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
                 } else {
                     // Image didn't resize to this size, probably because it was smaller than the destination size (silly WP Image Editor class) - so just use the original
                     copy(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$newFilename, GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/'.$k.'/'.$newFilename);
                 }
 
             }
+            // Since we copied the files from the main images directory we need
+            // some clean-up here.
+            foreach ( $sizes as $imgSize => $imgData ) {
+                @unlink( GLM_MEMBERS_PLUGIN_IMAGES_PATH . '/' . $imgData['file'] );
+            }
 
             // Move the original to original directory
             if (!file_exists(GLM_MEMBERS_PLUGIN_IMAGES_PATH.'/original')) {
index f009a3b..35ceb2b 100644 (file)
@@ -108,14 +108,14 @@ class GlmMembersAdmin_import_index
      * @var float
      * @access public
      */
-    public $fileProcessCountPerRound = 10;
+    public $fileProcessCountPerRound = 40;
     /**
      * photoProcessCountPerRound
      *
      * @var float
      * @access public
      */
-    public $photoProcessCountPerRound = 10;
+    public $photoProcessCountPerRound = 40;
 
     /**
      * numberProcessed
@@ -530,8 +530,8 @@ class GlmMembersAdmin_import_index
                 // 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];
+                    $this->photosProcessed++;
                     // 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
@@ -553,15 +553,20 @@ class GlmMembersAdmin_import_index
                         if ( !$memberInfoId ) {
                             continue;
                         }
+                        // There's a character limit on the photo caption field
+                        // of 255 (mysql TINYTEXT)
+                        $caption = substr( $photo['caption'], 0, 250 );
                         $res = $ImageUpload->storeImage(
                             $photoUrl,
                             $refType,
                             $refTable,
                             $memberInfoId,
-                            $photo['caption']
+                            $caption
                         );
+                        if ( !$res ) {
+                            $this->errors = true;
+                        }
                     }
-                    $this->photosProcessed++;
 
                 }
 
@@ -609,6 +614,7 @@ class GlmMembersAdmin_import_index
                 $ending++;
                 for ( $index = $start; $index < $ending; $index++ ) {
                     $file = $filesData[$index];
+                    $this->filesProcessed++;
                     // If there's no url or the url is not valid then skip it.
                     if ( $fileUrl = filter_var( $file['file_url'], FILTER_VALIDATE_URL ) ) {
                         // Need to first get the member id from the database
@@ -638,7 +644,6 @@ class GlmMembersAdmin_import_index
                             $file['file_name']
                         );
                     }
-                    $this->filesProcessed++;
 
                 }
 
index 4127b08..8d16cfe 100644 (file)
@@ -28,7 +28,7 @@
 
     </table>
 
-    {if !$completed}
+    {if !$completed && !$errors}
             {$newStart = 1 + $photosProcessed}
     <script>
     var test = '{$thisUrl}?page={$thisPage}&glm_action=index&option=photosProcess&start={$newStart}&photosProcessed={$photosProcessed}';