863 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
Eloy Lafuente (stronk7)
ba1f804ffa
MDL-65292 style: Fix all function declarations white space
This has been generated running the following Sniffs, all
them part of the Moodle's CodeSniffer standard:
- PSR12.Functions.ReturnTypeDeclaration
- PSR12.Functions.NullableTypeDeclaration
- moodle.Methods.MethodDeclarationSpacing
- Squiz.Whitespace.ScopeKeywordSpacing

All them are, exclusively, about correct spacing, so the changes
are, all them, only white space changes.

Only exceptions to the above are 3 changes what were setting the
return type in a new line, and, when that happens, the closing
parenthesis (bracket) has to go to the same line than the colon.
2024-02-28 23:33:26 +01:00
Marina Glancy
5117dee664 MDL-80821 dml: declare arguments for sql_concat() 2024-02-19 12:27:51 +00:00
Tim Hunt
e8bfeea06c MDL-79780 DML: add the missing get_fieldset method 2023-12-22 12:09:41 +00:00
Andrew Nicols
e734858e55
MDL-79890 core: Session handlers must implement SessionHandlerInterface 2023-11-15 09:14:40 +08:00
Sara Arjona
cc9430929d
MDL-77708 docs: Update references from docs.moodle.org/dev 2023-09-26 10:30:19 +02:00
Eloy Lafuente (stronk7)
d2b6a1b7f3
MDL-76459 dml: Remove other remaining harcoded uses of old 28 & 30
Let's require lib/ddllib.php and use the constant properly,
so we don't need to go searching for cases in future changes.

They are a hand of files, but already are included often each
time the database manager is included. Possible alternative
for this, if we want to reduce the number of included files
is to move the constants to xmldb_constants and only include
that file, but I don't think that makes much sense.

Also, fix the xmldb schema definition to validate table and
column names with the new allowed lengths.
2023-09-02 09:22:13 +02:00
Eloy Lafuente (stronk7)
8996ee0eaa
MDL-76459 oracle: Remove the 2-chars prefix limit
Now Oracle can use longer table names, like all the
other databases, and the very same 10 characters limit
for $CFG->prefix applies.

As far as it's already checked by the environmental checks
we don't need to verify anything in the driver any more.

Also, deprecate the prefixtoolong,error string. I was tempted
to straight delete it but imagined some custom database driver
extending the core one so, it doesn't harm much to keep it as
deprecated some time.
2023-09-02 09:22:13 +02:00
Eloy Lafuente (stronk7)
8dc3486a04
MDL-76459 xmldb: Raise the table & column length limits
With Oracle 19 being the minimum version for Moodle >= 4.1, now
we can safely raise the table and column length limits by a
considerable amount.

In both tables and columns the new limit it 63, coming from PostgreSQL,
that is the one now having the more restrictive limit.

1) NP with columns, let's allow up to 63 ascii chars (bytes) there.
2) But, for table names, now we need to specify a maximum prefix length,
   to know how many chars we leave remaining for table names (without
   prefix). 63 - 10 (max prefix length) = 53 ascii chars (bytes).

So, in this patch, we are introducing a new constant:

xmldb_table::PREFIX_MAX_LENGTH = 10

That will be used to:
- Validate that we aren't using a prefix longer than it.
- Calculate the final table limit that will be 63 minus
  the prefix max length.

Details added to 4.2 main upgrade.txt file.

Also, update related to tests to (near) always use the constants
so they won't need modification in the future.
2023-09-02 09:22:13 +02:00
Paul Holden
36af5457dc
MDL-78787 dml: native casting to char in SQL Server driver.
Ensure the same is used during concatentation to prevent truncation
of data, which was previously set at 255 characters per field.
2023-08-23 00:55:24 +01:00
Mark Webster
1a561c23e6 MDL-78492 dml: Better support for auroramysql
Aurora MySQL does not support row format COMPRESSED and falls back
to COMPACT if you try to use it, cuasing column size too large
errors if you try to use it with utf8mb4 collation.
2023-07-25 11:56:50 +01:00
Srdjan
bb1ecd8ea4 MDL-54704 dml: support for SSL with MySQL / MariaDB and PostgreSQL 2023-06-30 15:41:39 +10:00
Andrew Nicols
28b2c57c82 Merge branch 'MDL-78212-MYSQLI_CLIENT_COMPRESS' of https://github.com/catalyst/moodle 2023-06-22 14:29:41 +02:00
Srdjan
9fcba75de4 MDL-78212 dml: Added MYSQLI_CLIENT_COMPRESS option for mysqli
Config dboptions key 'clientcompress'.
Decreases traffic between the application server and the database host.
2023-06-21 10:07:17 +10:00
Meirza
81a5016ec7 MDL-78160 lib: Added class properties that are not declared in dml
In PHP 8.2 and later, setting a value to an undeclared class property is
deprecated and emits a deprecation notice.
So we need to add missing class properties that still need to be declared.

