Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code checker updates: PHP 8.2, Moodle 4.3, arrays #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

mariadb:
image: mariadb:10.6 # Moodle 4.2: >=10.6.7
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"

ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
Expand All @@ -34,30 +34,25 @@ jobs:
fail-fast: false
matrix:
include:
# Moodle 4.0, PHP 7.3, PostgreSQL
- php: '7.3' # 7.3-8.0
moodle-branch: 'MOODLE_400_STABLE'
database: pgsql
plugin-ci: ^3
# Moodle 4.1, PHP 7.4, MariaDB
- php: '7.4' # 7.4-8.1
moodle-branch: 'MOODLE_401_STABLE'
# Moodle 4.3, PHP 8.0, MariaDB
- php: '8.0' # 8.0-8.2
moodle-branch: 'MOODLE_403_STABLE'
database: mariadb
plugin-ci: ^4
# Moodle 4.2, PHP 8.0, PostgreSQL
- php: '8.0' # 8.0-8.1
moodle-branch: 'MOODLE_402_STABLE'
# Moodle 4.4, PHP 8.2, PostgreSQL
- php: '8.2' # 8.1-8.3
moodle-branch: 'MOODLE_404_STABLE'
database: pgsql
plugin-ci: ^4
# Moodle master, PHP 8.1, MariaDB
- php: '8.1'
moodle-branch: 'master'
# Moodle main, PHP 8.3, MariaDB
- php: '8.3'
moodle-branch: 'main'
database: mariadb
plugin-ci: ^4

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -80,54 +75,64 @@ jobs:
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV

- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
# Uncomment this to run Behat tests using the Moodle App.
# MOODLE_APP: 'true'

- name: PHP Lint
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci phpcs --max-warnings 0
#- name: Moodle Code Checker
# if: ${{ !cancelled() }}
# run: moodle-plugin-ci phpcs --max-warnings 0

#- name: Moodle PHPDoc Checker
# if: ${{ always() }}
# run: moodle-plugin-ci phpdoc
# if: ${{ !cancelled() }}
# run: moodle-plugin-ci phpdoc --max-warnings 0

- name: Validating
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci mustache

#- name: Grunt
# if: ${{ always() }}
# if: ${{ !cancelled() }}
# run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpunit --fail-on-warning

#- name: Behat features
# if: ${{ always() }}
# id: behat
# if: ${{ !cancelled() }}
# run: moodle-plugin-ci behat --profile chrome

#- name: Upload Behat Faildump
# if: ${{ failure() && steps.behat.outcome == 'failure' }}
# uses: actions/upload-artifact@v4
# with:
# name: Behat Faildump (${{ join(matrix.*, ', ') }})
# path: ${{ github.workspace }}/moodledata/behat_dump
# retention-days: 7
# if-no-files-found: ignore

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
38 changes: 19 additions & 19 deletions backup/moodle2/backup_mediagallery_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,43 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated.
$mediagallery = new backup_nested_element('mediagallery', array('id'), array(
$mediagallery = new backup_nested_element('mediagallery', ['id'], [
'course', 'name', 'intro', 'introformat', 'timecreated', 'timemodified',
'thumbnailsperpage', 'thumbnailsperrow', 'displayfullcaption',
'captionposition', 'galleryfocus', 'carousel', 'grid', 'gridrows',
'gridcolumns', 'enforcedefaults', 'readonlyfrom', 'readonlyto',
'maxbytes', 'maxitems', 'maxgalleries', 'allowcomments', 'allowlikes',
'colltype', 'objectid', 'source', 'mode', 'creator', 'userid',
));
]);

$userfeedbacks = new backup_nested_element('userfeedback');
$userfeedback = new backup_nested_element('feedback', array('id'), array(
'itemid', 'userid', 'liked', 'rating'
));
$userfeedback = new backup_nested_element('feedback', ['id'], [
'itemid', 'userid', 'liked', 'rating',
]);

