878 Commits

Author SHA1 Message Date
Andrew Nicols
024e36be17
MDL-81634 core: Fix all implicitly defined nullables
Note: This does not impact third-party libraries.
2024-08-02 14:11:12 +08:00
Shamim Rezaie
5aee595206 Merge branch 'MDL-78030-main-improvement' of https://github.com/meirzamoodle/moodle 2024-07-31 17:38:29 +10:00
Ilya Tregubov
f14746511b Merge branch 'MDL-78776-expunge_myisam' of https://github.com/leonstr/moodle 2024-07-31 09:38:25 +08:00
meirzamoodle
42664ee49a MDL-78030 dml: get total count records using the window function
The COUNT window function can be helpful to fasten the complex query,
but it's not recommended to be used for a single table query.

The patch is specifically for PostgreSQL, MariaDB and Oracle databases as they have better performance
compared to MySQL and MSSQL. Although these databases support the COUNT window functions,
the results indicate that the query runs slower when using them.
2024-07-29 13:53:46 +07:00
Leon Stringer
7c70eb8e89 MDL-78776 database: Remove MyISAM migration
Remove functionality to migrate from MyISAM, and remove tests of whether
the existing database is using this.

Support for MyISAM was dropped in Moodle 2.9 (MDL-46064) so it should
not be possible for any subsequent Moodle version to be using this.

The only remaining MyISAM-aware code is the environment check via
check_database_storage_engine() to prevent installation/upgrade if the
database is set to use this.
2024-06-28 16:00:06 +01:00
Eloy Lafuente (stronk7)
ad5fe71868
MDL-82207 phpunit: fix various @covers annotations (take#1)
This fixes various (not all) wrong @covers annotations that
are reported as warnings by PHPUnit when it's run with
code-coverage enabled.

When possible, the preferred solution is to change to
@covers at class level, that is the recommended way.

If multiple classes are involved, then a mix of @coversDefaultClass
and @covers at method level are used (always trying to use the
minimum needed patch).

This is the first of a series of issues created as sub-tasks
of MDL-82142.
2024-06-24 12:07:39 +02:00
Eloy Lafuente (stronk7)
674497a12c
MDL-81523 phpunit: Add all missing setUp/tearDown parent calls
All setUp(), tearDown(), setUpBeforeClass() and tearDownAfterClass()
must, always, call to parent, to ensure that everything is properly
set and cleaned.

While in a lot of situations this is not needed (parents may not
have anything to run), with PHPUnit >= 10 this can become more
important because we are going to move the reset code from current
placement @ runBare() to setUp()/tearDown().

Note that all the changes performed in this commit have been detected
and fixed by moodle-cs (ParentSetUpTearDownSniffTest).
2024-06-14 16:04:57 +02:00
Eloy Lafuente (stronk7)
4f7631113c
MDL-81522 phpunit: Add missing void return type to all tests #2
This commit includes more changes, all them also adding the :void
return type to unit tests missing them.

The difference is that all these changes, while also detected
perfectly by the moodle.PHPUnit.TestReturnType sniff, were not
auto-fixed (like the previous commit ones), because all them
do include some "return" statement and, for safety, we don't
fix them.

All the cases have been visually inspected and confirmed that
the existing "return" statements always belong to anon
functions within the test body and not the test own return statement.
2024-06-11 11:55:08 +02:00
Eloy Lafuente (stronk7)
01148a0816
MDL-81522 phpunit: Add missing void return type to all tests
While this change is not 100% required now, it's good habit
and we are checking for it since Moodle 4.4.

All the changes in this commit have been applied automatically
using the moodle.PHPUnit.TestReturnType sniff and are, exclusively
adding the ": void" return types when missing.
2024-06-11 11:55:07 +02:00
Paul Holden
113b64c2de
MDL-82047 dml: correct constant name in large integer test docblock. 2024-05-31 07:19:23 +01:00
Paul Holden
96ded90e68
MDL-81282 dml: define SQL_INT_MAX, to determine large supported ints.
The constant can be used by calling code in place of various adhoc
versions of the same, when they require a large value with known cross
platform support.
2024-05-24 22:19:54 +01:00
Sara Arjona
4dbeaddc5f
Merge branch 'MDL-81457-main' of https://github.com/andrewnicols/moodle 2024-04-23 14:56:31 +02:00
Marina Glancy
ef1759da74 MDL-80820 various: fix incorrect phpdocs 2024-04-08 10:13:10 +01:00
Andrew Nicols
d9a8eb2bdb
MDL-81457 core: Mark SSL test as skipped, not incomplete
The incomplete test is intended for tests which are written but whose
code does not yet exist.

https://docs.phpunit.de/en/9.6/incomplete-and-skipped-tests.html
2024-04-08 08:45:16 +08:00
Huong Nguyen
388cc303f9 MDL-81246 dml: Check the statement resource before freeing it 2024-03-15 11:07:51 +07:00
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