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

Update Moodle coding standards #128

Open
wants to merge 7 commits into
base: MOODLE_401_STABLE
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
99 changes: 48 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,116 @@ on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
include:
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'
runs-on: ubuntu-22.04

services:
postgres:
image: postgres
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

mariadb:
image: mariadb:10.5
image: mariadb:10
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

strategy:
fail-fast: false
matrix:
include:
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'

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

- name: Install node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Setup PHP
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: zip, gd, mbstring, pgsql, mysqli
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Deploy moodle-plugin-ci
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
- name: Install Moodle
# Need explicit IP to stop mysql client fail on attempt to use unix socket.
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
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
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
IGNORE_PATHS: 'tool/printable/classes/bfpdf.php'

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

- name: phpcpd
- name: PHP Copy/Paste Detector
if: ${{ always() }}
run: moodle-plugin-ci phpcpd || true
run: moodle-plugin-ci phpcpd

- name: phpmd
- name: PHP Mess Detector
if: ${{ always() }}
run: moodle-plugin-ci phpmd

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

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

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

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

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

- name: grunt
- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt

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

- name: behat
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
Empty file modified amd/build/board.min.js
100755 → 100644
Empty file.
Empty file modified amd/build/board.min.js.map
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion amd/build/comments.min.js.map

Large diffs are not rendered by default.