At the test_transaction_with_events() I changed $this->_called into $called local var,
since the $called is used inside the anonymous function I added the third param as
a variable passed by reference so the last assert can get the newest value.
2023-06-19 19:56:07 +07:00
Eloy Lafuente (stronk7)
ff8a9478b2
MDL-78016 dml: Add Oracle support for OFFSET ... FETCH clauses
Since Oracle 12, these statements (providing the same than the
well-known LIMIT clauses in MySQL and PostgreSQL) are available,

Just let's switch to use them, removing the old complex ROWNUM
based queries needed before to provide limits support.
2023-05-19 17:47:57 +02:00
Marina Glancy
8fc1486d36 MDL-77164 various: fix incorrect phpdocs 2023-04-13 11:35:06 +01:00
Meirza
e2cd808b34 MDL-76415 core: Fixed ${var} string interpolation deprecations.
Since PHP 8.2, placing the dollar sign outside the curly brace is deprecated when
the expression inside the braces resolves to a variable or an expression.
2023-02-13 19:51:46 +07: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
Meirza
f8537ffec6 MDL-64153 dml: Added extrainfo in the DB options config.
extrainfo is an extra information for the DB driver, e.g. SQL Server,
has additional configuration according to its environment,
which the administrator can specify to alter and override any connection options.

Co-authored-by: LukeCarrier <luke@carrier.im>
2023-01-06 06:17:17 +07:00
Matteo Scaramuccia
0131c3be00 MDL-69581 dml: Improve MySQL/MariaDB server version detection
Add 'versionfromdb' to opt-in for VERSION() query.

mariadb_native_moodle_database::get_server_info() has been removed
to avoid the specific override: everything is now managed in the base
method which takes care of both MySQL and MariaDB versioning details.

New protected methods have been added too to improve the testing strategy,
allowing to mock the results from an actual DB connection.
The new testing strategy enables simulating even the Azure scenarios.
2022-12-28 10:59:45 +01:00
Eloy Lafuente (stronk7)
eeaaf131ac MDL-75977 xmldb: Avoid using null params on built-in DB functions
This changes a couple of cases, in postgres and oracle where we
were trying to calculate strlen() on null values (that causes a
PHP 8.1 warning).

Also, at the same time, fixing another case in xmldb_field, it
was detected that it had a bug around precision (being set to the
value of type), being used as object property, when it's not, so
it was also fixed by moving the code logic a little bit.

Note that the bug has been there since inception because there
isn't any code in Moodle using that ->precision property. It
was just detected thanks to PHP 8.2, but that's another story. :-)

Verified that with the patch:
- All DBs can be installed (phpunit install)
- Both DDL and DML pass without any ddl/dml warning (in all DBs).
2022-11-26 16:16:20 +01:00
Matteo Scaramuccia
75123ed7fd MDL-74912 dml: Fix missing nullable marker 2022-11-05 10:07:26 +01:00
Matteo Scaramuccia
b82c95a075 MDL-74912 mod_forum: Fix regexp word boundaries markers in MySQL 8 2022-11-05 10:07:26 +01:00
Eloy Lafuente (stronk7)
83eb19338e MDL-75760 database: Keep mysql driver working over all PHP versions
Before PHP 8.1, the mysqli extension had MYSQLI_REPORT_OFF as default setting.
With PHP 8.1, it has been changed to MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT
The native driver is not ready to work with this new reporting level,
see MDL-75761 about to considering to improve it.

