? NPM Resource Changed ? ? Pending

User tests: Successful: Unsuccessful:

avatar richard67
richard67
19 Jan 2020

Pull Request for Issue #27494 .

Summary of Changes

This Pull Request (PR) adds following to the Upload & Update tab of the Joomla Update Component:

  • Display of the selected upload file's size.
  • Check if the selected file is too big to be uploaded with respect to the PHP limits.

If the selected upload file is too big, a warning alert is shown. If the user tries to upload that file anway, the upload is rejected with an appropriate browser alert message.

The size of the selected file is always shown in MB because the PHP limits and so the maximum file size will with a 99.9 % likelyhood also be in MB.

For the Upload & Install Package tab of the Extension Installer I've created PR #27665 with similar changes, but there only the browser alert is implemented. Display of the size of the selected files is not really possible there.

Testing Instructions

Requirements: npm

  1. Apply patch of this PR.
  2. Run npm run build:js (or npm install if you prefer this).
  3. Clear browser cache to get rid of old cached JS.
  4. Go to administrator/index.php?option=com_joomlaupdate and there to tab "Upload & Update".
  5. Check the Joomla package file fields.
    Result: See section "Expected result" screenshot 1. No information related to the selected file's size is shown if no file is selected.
  6. Select a file which is not too big compared to the maximum upload size shown below the file selection.
    Hint: This can be any file, it doesn't necessarily have to be a Joomla Update package.
    Result: See section "Expected result" screenshot 2. The size of the selected file is shown below the maximum upload size.
  7. Select a file which is too big compared to the maximum upload size shown below the file selection.
    Hint: This can be any file, it doesn't necessarily have to be a Joomla Update package.
    Result: See section "Expected result" screenshot 3. The size of the selected file is shown below the maximum upload size, and below that a warning alert is shown telling that the selected file is too big.
  8. Try to upload the file anway by selecting the Upload & Install button.
    Result: See section "Expected result" screenshot 4. A browser alert is shown telling that the file can't be uploaded because it's too big. The upload is not started.
  9. Toggle the file selection a few times between too big and not too big file, and also between different files of each type.
    Result: The warning disappears when the selection is changed from too big to not too big, and it appears again when vice versa. The file size is updated with each change of the file.
  10. Finally select a valid Joomla Update package which is not too big and verify that uploading still works.
    Result: Uploading of not too big file still works as well as without this PR.

Expected result

  • No file selected:
    snap-01-no-file-selected
  • File size ok:
    snap-02-file-ok
  • File too big:
    snap-03-file-too-big
  • Broswer alert when trying to upload too big file:
    snap-04-file-too-big-upload

Actual result

See isue #27494

  • If post_max_size is big enough but upload_max_size is violated:
    j4_upload-max-filesize-violated_com-joomlaupdate
    Hint: The 403 and the missing language strings are separate issues not being fixed with this PR here. The 403 could also be related to a problem in my testing environment.

  • If upload_max_size is big enough but post_max_size is violated:
    Nothing happens, and PHP error log shows: PHP Warning: POST Content-Length of 22972015 bytes exceeds the limit of 16777216 bytes in Unknown on line 0, referer: ... (with byte figures suitable to your test).

Documentation Changes Required

Nothing special for this PR. The help screens for J4 backend have to be udpated anyway.

avatar richard67 richard67 - open - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 19 Jan 2020
Category Administration com_joomlaupdate Language & Strings JavaScript Repository NPM Change
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
Title
[4.0] [WiP] Add upload file size check to Joomla Update Component Upload & Update
[4.0] Add upload file size check to Joomla Update Component Upload & Update
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67
richard67 - comment - 19 Jan 2020

@brianteeman I'd be happy if you could find time and review language strings, and - what is more important - accessibility of the new fields, if necessary.

avatar richard67
richard67 - comment - 19 Jan 2020

@brianteeman P.S.: I'd also be happy if you could give feeback regarding point 2 in the "To be done" section of the description of this PR, if that alert div shall always be there and only visibility is changed with js like it is now, or if maybe the alert class also should be changed from warning to something else if that div is hidden, or how that is normally handled. Thanks in advance.

Update: Removed the "To be done" section because I have the feeling it might discourage people from testing. You'll see anyway if this PR does it in a good or a bad way when looking at the code changes.

avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67
richard67 - comment - 19 Jan 2020

@Fedik As you are very good in Joomla JS: Do you know if we already have something to make bytes nice, i.e. not show 16777216 bytes but 16 MB, or GB or whatever we have? I know it's not a big thing to write it bout would be pity to have duplicate functionality at several places.

avatar Fedik
Fedik - comment - 19 Jan 2020

Do you know if we already have something to make bytes nice, i.e. not show 16777216 bytes but 16 MB, or GB or whatever we have?

I did not seen such in Joomla code

avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 19 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 19 Jan 2020
avatar richard67 richard67 - change - 21 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 21 Jan 2020
avatar richard67 richard67 - change - 21 Jan 2020
Labels Added: ? NPM Resource Changed ?
avatar richard67 richard67 - change - 22 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 22 Jan 2020
avatar richard67 richard67 - change - 23 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 23 Jan 2020
avatar richard67 richard67 - change - 23 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 23 Jan 2020
avatar brianteeman
brianteeman - comment - 26 Jan 2020