$gallerys = new backup_nested_element('gallerys');
$gallery = new backup_nested_element('gallery', array('id'), array(
$gallery = new backup_nested_element('gallery', ['id'], [
'instanceid', 'name', 'userid', 'nameposition', 'exportable', 'galleryview',
'gridrows', 'gridcolumns', 'visibleinstructor', 'visibleother', 'thumbnail',
'galleryfocus', 'groupid', 'mode', 'objectid', 'source', 'creator',
'contributable',
));
]);

$items = new backup_nested_element('items');
$item = new backup_nested_element('item', array('id'), array(
$item = new backup_nested_element('item', ['id'], [
'galleryid', 'userid', 'caption', 'description', 'sortorder', 'display', 'moralrights',
'originalauthor', 'productiondate', 'medium', 'publisher', 'reference', 'externalurl',
'timecreated', 'broadcaster', 'objectid', 'source', 'processing_status', 'creator',
));
]);

$ctags = new backup_nested_element('collectiontags');
$ctag = new backup_nested_element('collectiontag', array('id'), array('itemid', 'rawname'));
$ctag = new backup_nested_element('collectiontag', ['id'], ['itemid', 'rawname']);

$gtags = new backup_nested_element('gallerytags');
$gtag = new backup_nested_element('gallerytag', array('id'), array('itemid', 'rawname'));
$gtag = new backup_nested_element('gallerytag', ['id'], ['itemid', 'rawname']);

$itags = new backup_nested_element('itemtags');
$itag = new backup_nested_element('itemtag', array('id'), array('itemid', 'rawname'));
$itag = new backup_nested_element('itemtag', ['id'], ['itemid', 'rawname']);

// Build the tree.

Expand All @@ -90,13 +90,13 @@ protected function define_structure() {
$itags->add_child($itag);

// Define sources.
$mediagallery->set_source_table('mediagallery', array('id' => backup::VAR_ACTIVITYID));
$mediagallery->set_source_table('mediagallery', ['id' => backup::VAR_ACTIVITYID]);

// All the rest of elements only happen if we are including user info.
if ($userinfo) {
$gallery->set_source_table('mediagallery_gallery', array('instanceid' => backup::VAR_PARENTID));
$item->set_source_table('mediagallery_item', array('galleryid' => backup::VAR_PARENTID));
$userfeedback->set_source_table('mediagallery_userfeedback', array('itemid' => backup::VAR_PARENTID));
$gallery->set_source_table('mediagallery_gallery', ['instanceid' => backup::VAR_PARENTID]);
$item->set_source_table('mediagallery_item', ['galleryid' => backup::VAR_PARENTID]);
$userfeedback->set_source_table('mediagallery_userfeedback', ['itemid' => backup::VAR_PARENTID]);

if (core_tag_tag::is_enabled('mod_mediagallery', 'mediagallery')) {
$ctag->set_source_sql('SELECT t.id, ti.itemid, t.rawname
Expand All @@ -107,7 +107,7 @@ protected function define_structure() {
AND ti.contextid = ?', [
backup_helper::is_sqlparam('mediagallery'),
backup_helper::is_sqlparam('mod_mediagallery'),
backup::VAR_CONTEXTID]);
backup::VAR_CONTEXTID, ]);
}

if (core_tag_tag::is_enabled('mod_mediagallery', 'mediagallery_gallery')) {
Expand All @@ -119,7 +119,7 @@ protected function define_structure() {
AND ti.contextid = ?', [
backup_helper::is_sqlparam('mediagallery_gallery'),
backup_helper::is_sqlparam('mod_mediagallery'),
backup::VAR_CONTEXTID]);
backup::VAR_CONTEXTID, ]);
}

