*

webcity

  • ****
  • 220 posts
Osclass 8.2.0 Image count error
« on: November 25, 2023, 01:43:02 AM »
Hi,

Thanks for the recent update, the new uppy.io image uploader is great :-) .

I'm getting a small problem with half the images not uploading. When I upload say 15 images, uppy.io converts them OK, I see 15 images ready to upload, when I click the Submit button it only uploads half the number of images, in this case 8 images.

I've removed the
Code: [Select]
$newUploadImages++; that was mentioned earlier, this hasn't resolved the problem.

Can anyone suggest a solution?

Many thanks

*

webcity

  • ****
  • 220 posts
Re: Osclass 8.2.0 Image count error
« Reply #1 on: November 25, 2023, 02:21:23 AM »
Hi,

Further to my last message.

I'm using APCu for my cache, when the cache clears the missing images appear.

So if I upload 15 images, the listing shows only 8 images, 15 images are showing in the Media manager, then if I clear the APCu cache then the 15 images show in the listing.

*

MB Themes

Re: Osclass 8.2.0 Image count error
« Reply #2 on: November 25, 2023, 01:44:37 PM »
This is final look of uploadItemResources function
Code: [Select]
  public function uploadItemResources($aResources, $itemId) {
    if(is_array($aResources) && !empty($aResources)) {
      $limit_reached = false;
      $itemResourceManager = ItemResource::newInstance();
      $folder = osc_uploads_path() . floor($itemId / 100) . '/';
      $maxImagesPerItem = osc_max_images_per_item();
      $totalItemImages = $itemResourceManager->countResources($itemId);
      $newUploadImages = 0;
     
      foreach($aResources['error'] as $key => $error) {
        if($maxImagesPerItem == 0 || ($maxImagesPerItem > 0 && ($totalItemImages + $newUploadImages) < $maxImagesPerItem)) {
          if($error == UPLOAD_ERR_OK) {
            $tmpName = $aResources['tmp_name'][$key];
            $order = $aResources['order'][$key];
            $imgres = ImageProcessing::fromFile($tmpName);
            $extension = osc_apply_filter('upload_image_extension', $imgres->getExt());
            $mime = osc_apply_filter('upload_image_mime', $imgres->getMime());

            // Create normal size
            $normal_path = $path = $tmpName . '_normal';
            $size = explode('x', osc_normal_dimensions());
            $img = $imgres->autoRotate();

            $img = $img->resizeTo($size[0], $size[1]);
           
            if (osc_is_watermark_text()) {
              $img->doWatermarkText(osc_watermark_text(), osc_watermark_text_color());
            } elseif (osc_is_watermark_image()) {
              $img->doWatermarkImage();
            }
           
            $img->saveToFile($path, $extension);

            // Create preview
            $path = $tmpName . '_preview';
            $size = explode('x', osc_preview_dimensions());
            ImageProcessing::fromFile($normal_path)->resizeTo($size[0], $size[1])->saveToFile($path, $extension);

            // Create thumbnail
            $path = $tmpName . '_thumbnail';
            $size = explode('x', osc_thumbnail_dimensions());
            ImageProcessing::fromFile($normal_path)->resizeTo($size[0], $size[1])->saveToFile($path, $extension);

            $newUploadImages++;
           
            $itemResourceManager->insert(array('fk_i_item_id' => $itemId));
            $resourceId = $itemResourceManager->dao->insertedId();

            if (!is_dir($folder)) {
              if (!@mkdir($folder, 0755, true)) {
                return 3; // PATH CAN NOT BE CREATED
              }
            }
           
            $copy_options = array('folderPermission' => 0755, 'filePermission' => 0644);
           
            osc_copy($tmpName . '_normal', $folder . $resourceId . '.' . $extension, $copy_options);
            osc_copy($tmpName . '_preview', $folder . $resourceId . '_preview.' . $extension, $copy_options);
            osc_copy($tmpName . '_thumbnail', $folder . $resourceId . '_thumbnail.' . $extension, $copy_options);
           
            if (osc_keep_original_image()) {
              $path = $folder . $resourceId . '_original.' . $extension;
              osc_copy($tmpName, $path, $copy_options);
            }
           
            @unlink($tmpName . '_normal');
            @unlink($tmpName . '_preview');
            @unlink($tmpName . '_thumbnail');
            @unlink($tmpName);

            $s_path = str_replace(osc_base_path(), '', $folder);
            $itemResourceManager->update(
              array(
                's_path' => $s_path,
                's_name' => osc_genRandomPassword(),
                's_extension' => $extension,
                's_content_type' => $mime,
                'i_order' => $order
              ),
              array(
                'pk_i_id' => $resourceId,
                'fk_i_item_id' => $itemId
              )
            );
           
            osc_run_hook('uploaded_file', ItemResource::newInstance()->findByPrimaryKey($resourceId));
          }
        } else {
          // images per item limit reached
          $limit_reached = true;
        }
      }
     
      if($limit_reached) {
        osc_add_flash_warning_message(_m('Image limit reached, some images were not uploaded!'));
      }
     
      unset($itemResourceManager);
    }

    return 0; // NO PROBLEMS
  }
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

webcity

  • ****
  • 220 posts
Re: Osclass 8.2.0 Image count error
« Reply #3 on: November 25, 2023, 03:24:14 PM »
Thanks for your help.

I've disabled APCu and the image uploads now work as they should, no missing images after pressing the submit button. When I re-enable the APCu cache the problem returns.

I didn't have this problem with the previous release.

APCu does really increase the speed of my site, so it would be great to get it working properly with this new release.

Many thanks

*

MB Themes

Re: Osclass 8.2.0 Image count error
« Reply #4 on: November 26, 2023, 11:43:29 AM »
@webcity
Clean cache. There is no magic behind this bug.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots