340 Commits

Author SHA1 Message Date
Huong Nguyen
d3e4821bc7 Merge branch 'MDL-80206-main' of https://github.com/andrewnicols/moodle 2024-03-18 09:42:06 +07:00
Ilya Tregubov
5c0ad525b0 Merge branch 'MDL-81035-main' of https://github.com/HuongNV13/moodle 2024-03-12 10:40:26 +08:00
Andrew Nicols
d5ec9d695f
MDL-80206 core: Allow debugging to be treated as an error 2024-03-11 22:35:47 +08:00
Huong Nguyen
a7503b01ce MDL-81035 core: Fix redirect with sub-path 2024-03-11 15:56:06 +07:00
Eloy Lafuente (stronk7)
78b5db34a8
MDL-81124 install: Enable is_major_upgrade_required for 4.4dev
Setting it to 2024010400.00 that is the week when MDL-80186 landed.
2024-03-08 17:20:45 +01:00
Brendan Heywood
ccac5c1a20 MDL-80823 core: Redirect to wwwroot with full path 2024-02-05 16:07:36 +11:00
Andrew Nicols
7b7b618b96
MDL-80215 core: Use correct behat constant 2023-11-22 09:00:35 +08:00
Andrew Nicols
eddae1808b
MDL-79974 core: Add Whoops when debugging
Whoops will only be used under the following conditions:

- Not an AJAX request
- Not a CLI usage
- debugdisplay is set
- composer dependencies are installed
- Whoops is available
- The configuration setting is enabled
2023-11-05 21:23:18 +08:00
Andrew Nicols
99a6cd12b2
MDL-79637 phpunit: Do not reset DB during init of isolated tests
During the bootstrap of PHPUnit we ensure that the database has been
reset to its initial state.

We do this by checking the internally-stored DB write count between
runs. If the count is not yet set (null), or it has been increased, we
force a reset.

When running an isolated test the test runner resets the database, it
then sets up a new isolated test environment by writing a new PHPUnit
test case and passing it to a new PHP Process using standard in. As part
of this, the bootstrap is run for that process.

Because we are in a new process, the db write count is fresh and not yet
set. This has been leading to an additional db reset before the isolated
test.

To handle this we want to _not_ perform a reset during the
initialisation for isolated runs. We know that the DB is in a fresh
state before we start the run.

To support this we need to know whether the test is an isolated test
during the bootstrap, which means we cannot use the previous approach to
calculating this.

Instead we look at the PHP_SELF value. PHP sets this to "Standard input
code" when run from stdin, instead of running a file.

There should not be any other legitimate reason to run a PHPUnit
bootstrap via this stdin approach.

Unfortunately this approach is a little bit risky as it depends on the
presence of a specific string, however this string has been in place
since 2016, and there is no legitimate way of calculating this.

I did consider looking at whether the called script included `/vendor/`
and `/phpunit`, but this is also likely a risky approach if someone
calls PHPUnit in an unexpected way.

This approach is itself unit tested so any change to PHP's stdin string
before we deprecate this approach entirely in 12 months time will be
caught.
2023-10-11 09:29:26 +08:00
Sara Arjona
cc9430929d
MDL-77708 docs: Update references from docs.moodle.org/dev 2023-09-26 10:30:19 +02:00
Paul Holden
2518317649
MDL-75371 core: fix typos in reverse proxy setup docs. 2023-09-06 14:38:08 +01:00
Paul Holden
4be889a1c7
Merge branch 'patch-1' of https://github.com/ewjoachim/moodle 2023-09-06 14:25:57 +01:00
Petr Skoda
3c25ccdcd1 MDL-78552 core: tidy up MDL_PERF constants
* all constans usable in ABORT_AFTER_CONFIG should be always defined
* MDL_PERFDB and $PERF->logwrites not used after legacy log removal
* MDL_PERF_TEST should be documented in codebase
* deprecated warnings in shutdowb manager
2023-06-25 08:39:09 +02:00
Andrew Nicols
1a53cbbae4 MDL-77989 testing: Add test file isolation helper
When we deprecate the use of a file, we often include tests which ensure
that the legacy behaviour is maintained. There are also legacy uses
in the community where people would like to use the deprecated API for a
period.

The issue that we face is that, if the deprecated file is included once,
then it will be included for all other, unrelated, tests. This means
that other tests may not detect cases where the deprecated file was
included.

We can solve these cases by running the test that performs the inclusion
in a deprecated process. This means that the inclusion is only performed
in that isolated process, and other unrelated tests do not include the
file.

However, we also then need to detect which files which are including the
file and which we do not know about.

This change introduces:
- an override to the TestCase::setInIsolation method to define a
  constant when the test is running in isolation
- a new function that a file can call when it is included, to make sure
  that the test process was isolated, where there is any test.
