327 Commits

Author SHA1 Message Date
Eloy Lafuente (stronk7)
361dfe8145
MDL-75952 general: Since php81, refection->setAccessible() is no-op
Refereces:
- https://wiki.php.net/rfc/make-reflection-setaccessible-no-op
- https://www.php.net/manual/en/reflectionproperty.setaccessible.php
- https://www.php.net/manual/en/reflectionmethod.setaccessible.php

As of PHP 8.1.0, calling this method has no effect; all methods are
invokable by default. So, let's remove all uses from core, they are
no-op.
2024-03-10 21:15:00 +01:00
Eloy Lafuente (stronk7)
29a541724f
MDL-65292 style: Fix all the function declaration ordering
This has been generated running the following Sniff,
part of the Moodle's CodeSniffer standard:
- PSR2.Methods.MethodDeclaration

It just ensures all the function declarations have
the correct order for:
- abstract and final.
- visibility (public, protected, private).
- static.

So, all the lines modified by this commit are function declarations
and the only changes are in the positions of those keywords.
2024-02-28 23:47:47 +01:00
meirzamoodle
a73e0ac76d MDL-74641 repository: Fix wrong increment of temporary file for small sizes 2024-02-07 02:34:19 +01:00
meirzamoodle
9ba1423359 MDL-74641 repository: Handles increase bytes while extracting zip files
We should not rely solely on the provided size information.
Therefore the system needs to recalculate the size of each file in the zip file,
whether small or big.

The changes also cover the filemanager.js file if an error appears.
2024-02-07 02:34:19 +01:00
Leon Stringer
a1a8facb9b MDL-80157 file: Exception message spelling 2023-11-17 12:49:42 +00:00
Paul Holden
b78663083f MDL-78647 files: safer unserializing of file reference data. 2023-08-09 04:44:18 +00:00
Paul Holden
85afb069a0
MDL-78644 files: more fault tolerant resizing of logos/icons.
If we cannot resize the given file (files such as ICO can't be, for
SVG it makes no sense), then we should just return the original file
as is rather than an error.
2023-07-05 00:54:03 +01:00
Stefan Hanauska
d23ad2c39a MDL-77152 files: Ensure trailing/leading slash 2023-06-24 10:32:05 +02:00
Eloy Lafuente (stronk7)
e4eb21e0ea MDL-78002 phpunit: Ensure that all uses of psr streams are closed
While the uses here were not causing too much problem with PHPUnit
execution in any OS, better have them explicitly closed to better
serve as reference for other, future uses anywhere in codebase.

Always that a stream is used, better we close it as soon as possible,
not relying on destructors, gc and friends.
2023-04-29 23:05:06 +02:00
Andrew Nicols
96a1a0abce MDL-77958 file: Add psr stream functionality to file API
This change introduces a new get_psr_stream() method to:
* stored_file
* file_system

This allows us to fetch a Psr Stream implementing the
PSR\Http\Message\StreamInterface and pass it into Guzzle, which means
that there is no need to load the entire file content into memory to
serve it.
2023-04-19 13:51:49 +08:00
Marina Glancy
8fc1486d36 MDL-77164 various: fix incorrect phpdocs 2023-04-13 11:35:06 +01:00
Andrew Nicols
9ec46c232d MDL-77186 core: Move all uses of cronlib to new class 2023-03-13 21:21:13 +08:00
sam marshall
201b6db1ac MDL-77149 core_files: Network filesystem (Amazon EFS) can warn
If you delete a file with a hash and then create another file with
the same hash, sometimes on EFS filesystems while trying to create
the new file, it returns true to the file_exists check even though
the file doesn't exist, but then fails other calls.

