Skip to content

Commit

Permalink
Merge branch 'master' into fix/dont_show_unenrolled_in_statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe authored Jul 30, 2024
2 parents 41bf92a + 41670f1 commit 46973e0
Show file tree
Hide file tree
Showing 82 changed files with 3,185 additions and 1,225 deletions.
95 changes: 30 additions & 65 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:

strategy:
matrix:
php: ['8.2']
moodle-branch: ['MOODLE_403_STABLE']
php: ['8.3']
moodle-branch: ['MOODLE_404_STABLE']
database: ['pgsql']

steps:
- name: Start PostgreSQL
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

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

Expand All @@ -28,29 +28,9 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
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
sudo locale-gen en_AU.UTF-8
Expand All @@ -67,11 +47,6 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci phplint

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

- name: PHP Mess Detector
if: ${{ always() }}
run: moodle-plugin-ci phpmd
Expand Down Expand Up @@ -108,31 +83,27 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE']
php: ['8.0', '8.1', '8.2', '8.3']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE']
database: ['mariadb', 'pgsql']
exclude:
- php: '8.0'
moodle-branch: 'MOODLE_404_STABLE'
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
- php: '8.3'
moodle-branch: 'MOODLE_401_STABLE'
- php: '8.3'
moodle-branch: 'MOODLE_402_STABLE'
- php: '8.3'
moodle-branch: 'MOODLE_403_STABLE'
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'

steps:
- name: Start MariaDB
Expand All @@ -144,7 +115,7 @@ jobs:
run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

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

Expand All @@ -155,24 +126,6 @@ jobs:
ini-values: max_input_vars=5000
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Composer cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: npm cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
Expand All @@ -195,3 +148,15 @@ jobs:
- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome --auto-rerun 0

# This step allows to upload Behat faildump (screenshots) as workflow artifact,
# so it can be downloaded and inspected. You do not need this step if you
# are not running Behat test. Artifact will be retained for 7 days.
- 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
46 changes: 27 additions & 19 deletions backup/moodle2/backup_ratingallocate_activity_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,62 @@

require_once(dirname(__FILE__) . '/backup_restore_helper.php');

use ratingallocate\db as this_db;
use mod_ratingallocate\db as this_db;