2023-04-21 13:33:56 +08:00
Petr Skoda
f0613d1bfa MDL-75005 core: remove invalid addslashes() 2023-02-17 09:50:06 +01: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
Tim Hunt
192f993906 MDL-76649 quiz statistics task: output more useful trace info
At the moment, quiz_statistics\task\recalculate gives no useful
information about what it is doing, which makes it hard to investigate
if the task fails. This commit makes it more usefully verbose.

Also, following this change, one instance of this task will not
run for more than one hour at a time.

As part of this commit, I have added a new helper mtrace_exception.
to consistently log exceptions in scheduled tasks. It is sad to
add a new function to moodlelib.php, but that seemed the logical place.
Looking at other tasks, this method is badly needed. Many are just
logging the ->getMessage() which is normaly insufficient for proper
debugging. However, swiching all existing tasks to use the new function
will need to wait for a future MDL.
2023-01-09 13:26:41 +00:00
Sara Arjona
d5b3abde3c Merge branch 'MDL-76166-username-logging' of https://github.com/brendanheywood/moodle 2022-12-05 12:44:17 +01:00
Jun Pataleta
3947ad99c1 Merge branch 'MDL-76483-master' of https://github.com/andrewnicols/moodle 2022-12-01 08:55:34 +03:00
Brendan Heywood
825d11ec50 MDL-76166 auth: Ensure user is in server access logs 2022-11-30 13:25:20 +11:00
Marina Glancy
a800e7e62f MDL-74853 various: add second parameter to htmlentities functions
Default value of the $flag argument changed in PHP 8.1 from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE
To ensure consistent behavior across different PHP version the second parameter is now required for the functions:
htmlspecialchars(), htmlentities(), htmlspecialchars_decode(), html_entity_decode() and get_html_translation_table()
2022-11-28 16:12:20 +01:00
Andrew Nicols
6eccbc7af5 MDL-76483 core: Handle default value for get_docs_url() 2022-11-25 22:19:04 +08:00
Ilya Tregubov
3f568024a1 MDL-76033 core: bump version in is_major_upgrade_required
MDL-58266 changes db structure. So upgrade must happen before
accessing any page.
2022-10-19 15:08:44 +03:00
Brendan Heywood
11efc67eb5 MDL-75614 dml: Fixed debugsqltrace with anon classes bug 2022-09-02 11:42:04 +10:00
Joachim Jablon
42c69bd155
MDL-75371: Remove unrespectful language from code comment
https://tracker.moodle.org/browse/MDL-75371
2022-08-04 09:55:24 +02:00
Sujith Haridasan
73d604369d MDL-71062 core: Step 1 deprecation of print_error function 2022-07-13 08:20:54 +05:30
Brendan Heywood
9fa26ed911 MDL-72486 core: Add unsafe log and fix options to proxy settings 2022-06-20 11:18:42 +10:00
sam marshall
3776b5542f MDL-74032 core_cache: Coding error before upgrade with versioned cache
In certain cases where it doesn't already redirect to run the upgrade,
users could see an exception 'Unexpectedly found non-versioned cache
entry'. This change ensures the upgrade happens instead.
2022-03-09 12:11:14 +00:00
Cameron Ball
776bfb134c MDL-73427 core: Remove $SESSION->fromurl 2022-01-05 19:39:21 +08:00
Jason den Dulk
e7f51a3857 MDL-68199 setup: Fix invalid parameters to make_request_directory()
Added parameter type hint to make_request_directory()
Removed invalid parameters from calls to make_request_directory()

Removing these parameters should have no effect on behaviour.
2021-12-02 07:49:28 +11:00
Eloy Lafuente (stronk7)
4c0ae3e138 MDL-73098 install: Detect stale bootstrap.php files and disable them
It's important to say that this bug apparently (till now) only happens
when an *incorrect* instalation of a site happens, reusing the dataroot
from another existing site.

When that happens, the localcache/bootstrap.php file from the old
site is reused, setting siteidentifier and SYSCONTEXTID when it's not
time for them to be defined yet.

Their existenece leads to reusing some other structures from the old
dataroot (that, again, should have been changed or wiped!), ultimately
leading to all sort of errors about non-existent tables (course,
context...).

With this change we ensure that:

1) Whenever any change to the database configuration (prefix, user,
   type..) happens, it's detected and immediately the information
   in the localcache/bootstrap.php is discarded and the file removed.
   This should fix problems like MDL-73098 itself.

2) We only set SYSCONTEXTID if the file is not stale. Main reason
   for doing that check within the localcache/bootstrap.php file
   itself is that we cannot "undefine" it @ setup.php. This should
   prevent errros like MDL-72888 to happen.

3) Finally, little detail, we only define SYSCONTEXTID if it has
   not been defined earlier. In the past, it was recommended to
   define it in config.php (exactly to save one DB read) and, sites
   having them will face "already defined" warnings.