This change makes Moodle tolerate that behaviour.
2023-02-21 10:53:31 +00:00
Andrew Nicols
7000a99de3 MDL-76362 core: Coding style fixes 2023-01-23 09:15:55 +08:00
Marina Glancy
b0a83aa7bd MDL-76362 various: Avoid passing nulls to functions that don't allow nulls
PHP 8.1 is more strict on the parameter type. Functions such as trim(), strlen(), str_replace(), etc
show notice when null is passed as an argument
2023-01-23 09:15:54 +08:00
Sara Arjona
2ada61c243 Merge branch 'MDL-75448-master' of https://github.com/golenkovm/moodle 2022-11-10 13:19:38 +01:00
Jun Pataleta
58a92364ed Merge branch 'MDL-70368-cache-image-metadata' of https://github.com/brendanheywood/moodle 2022-10-21 09:07:58 +03:00
Marina Glancy
41b93bd7e5 MDL-73424 general: Internal methods must have same type as parent
Otherwise the error is thrown in PHP8.1
2022-10-10 16:46:13 +02:00
Brendan Heywood
fe88783c0f MDL-70368 files: Cache image dimensions 2022-09-19 13:21:20 +10:00
Sara Arjona
eef0a430be Merge branch 'MDL-75548' of https://github.com/timhunt/moodle 2022-09-05 13:09:09 +02:00
Eloy Lafuente (stronk7)
83b490a594 MDL-75111 phpunit: Move tests to use correct names and ns (take#4)
Applied the following changes to various testcase classes:

- Namespaced with component[\level2-API]
- Moved to level2-API subdirectory when required.
- Fixed incorrect use statements with leading backslash.
- Remove file phpdoc block
- Remove MOODLE_INTERNAL if not needed.
- Changed code to point to global scope when needed.
- Fix some relative paths and comments here and there.
- All them passing individually.
- Complete runs passing too.

Special mention to:

- The following task tests have been moved within the level2 directory:
  - \core\adhoc_task_test => \core\task\adhoc_task_test
  - \core\scheduled_task_test => \core\task\scheduled_task_test
  - \core\calendar_cron_task_test => \core\task\calendar_cron_task_test
  - \core\h5p_get_content_types_task_test => \core\task\h5p_get_content_types_task_test
  - \core\task_database_logger_test => \core\task\database_logger_test
  - \core\task_logging_test => \core\task\logging_test

- The following event tests have been moved within level2 directory:
  - \core\event_context_locked_test => \core\event\context_locked_test
  - \core\event_deprecated_test => \core\event\deprecated_test
  - \core\event_grade_deleted_test => \core\event\grade_deleted_test
  - \core\event_profile_field_test => \core\event\profile_field_test
  - \core\event_unknown_logged_test => \core\event\unknown_logged_test
  - \core\event_user_graded_test => \core\event\user_graded_test
  - \core\event_user_password_updated_test => \core\event\user_password_updated_test

- The following output tests have been moved within level2 directory:
  - \core\mustache_template_finder_test => \core\output\mustache_template_finder_test
  - \core\mustache_template_source_loader_test => \core\output\mustache_template_source_loader_test
  - \core\output_mustache_helper_collection_test => \core\output\mustache_helper_collection_test

- The following tests have been moved to their correct tests directories:
  - lib/tests/time_splittings_test.php => analytics/tests/time_splittings_test.php

- All the classes and tests under lib/filebrowser and lib/filestorage
  belong to core, not to core_files. Some day we should move
  them to their correct subsystem.
- All the classes and tests under lib/grade belong to core, not
  to core_grades. Some day we should move them to their correct
  subsystem.
- The core_grades_external class and its \core\grades_external_test
  unit test should belong to the grades subsystem or, alternatively,
  to \core\external, they both should be moved together.
- The core_grading_external class and its \core\grading_external_test
  unit test should belong to the grading subsystem or, alternatively,
  to \core\external, they both should be moved together.
- The \core\message\message and \core\message\inbound (may be others)
  classes, and their associated tests should go to the core_message
  subsystem.
- The core_user class, and its associated tests should go to the
  core_user subsystem.
- The \core\update namespace is plain wrong (update is not valid API)
  and needs action 1) create it or 2) move elsewhere.