/**
* Define the complete ratingallocate structure for backup, with [file and] id annotations
* Class to define the complete ratingallocate structure for backup, with [file and] id annotations
*
* @package mod_ratingallocate
* @copyright 2014 C. Usener
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_ratingallocate_activity_structure_step extends backup_activity_structure_step {

/**
* Define the complete ratingallocate structure for backup.
* @return backup_nested_element
* @throws ReflectionException
* @throws base_element_struct_exception
* @throws base_step_exception
*/
protected function define_structure() {

// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated.
$class = 'ratingallocate\db\ratingallocate';
$class = 'mod_ratingallocate\db\ratingallocate';
$ratingallocate = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$class = 'ratingallocate\db\ratingallocate_choices';
$class = 'mod_ratingallocate\db\ratingallocate_choices';
$ratingallocatechoices = new backup_nested_element(get_tablename_for_tableClass($class) . 's');
$ratingallocatechoice = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$class = 'ratingallocate\db\ratingallocate_ratings';
$class = 'mod_ratingallocate\db\ratingallocate_ratings';
$ratingallocateratings = new backup_nested_element(get_tablename_for_tableClass($class) . 's');
$ratingallocaterating = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$class = 'ratingallocate\db\ratingallocate_allocations';
$class = 'mod_ratingallocate\db\ratingallocate_allocations';
$ratingallocateallocations = new backup_nested_element(get_tablename_for_tableClass($class) . 's');
$ratingallocateallocation = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$groupchoiceclass = 'ratingallocate\db\ratingallocate_group_choices';
$groupchoiceclass = 'mod_ratingallocate\db\ratingallocate_group_choices';
$groupchoices = new backup_nested_element(get_tablename_for_tableClass($groupchoiceclass) . 's');
$groupchoice = new backup_nested_element(get_tablename_for_tableClass($groupchoiceclass),
get_id_for_tableClass($groupchoiceclass),
get_fields_for_tableClass($groupchoiceclass));

$choicegroupclass = 'ratingallocate\db\ratingallocate_ch_gengroups';
$choicegroupclass = 'mod_ratingallocate\db\ratingallocate_ch_gengroups';
$ratingallocatechoicegroups = new backup_nested_element(get_tablename_for_tableClass($choicegroupclass) . 's');
$ratingallocatechoicegroup = new backup_nested_element(get_tablename_for_tableClass($choicegroupclass),
get_id_for_tableClass($choicegroupclass),
get_fields_for_tableClass($choicegroupclass));

$groupingclass = 'ratingallocate\db\ratingallocate_groupings';
$groupingclass = 'mod_ratingallocate\db\ratingallocate_groupings';
$ratingallocategroupings = new backup_nested_element(get_tablename_for_tableClass($groupingclass) . 's');
$ratingallocategrouping = new backup_nested_element(get_tablename_for_tableClass($groupingclass),
get_id_for_tableClass($groupingclass),
Expand All @@ -92,10 +99,10 @@ protected function define_structure() {
$ratingallocatechoicegroups->add_child($ratingallocatechoicegroup);

// Define sources.
$ratingallocate->set_source_table(get_tablename_for_tableClass('ratingallocate\db\ratingallocate'),
array(this_db\ratingallocate::ID => backup::VAR_ACTIVITYID), this_db\ratingallocate_choices::ID . ' ASC');
$ratingallocatechoice->set_source_table(get_tablename_for_tableClass('ratingallocate\db\ratingallocate_choices'),
array(this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID),
$ratingallocate->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'),
[this_db\ratingallocate::ID => backup::VAR_ACTIVITYID], this_db\ratingallocate_choices::ID . ' ASC');
$ratingallocatechoice->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_choices'),
[this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID],
this_db\ratingallocate_choices::ID . ' ASC');
$groupchoice->set_source_table(get_tablename_for_tableClass($groupchoiceclass), ['choiceid' => backup::VAR_PARENTID]);
$ratingallocatechoicegroup->set_source_table(
Expand All @@ -105,14 +112,15 @@ protected function define_structure() {

if ($userinfo) {
$ratingallocaterating->set_source_table(get_tablename_for_tableClass(
'ratingallocate\db\ratingallocate_ratings'),
array(this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID),
'mod_ratingallocate\db\ratingallocate_ratings'),
[this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID],
this_db\ratingallocate_ratings::ID . ' ASC');
$ratingallocateallocation->set_source_table(
get_tablename_for_tableClass('ratingallocate\db\ratingallocate_allocations'),
array(
this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID,
this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID),
get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_allocations'),
[
this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID,
this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID,
],
this_db\ratingallocate_allocations::ID . ' ASC'
);
}
Expand Down
31 changes: 27 additions & 4 deletions backup/moodle2/backup_restore_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,55 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package moodlecore
* Backup restore helper.
*
* @package mod_ratingallocate
* @subpackage backup-moodle2
* @copyright 2014 C. Usener
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Get fields for tableclass
*
* @param $class
* @return array
* @throws ReflectionException
*/
function get_fields_for_tableclass($class) {
$class = new ReflectionClass($class);
$constants = $class->getConstants();
$keystoremove = array('ID', 'TABLE');
$keystoremove = ['ID', 'TABLE'];
foreach ($constants as $key => $value) {
if (count(array_intersect(array($key), $keystoremove)) > 0) {
if (count(array_intersect([$key], $keystoremove)) > 0) {
unset($constants[$key]);
}
}
return array_values($constants);
}

/**
* Get tablename for tableclass.
*
* @param $class
* @return mixed
* @throws ReflectionException
*/
function get_tablename_for_tableclass($class) {
$class = new ReflectionClass($class);
$constants = $class->getConstants();
return $constants['TABLE'];
}

/**
* Get id for tableclass.
*
* @param $class
* @return array
* @throws ReflectionException
*/
function get_id_for_tableclass($class) {
$class = new ReflectionClass($class);
$constants = $class->getConstants();
return array($constants['ID']);
return [$constants['ID']];
}
Loading

0 comments on commit 46973e0

Please sign in to comment.