2021-11-17 20:56:36 +01:00
Ilya Tregubov
1025ed1c22 MDL-72851 core: Bump $lastmajordbchanges to trigger upgrade immediately.
Fixing regression of MDL-52206.
2021-10-19 16:40:42 +02:00
Brendan Heywood
7b938088b5 MDL-71014 core: Cache immutable bootstrap config locally 2021-09-02 13:22:28 +10:00
Sujith Haridasan
fbc7b28614 MDL-67412 setuplib: Final deprecation of generate_uuid
Final deprecation of generate_uuid function.
2021-08-03 08:32:01 +05:30
Matteo Scaramuccia
7910fa322a MDL-63770 core: 'port' should be an integer like in parse_url()
Plus trivial comment cleanup.
2021-07-15 11:37:13 +08:00
Dmitri Pisarev
1983718149 MDL-63770 core: Fix a false-positive in reverseproxyabused check
A `reverseproxyabused` error is wrongly triggered when external port number doesn't equal internal.
2021-07-12 11:23:49 +02:00
Jess Ansell
52bc582e77 MDL-71012 setup: Return 500 error code for setup errors. 2021-03-22 14:05:45 +00:00
Eloy Lafuente (stronk7)
08ae245926 MDL-70876 php80: 5th param removed from custom error handlers
It was deprecated in php72 and now it's gone.

Have used this regexp to find all the uses in core:

ag set_error_handler | uniq

And then checked all them manually, that parameter was not
being used in the 3 methods where we are removing it.
2021-02-26 13:08:27 +01:00
Brendan Heywood
10f33b6fdc MDL-69975 core: Fix paths longer than 260 chars on windows
Also, ensure that remove_dir() only processes directories,
because sometimes it was being called by shutdown managers
with files, leading to PHP warnings.

Co-authored-by: Eloy Lafuente (stronk7) <stronk7@moodle.org>
Co-authored-by: Jun Pataleta <jun@moodle.com>
2020-11-01 11:02:00 +01:00
Brendan Heywood
9fabe1dda5 MDL-66928 core: Move request dirs to system tmp instead of localcache 2020-10-13 14:17:39 +11:00
Brendan Heywood
6e935cc29c MDL-69718 core: Added support for TB and PT to display_size 2020-09-21 11:02:16 +10:00
Jake Dallimore
7a40781aeb Merge branch 'MDL-56041-custom-error-pages' of https://github.com/brendanheywood/moodle 2020-07-08 09:33:46 +08:00
Brendan Heywood
43999a3f2b MDL-56041 error: Enable custom 404 and 500 error pages 2020-07-08 09:36:21 +10:00
Matteo Scaramuccia
82850a0418 MDL-68588 Backup: Hide ->backuptempdir in exception info 2020-07-03 21:17:42 +02:00
Brendan Heywood
1fef1de592 MDL-58281 files: Correctly handle missing files in readfile_accel 2019-12-30 17:18:49 +11:00
Eloy Lafuente (stronk7)
df272345ba MDL-65996 exceptions: Make exception handler early-errors compliant
Some errors can happen really early in Moodle bootstrap/warmup
(basically when executing setup.php stuff, before general libraries
are loaded and available).

That's called "early errors" and there are good parts within
setuplib.php that must be able to run without any dependency
other than vanilla php code.

It seems that, along the years, some dependencies have been
added (calls to debugging(), to s()....) and they worked mostly
ok because early errors are rare.

This commit just makes all those dependencies conditional so,
if an early error is detected... the exception handler will
return real information about he error happening and not
handler own errors (like it's happening now).
2019-06-22 11:38:43 +02:00
Matteo Scaramuccia
c7321899c9 MDL-61038 setuplib: Fixed PECL UUID extension support
generate_uuid() has been refactored into \core\uuid::generate()
2019-06-09 23:24:26 +02:00
Eloy Lafuente (stronk7)
7726bec6b3 Merge branch 'MDL-63262-master' of git://github.com/damyon/moodle 2019-05-07 16:26:40 +08:00
Damyon Wiese
aae219acce MDL-63262 badges: Add badgr.io
Upgrade the support for Open Badges 2 to support a real open badges 2 backpack.
Moodle can only talk to one backpack at a time, so after switching backpacks, users
will have to manually disconnect and then reconnect their backpack to the new one.

This commit combines several changes:
* Split classes into badges namespace
* Publish expiry data with a badge
* Publish badge alignments in badges exported to the backpack.
* Export the criteria for a badge to the backpack.
2019-05-03 15:00:00 +08:00
Andrew Nicols
ea00cdc79f Merge branch 'MDL-64394-accesslog' of https://github.com/brendanheywood/moodle 2019-05-03 08:49:33 +08:00