So this change just ensures that we continue using MYSQLI_REPORT_OFF
with any PHP version.
2022-10-21 16:33:22 +02:00
Marina Glancy
44aac31980 MDL-73424 general: specify return type where possible 2022-10-10 16:46:26 +02: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
Andrew Nicols
010ad8751a MDL-75614 dml: Unit tests must test something 2022-09-30 16:36:36 +08:00
Andrew Nicols
9911faf8be Merge branch 'MDL-75614-debugsqltrace' of https://github.com/brendanheywood/moodle 2022-09-30 16:36:10 +08:00
Alex Morris
70dfee9e23
MDL-75170 dml: add sql_order_by_null method
Standardises return patterns of null values across database types
to keep with sorting nullsto the top when ascending, and
to the bottom when descending
2022-09-30 11:27:26 +13:00
Sara Arjona
eef0a430be Merge branch 'MDL-75548' of https://github.com/timhunt/moodle 2022-09-05 13:09:09 +02:00
Brendan Heywood
11efc67eb5 MDL-75614 dml: Fixed debugsqltrace with anon classes bug 2022-09-02 11:42:04 +10: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
Srdjan
5248067884 MDL-71000 lib/dml: New query type SQL_QUERY_AUX_READONLY
For SQL_QUERY_AUX queries that can go to readonly, conditions permitting.
2022-08-23 10:39:43 +10:00
Tim Hunt
797b9fbd62 MDL-75548 misc: final Required parameter follows optional notices 2022-08-22 15:20:13 +01:00
Jun Pataleta
3c6fdb1993 Merge branch 'MDL-71062-master' of https://github.com/sharidas/moodle 2022-07-13 11:39:08 +08:00
Sujith Haridasan
73d604369d MDL-71062 core: Step 1 deprecation of print_error function 2022-07-13 08:20:54 +05:30
Srdjan
bab70a42a0 MDL-74681 lib/dml: moodle_read_slave_trait: written table timestamping
Moved written table timestamping from query_start() to query_end():
We are adjusting table last written times at the end of transaction.
That does not apply to immediate database writes that are not performed
within transaction. This change is to set last written time after the query
has finished for such writes, rather than before it started. That way
long write operations cannot spill over the latency parameter.
2022-07-08 12:27:33 +10:00
Paul Holden
27f9929b52 MDL-72184 dml: implement driver methods for casting to char. 2022-06-12 19:31:34 +01:00
Marina Glancy
a0398fdde8 MDL-73423 core_privacy: Calling reset() on objects deprecated PHP8.1 2022-04-29 16:16:07 +02:00
Jun Pataleta
097d14c3f2 Merge branch 'MDL-74143' of https://github.com/stronk7/moodle 2022-03-25 17:56:10 +08:00
Srdjan
d8baf29573 MDL-73713 dml: moodle_read_slave_trait default latency to 1 second
In practice it is as if the feature was turned off most of the time.
However, some long processes may benefit from this very safe value
in case admins missed to configure it.
2022-03-24 09:32:24 +10:00
Srdjan
343384d921 MDL-73713 dml: test namespaces fix - a noop 2022-03-24 09:30:10 +10:00
Srdjan
8a386d68f6 MDL-73713 dml: moodle_read_slave_trait table written time adjustment
moodle_database::commit_delegated_transaction() calls
core\event\manager::database_transaction_commited() which may invoke
events that do database reads.
This change adjusts tables last written time in moodle_read_slave_trait *before*
calling moodle_database::commit_delegated_transaction().
2022-03-24 09:19:56 +10:00
Eloy Lafuente (stronk7)
848ec32df0 MDL-74143 database: Make get_indexes() to return original column names
Sometimes, in order to provide a cross-db behaviour of unique indexes
mixing null and not null columns, we create, under the hood, some
function based indexes.

When that happens get_indexes() is returning the name of the
expression objects used to calculate that function index. But we need
the original column names to be able to compare indexes and get
column dependencies properly.

So, this patch just looks, when the index is unique and function based,
to the expressions (pretty standard CASE statements) and gets the
original column name from it.

Covered with tests.
2022-03-23 23:16:53 +01:00
Eloy Lafuente (stronk7)
a5c91474ee MDL-71807 cleanup: Replace deprecated codingStandardsIgnore annotations
The PHP_CodeSniffer @codingStandardsIgnore annotations are deprecated
and, since version 3.x, the new // phpcs:ignore comments should be used
instead.

This commits just reviews all the uses in core, replacing them for
the better new candidate, or removing when no longer needed.
2022-03-08 10:48:53 +01:00
Limekiller
3c60f8a0ce MDL-73450 installation: Support Aurora MySQL >= 8.0.0 2022-02-10 15:14:35 -05:00
Cameron Ball
d5eaa5224e MDL-72670 session: Correct read only debugging logic
Prior to this patch the debugging mode (when enabled) would trigger
on everywhere, regardless of whether or not READ_ONLY_SESSION is defined.

This patch modifies that behaviour so that the debugging only kicks in
if READ_ONLY_SESSION is defined and set to true.
2021-10-08 15:11:40 +08:00
Brendan Heywood
66a923fe77 MDL-68164 dml: Cache postgres field type metadata in MUC 2021-09-07 19:29:31 +10:00