@richard67 are you looking for this

* Creates the rounded size of the size with the appropriate unit
*
* @param float $max_size The maximum size which is allowed for the uploads
*
* @return string String with the size and the appropriate unit
*
* @since 3.4
*/
private static function parseSizeUnit($max_size)
{
$base = log($max_size) / log(1024);
$suffixes = array('', 'k', 'M', 'G', 'T');
return round(pow(1024, $base - floor($base)), 0) . $suffixes[floor($base)];
}

avatar brianteeman
brianteeman - comment - 26 Jan 2020

Other than comments about the strings and size it all seems to work fine

avatar richard67
richard67 - comment - 26 Jan 2020

@richard67 are you looking for this

* Creates the rounded size of the size with the appropriate unit
*
* @param float $max_size The maximum size which is allowed for the uploads
*
* @return string String with the size and the appropriate unit
*
* @since 3.4
*/
private static function parseSizeUnit($max_size)
{
$base = log($max_size) / log(1024);
$suffixes = array('', 'k', 'M', 'G', 'T');
return round(pow(1024, $base - floor($base)), 0) . $suffixes[floor($base)];
}

@brianteeman For same functionality but available in javascript so I can use it here: https://github.com/joomla/joomla-cms/pull/27570/files#diff-b155936a54bbb6b34c31eb456d23a45cR48. The actual file size is determined in javascript, so I can't prepare formatted output for it in PHP like I can with the maximum allowed file size.

avatar brianteeman
brianteeman - comment - 26 Jan 2020

sorry missed the js part of the question - something like this should do it

this.files[0].size/1024/1024 + "MB"

PS fileSizeAct - what does the Act mean/represent?

avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67
richard67 - comment - 26 Jan 2020

@brianteeman If I want to hard-code it to MB then yes, this works. But what if GB would be more suitable?

avatar richard67
richard67 - comment - 26 Jan 2020

@brianteeman "act" stands for "actual", i.e. size of actually selected file, on opposite to "max", which stands for the maximum allowed.

avatar richard67
richard67 - comment - 26 Jan 2020

@brianteeman Since the PHP limits are in almost all cases given in MB, do you think it's ok to hard-code the displayed size of the actually selected file always in MB, i.e. use your code above? If you think it's ok I'll update my PR to do so.

avatar brianteeman
brianteeman - comment - 26 Jan 2020

@brianteeman If I want to hard-code it to MB then yes, this works. But what if GB would be more suitable?

hardly likely that someone would try to load a file that large via a web browser. And if they really did try to then I am sure they would understand why 5000MB is too big

@brianteeman "act" stands for "actual", i.e. size of actually selected file, on opposite to "max", which stands for the maximum allowed.

Doesnt make sense to me - what is wrong with simply saying fileSize

avatar richard67
richard67 - comment - 26 Jan 2020

what is wrong with simply saying fileSize

@brianteeman Nothing wrong with that, I just thought fileSizeAct would be more precise. But if you think it is confusing I can change that. Readability of code is an important thing.

Other question: If I implement all changes suggested by you, will you then test this PR and mark the result in the issue tracker? ;-)

avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67
richard67 - comment - 26 Jan 2020

Implemented all changes suggested by @brianteeman . Thanks for review.

To him and all other readers: Please test (if you have npm).

avatar richard67
richard67 - comment - 26 Jan 2020

Updated also testing instructions (text and screenshots).

avatar richard67
richard67 - comment - 26 Jan 2020

@wilsonge Could you review again? I've made a few changes, see last commit message. Thanks in advance.

avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar richard67 richard67 - change - 26 Jan 2020
The description was changed
avatar richard67 richard67 - edited - 26 Jan 2020
avatar brianteeman brianteeman - test_item - 26 Jan 2020 - Tested successfully
avatar brianteeman
brianteeman - comment - 26 Jan 2020

I have tested this item successfully on 975fb9b


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/27570.

avatar brianteeman
brianteeman - comment - 26 Jan 2020

I have tested this item successfully on 975fb9b


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/27570.

avatar brianteeman
brianteeman - comment - 26 Jan 2020

LGTM
image

avatar richard67
richard67 - comment - 26 Jan 2020

@brianteeman Thanks a lot. If you have time and mood, could you also test my similar PR for the extensions installer, PR #27665 ?

avatar brianteeman
brianteeman - comment - 26 Jan 2020

already done

avatar jwaisner jwaisner - test_item - 26 Jan 2020 - Tested successfully
avatar jwaisner
jwaisner - comment - 26 Jan 2020

I have tested this item successfully on 975fb9b


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/27570.

avatar richard67 richard67 - change - 26 Jan 2020
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 26 Jan 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/27570.

avatar richard67
richard67 - comment - 26 Jan 2020

Thanks for testing.

avatar Quy Quy - change - 1 Feb 2020
Labels Added: ?
avatar Quy Quy - change - 1 Feb 2020
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2020-02-01 23:26:05
Closed_By Quy
avatar Quy Quy - close - 1 Feb 2020
avatar Quy Quy - merge - 1 Feb 2020
avatar richard67
richard67 - comment - 1 Feb 2020

Thanks.

Add a Comment

Login with GitHub to post a comment