2022-08-26 16:34:20 +02:00
Tim Hunt
797b9fbd62 MDL-75548 misc: final Required parameter follows optional notices 2022-08-22 15:20:13 +01:00
Mikhail Golenkov
aeda4b9a87 MDL-75448 stored_file: Cover rotate_image() method with unit tests 2022-08-19 15:39:06 +10:00
Sujith Haridasan
73d604369d MDL-71062 core: Step 1 deprecation of print_error function 2022-07-13 08:20:54 +05:30
Andrew Nicols
bb9741d472 MDL-72701 unit tests: Fix broken @covers annotations 2021-12-21 09:24:00 +08:00
Sara Arjona
5ae7fa42b7 NOBUG: Fixed SVG browser compatibility 2021-11-26 15:26:18 +01:00
Paul Holden
143c80e229 MDL-72443 files: support svg preview as with other image types. 2021-11-12 15:07:02 +00:00
Sara Arjona
27243e2ff7 Merge branch 'MDL-71991' of https://github.com/timhunt/moodle 2021-06-30 16:09:30 +02:00
Eloy Lafuente (stronk7)
a12cac8724 NOBUG: Fixed SVG browser compatibility 2021-06-24 23:03:02 +02:00
Huong Nguyen
816aa7aec2 MDL-55243 files: Make is_valid_image support SVG files 2021-06-24 09:02:05 +07:00
Tim Hunt
1af25720b0 MDL-71991 files: check return value of rename when writing files 2021-06-22 19:36:09 +01:00
Víctor Déniz
162278e69a Merge branch 'MDL-70864-master-zip_packer_windows' of git://github.com/mudrd8mz/moodle 2021-05-05 00:01:28 +01:00
Shamim Rezaie
9c11ceac1f MDL-69028 repository: Put a rate limit on draft file uploads 2021-05-04 17:23:11 +02:00
David Mudrák
260c2bdb00 MDL-70864 files: Fix zip_packer extracting files with trailing dots
File and folder names cannot end with dots on Windows. So replace the
trailing dots with underscore consistently with how some other zip tools
(such as 7-zip) handle this case.
2021-05-03 18:13:14 +02:00
Eloy Lafuente (stronk7)
e3a46964dc Merge branch 'MDL-70901-master' of git://github.com/marinaglancy/moodle 2021-03-18 00:40:46 +01:00
Eloy Lafuente (stronk7)
81407f18ec MDL-71036 phpunit: Mock->setMethods() silently deprecated
The current ->setMethods() has been silently (won't emit any
warning) in PHPUnit 9. And will stop working (current plans)
in PHPUnit 10.

Basically the now deprecated method has been split into:

- onlyMethods(): To point to existing methods in the mocked artifact.
- addMethods(): To point to non existing (yet) methods in the mocked
  artifact.

In practice that means that all our current setMethods() calls can be
converted to onlyMethods() (existing) and done. The addMethods() is
mostly useful on development phases, not final testing.

Finally note that <null> isn't accepted anymore as parameter to
double all the methods. Instead empty array [] must be used.

Link: https://github.com/sebastianbergmann/phpunit/issues/3770
2021-03-11 23:04:31 +01:00
Eloy Lafuente (stronk7)
ba5b6089d5 MDL-71036 phpunit: Renamed various regexp-related assertions
In PHPUnit 9.1, the following regexp-related assertions
have been deprecated and there are new alternatives for
all them:
    - assertRegExp()     -> assertMatchesRegularExpression()
    - assertNotRegExp()  -> assertDoesNotMatchRegularExpression()

This is about to, simply, move all cases to the new alternatives.

Source: https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md

Regexp to find all them:

    ag 'assertRegExp|assertNotRegExp' -li
2021-03-11 19:22:24 +01:00
Eloy Lafuente (stronk7)
309a65a6f7 MDL-71036 phpunit: Renamed various file-related assertions
In PHPUnit 9.1, the following file-related assertions
have been deprecated and there are new alternatives for
all them:
- assertNotIsReadable()         -> assertIsNotReadable()
- assertNotIsWritable()         -> assertIsNotWritable()
- assertDirectoryNotExists()    -> assertDirectoryDoesNotExist()
- assertDirectoryNotIsReadable()-> assertDirectoryIsNotReadable()
- assertDirectoryNotIsWritable()-> assertDirectoryIsNotWritable()
- assertFileNotExists()         -> assertFileDoesNotExist()
- assertFileNotIsReadable()     -> assertFileIsNotReadable()
- assertFileNotIsWritable()     -> assertFileIsNotWritable()

This is about to, simply, move all cases to the new alternatives.

Source: https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md

Regexp to find all them:

ag 'assertNotIsReadable|assertNotIsWritable|assertDirectoryNotExists|\
assertDirectoryNotIsReadable|assertDirectoryNotIsWritable|\
assertFileNotExists|assertFileNotIsReadable|assertFileNotIsWritable'
2021-03-11 19:22:23 +01:00
Sara Arjona
b64ee9ecf3 Merge branch 'MDL-70877' of https://github.com/stronk7/moodle 2021-03-02 09:29:17 +01:00
Marina Glancy
a7553de7ad MDL-70877 php: remove final functions __clone and __wakeup
Implementing these functions as final does not prevent the object to be
cloned or serialized, so the comment to them was wrong.
However having these functions not public breaks in PHP 8.0.
It still does not make sense to clone or serialise file_system or external_settings classes
but there are a lot of classes in moodle that should not be cloned, no reason to have
a specific solution here.
2021-02-26 13:07:52 +01:00
David Mudrák
0c9eaeff59 MDL-70964 lang: Use the fixed strings in tests 2021-02-25 16:20:58 +01:00
Marina Glancy
b88f1a84bf MDL-70901 core: @ no longer masks errors in PHP 8.0 2021-02-22 16:18:46 +01:00
Marina Glancy
a1a72f720e MDL-70901 core_files: @ does no mask errors in php8 anymore 2021-02-22 16:17:49 +01:00
David Mudrák
6109e8b272 MDL-70631 files: Replace hard-coded value with FL_ENC_RAW constant
This is not related to the issue but I noticed it while trying to debug
it.

Back when this line was introduced in 9c140a681e9, the ZipArchive had
not yet exposed this flag as a constant. It was added later with PHP
7.0.8 and we can switch to using it now.
2021-02-03 16:06:39 +01:00
David Mudrák
b227b6ea45 MDL-70631 files: Fix performance of zip_packer::extract_to_pathname()
The original implementation was based on ZipArchive::getStream() which
turns out to be very slow and if the archive contains many files, the
unzipping performance is very slow.

The patch changes the implementation to use ZipArchive::extractTo()
unless the extracted entry path contains a folder name ending with dot
(such as some/path./to/file.txt). There is a known upstream bug in the
PHP ZIP extension #77214 (also #74619 and #69477) so that we fall back
to keep using the stream in those cases.
2021-02-03 16:06:39 +01:00
Eloy Lafuente (stronk7)
40de097e65 MDL-67673 phpunit: Remove deprecated assertContains() uses on strings
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: https://github.com/sebastianbergmann/phpunit/issues/3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
d95c378771 MDL-67673 phpunit: Remove expectedException annotations
While this is not strictly required, because removal will
happen in PHPUnit 9.0, we are already getting rid of all
uses in core.

From release notes:https://phpunit.de/announcements/phpunit-8.html

The annotations `@expectedException`, `@expectedExceptionCode`,
`@expectedExceptionMessage`, and `@expectedExceptionMessageRegExp`
are now deprecated.
Using these annotations will trigger a deprecation warning
in PHPUnit 8 and in PHPUnit 9 these annotations will be removed.

Also, all uses of expectExceptionMessageRegExp() has been moved
to expectExceptionMessageMatches(). See https://github.com/sebastianbergmann/phpunit/issues/3957

TODO: Various weirdness found while doing the changes with these tests:
- vendor/bin/phpunit lib/tests/exporter_test.php (created MDL-69700)
- vendor/bin/phpunit competency/tests/external_test.php (same issue than prev one)
- vendor/bin/phpunit question/engine/tests/questionengine_test.php (created MDL-69624)
- vendor/bin/phpunit lib/tests/event_test.php (created MDL-69688)
2020-10-21 12:46:00 +02:00
Eloy Lafuente (stronk7)
f6711bb394 MDL-67673 phpunit: Fix the return type of template methods
All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.

At the same time, fix a few wrong function names,
provider data and param types, return statements...
2020-10-21 12:45:59 +02:00
Paul Holden
582bb534c9 MDL-37802 repository: return error if unzipping files fails.
For instance, when a user tried to unzip a password protected zip
archive using the file manager.
2020-09-25 09:33:44 +01:00
Mihail Geshoski
09a55f952e MDL-65115 core_files: Add get_total_content_size() in stored_file class
New function get_total_content_size() is introduced in the stored_file
class. The puprose of this function is to calculate and return the
total size (in bytes) of the content of an archive file.
2020-09-08 08:54:26 +02:00