Empty file modified amd/build/jquery.editable.amd.min.js
100755 → 100644
Empty file.
Empty file modified amd/build/jquery.editable.amd.min.js.map
100755 → 100644
Empty file.
Empty file modified amd/build/main.min.js
100755 → 100644
Empty file.
Empty file modified amd/build/main.min.js.map
100755 → 100644
Empty file.
20 changes: 10 additions & 10 deletions amd/src/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export default function(settings) {
strings.delete,
strings.Cancel,
function() {
serviceCall('delete_note', { id: ident }, function (result) {
serviceCall('delete_note', {id: ident}, function(result) {
if (result.status) {
lastHistoryId = result.historyid;
let note = getNote(ident);
Expand Down Expand Up @@ -1551,29 +1551,29 @@ export default function(settings) {
removeOnClose: true
}).then(function(modal) {
// Use the body promise so we know body content is loaded.
modal.getBodyPromise().then(function () {
modal.getBodyPromise().then(function() {
let saveInProgress = false;
editModal = modal;
modal.setLarge();
modal.setSaveButtonText(strings.post_button_text);
modal.setButtonText('cancel', strings.cancel_button_text);

modal.getRoot().on(ModalEvents.hidden, function () {
modal.getRoot().on(ModalEvents.hidden, function() {
stopNoteEdit();
if (!note.data('ident')) {
note.remove();
}
});

modal.getRoot().on(ModalEvents.save, function (e) {
modal.getRoot().on(ModalEvents.save, function(e) {
e.preventDefault();
modal.getRoot().find('form').submit();
});

var changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);

modal.getRoot().on('submit', 'form', function (e) {
modal.getRoot().on('submit', 'form', function(e) {
e.preventDefault();

// Prevent multiple form submissions from being sent.
Expand All @@ -1593,7 +1593,7 @@ export default function(settings) {
// Normally this would happen when the form is submitted, but
// since we aren't submitting the form normally we need to run client side
// validation.
modal.getRoot().find(':input').each(function (index, element) {
modal.getRoot().find(':input').each(function(index, element) {
element.dispatchEvent(changeEvent);
});

Expand All @@ -1612,7 +1612,7 @@ export default function(settings) {
}

var formData = JSON.stringify(modal.getRoot().find('form').serialize());
serviceCall('submit_form', {contextid: contextid, jsonformdata: formData}, function (result) {
serviceCall('submit_form', {contextid: contextid, jsonformdata: formData}, function(result) {
if (result.status) {
if (result.action == 'insert') {
// Added a new note.
Expand Down Expand Up @@ -1750,7 +1750,7 @@ export default function(settings) {
});
modal.show();
// Handle hidden event.
modal.getRoot().on(ModalEvents.hidden, function () {
modal.getRoot().on(ModalEvents.hidden, function() {
// Destroy when hidden.
modal.destroy();
});
Expand Down Expand Up @@ -1795,13 +1795,13 @@ export default function(settings) {

// Get strings
var stringsInfo = [];
for (var string in strings) {
for (let string in strings) {
stringsInfo.push({key: string, component: 'mod_board'});
}

$.when(getStrings(stringsInfo)).done(function(results) {
var index = 0;
for (string in strings) {
for (let string in strings) {
strings[string] = results[index++];
}

Expand Down
2 changes: 1 addition & 1 deletion amd/src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const init = () => {
}
board.dataset.init = 1;

Str.get_string('addcomment', 'mod_board').then( s => {
Str.get_string('addcomment', 'mod_board').then(s => {
const style = document.createElement('style');
style.innerHTML = `
.comment-input:empty:before {
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/backup_board_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public static function encode_content_links($content) {
* @return string[]
*/
public function get_fileareas() {
return array('images', 'background');
return ['images', 'background'];
}
}
24 changes: 12 additions & 12 deletions backup/moodle2/backup_board_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ protected function define_structure() {
'completionnotes', 'embed']);

$columns = new backup_nested_element('columns');
$column = new backup_nested_element('column', array('id'), array('boardid', 'name', 'sortorder'));
$column = new backup_nested_element('column', ['id'], ['boardid', 'name', 'sortorder']);

$notes = new backup_nested_element('notes');
$note = new backup_nested_element('note', array('id'), array(
$note = new backup_nested_element('note', ['id'], [
'columnid', 'ownerid', 'userid', 'groupid', 'content', 'heading', 'type', 'info', 'url', 'timecreated',
'sortorder', 'deleted'));
'sortorder', 'deleted']);

$ratings = new backup_nested_element('ratings');
$rating = new backup_nested_element('rating', array('id'), array(
'noteid', 'userid', 'timecreated'));
$rating = new backup_nested_element('rating', ['id'], [
'noteid', 'userid', 'timecreated']);

$comments = new backup_nested_element('comments');
$comment = new backup_nested_element('comment', array('id'), array(
'noteid', 'userid', 'content', 'timecreated', 'timemodified', 'deleted'));
$comment = new backup_nested_element('comment', ['id'], [
'noteid', 'userid', 'content', 'timecreated', 'timemodified', 'deleted']);

$comments->add_child($comment);
$note->add_child($comments);
Expand All @@ -64,13 +64,13 @@ protected function define_structure() {
$columns->add_child($column);
$board->add_child($columns);

$board->set_source_table('board', array('id' => backup::VAR_ACTIVITYID));
$column->set_source_table('board_columns', array('boardid' => backup::VAR_PARENTID), 'id ASC');
$board->set_source_table('board', ['id' => backup::VAR_ACTIVITYID]);
$column->set_source_table('board_columns', ['boardid' => backup::VAR_PARENTID], 'id ASC');

if ($userinfo) {
$note->set_source_table('board_notes', array('columnid' => backup::VAR_PARENTID), 'id ASC');
$rating->set_source_table('board_note_ratings', array('noteid' => backup::VAR_PARENTID), 'id ASC');
$comment->set_source_table('board_comments', array('noteid' => backup::VAR_PARENTID), 'id ASC');
$note->set_source_table('board_notes', ['columnid' => backup::VAR_PARENTID], 'id ASC');
$rating->set_source_table('board_note_ratings', ['noteid' => backup::VAR_PARENTID], 'id ASC');
$comment->set_source_table('board_comments', ['noteid' => backup::VAR_PARENTID], 'id ASC');
}

$comment->annotate_ids('user', 'userid');
Expand Down
8 changes: 4 additions & 4 deletions backup/moodle2/restore_board_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ protected function define_my_steps() {
* @return array
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

$contents[] = new restore_decode_content('board', array('intro'), 'board');
$contents[] = new restore_decode_content('board_notes', array('content'), 'board_note');
$contents[] = new restore_decode_content('board', ['intro'], 'board');
$contents[] = new restore_decode_content('board_notes', ['content'], 'board_note');

return $contents;
}
Expand All @@ -71,6 +71,6 @@ public static function define_decode_rules() {
* @return string[]
*/
public function get_fileareas() {
return array('images', 'backgrond');
return ['images', 'backgrond'];
}
}
10 changes: 5 additions & 5 deletions backup/moodle2/restore_board_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class restore_board_activity_structure_step extends restore_activity_structure_s
*/
protected function define_structure() {

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

$paths[] = new restore_path_element('board', '/activity/board');
Expand Down Expand Up @@ -152,19 +152,19 @@ protected function after_execute() {

// UPDATE note url to new context.
$boardid = $this->get_new_parentid('board');
$board = $DB->get_record('board', array('id' => $boardid));
$board = $DB->get_record('board', ['id' => $boardid]);
$cm = get_coursemodule_from_instance('board', $board->id, $board->course, false, MUST_EXIST);
$context = context_module::instance($cm->id);

$columns = $DB->get_records('board_columns', array('boardid' => $boardid));
$columns = $DB->get_records('board_columns', ['boardid' => $boardid]);
foreach ($columns as $columnid => $column) {
$notes = $DB->get_records('board_notes', array('columnid' => $columnid));
$notes = $DB->get_records('board_notes', ['columnid' => $columnid]);
foreach ($notes as $noteid => $note) {
$pattern = '/pluginfile.php\/(\d+)\//i';
$replacement = 'pluginfile.php/'.$context->id.'/';
$url = preg_replace($pattern, $replacement, $note->url);

$DB->update_record('board_notes', array('id' => $noteid, 'url' => $url));
$DB->update_record('board_notes', ['id' => $noteid, 'url' => $url]);
}
}
}
Expand Down
Loading