if (core_tag_tag::is_enabled('mod_mediagallery', 'mediagallery_item')) {
Expand All @@ -131,7 +131,7 @@ protected function define_structure() {
AND ti.contextid = ?', [
backup_helper::is_sqlparam('mediagallery_item'),
backup_helper::is_sqlparam('mod_mediagallery'),
backup::VAR_CONTEXTID]);
backup::VAR_CONTEXTID, ]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions backup/moodle2/restore_mediagallery_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];
return $contents;
}

Expand All @@ -63,7 +63,7 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_decode_rule('MEDIAGALLERYVIEWBYID', '/mod/mediagallery/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('MEDIAGALLERYINDEX', '/mod/mediagallery/index.php?id=$1', 'course');
Expand All @@ -79,7 +79,7 @@ public static function define_decode_rules() {
* of {@see \restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('mediagallery', 'add', 'view.php?id={course_module}', '{page}');
$rules[] = new restore_log_rule('mediagallery', 'update', 'view.php?id={course_module}', '{page}');
Expand All @@ -99,7 +99,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

$rules[] = new restore_log_rule('mediagallery', 'view all', 'index.php?id={course}', null);

Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/restore_mediagallery_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class restore_mediagallery_activity_structure_step extends restore_activity_stru

protected function define_structure() {

$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('userinfo');

$mediagallery = new restore_path_element('mediagallery', '/activity/mediagallery');
Expand Down Expand Up @@ -179,7 +179,7 @@ protected function after_execute() {

// Can't do thumbnail mapping before the item is restored, so we do it here.
$mgid = $this->task->get_activityid();
if ($records = $DB->get_records('mediagallery_gallery', array('instanceid' => $mgid))) {
if ($records = $DB->get_records('mediagallery_gallery', ['instanceid' => $mgid])) {
foreach ($records as $record) {
if ($record->thumbnail) {
$record->thumbnail = $this->get_mappingid('mediagallery_item', $record->thumbnail);
Expand Down
16 changes: 8 additions & 8 deletions classes/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class base {
protected $record;
static protected $table;

public function __construct($recordorid, $options = array()) {
public function __construct($recordorid, $options = []) {
global $DB;

if (empty(static::$table)) {
Expand All @@ -52,7 +52,7 @@ public function __construct($recordorid, $options = array()) {
}
$this->record = $recordorid;
} else {
$this->record = $DB->get_record(static::$table, array('id' => $recordorid), '*', MUST_EXIST);
$this->record = $DB->get_record(static::$table, ['id' => $recordorid], '*', MUST_EXIST);
}

$this->options = $options;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static function create(\stdClass $data) {
$class = get_called_class();

$data->id = $DB->insert_record(static::$table, $data);
$record = $DB->get_record(static::$table, array('id' => $data->id));
$record = $DB->get_record(static::$table, ['id' => $data->id]);

// Return an instance of the gallery class.
$object = new $class($record);
Expand All @@ -90,10 +90,10 @@ public static function create(\stdClass $data) {
return $object;
}

public function delete($options = array()) {
public function delete($options = []) {
global $DB;

$DB->delete_records(static::$table, array('id' => $this->record->id));
$DB->delete_records(static::$table, ['id' => $this->record->id]);
\core_tag_tag::remove_all_item_tags('mod_mediagallery', static::$table, $this->id);

return true;
Expand Down Expand Up @@ -156,10 +156,10 @@ public function update($data) {
$this->set_tags();

if (empty($data->noevent)) {
$params = array(
$params = [
'context' => $this->get_context(),
'objectid' => $this->id,
);
];
if (isset($data->nosync) && $data->nosync) {
$params['other']['nosync'] = true;
}
Expand All @@ -182,7 +182,7 @@ public function is_thebox_creator_or_agent($userid = null) {
if (is_null($userid)) {
$userid = $USER->id;
} else if ($userid != $USER->id) {
$username = $DB->get_field('user', 'username', array('id' => $userid));
$username = $DB->get_field('user', 'username', ['id' => $userid]);
}

if ($username == $this->creator || $this->creator == 'z9999999') {
Expand Down
Loading