Skip to content

Commit

Permalink
Merge pull request #910 from catalyst/issue909
Browse files Browse the repository at this point in the history
issue #909: Moodle 4.5 support
  • Loading branch information
tuanngocnguyen authored Nov 15, 2024
2 parents b03f51a + 91d9fc2 commit 9034f9c
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 52 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ Dataflows is a generic workflow and processing engine which can be configured to

## Branches

| Moodle version | Branch | PHP |
|----------------|------------------|-----------|
| Moodle 4.1+ | MOODLE_41_STABLE | 7.4 | 8.0 |
| Totara 10+ | MOODLE_35_STABLE | 7.1 - 7.4 |
| Moodle version | Branch | PHP |
|----------------|-------------------|-----------|
| Moodle 4.1-4.2 | MOODLE_401_STABLE | 7.4 |
| Moodle 4.5 | MOODLE_405_STABLE | 8.1 - 8.3 |
| Totara 10+ | MOODLE_35_STABLE | 7.1 - 7.4 |

Note: Moodle 402 is supported with PHP 8.0 maximum at the moment

Expand Down
10 changes: 10 additions & 0 deletions classes/local/execution/iterators/dataflow_iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ class dataflow_iterator implements iterator {
/** @var int */
protected $iterationcount = 0;

/**
* @var \tool_dataflows\local\variables\var_step|null
*/
protected $stepvars = null;

/**
* @var null
*/
protected $pulled = null;

/**
* Create an instance of this class.
*
Expand Down
44 changes: 44 additions & 0 deletions classes/local/hooks/after_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

namespace tool_dataflows\local\hooks;

/**
* After config hook
*
* @package tool_dataflows
* @copyright 2024 Catalyst IT Australia
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_config {

/**
* Hook to be run after initial site config.
*
* Triggered as soon as practical on every moodle bootstrap after config has
* been loaded. The $USER object is available at this point too.
*
* This currently ensures all vendor libraries are loaded.
*
* @param \core\hook\after_config $hook
* return void
*/
public static function callback(\core\hook\after_config $hook): void {
global $CFG;

require_once($CFG->dirroot. '/admin/tool/dataflows/lib.php');
}
}
6 changes: 6 additions & 0 deletions classes/local/step/flow_cap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
*/
final class flow_cap extends flow_step {

/**
* Upstream interator.
* @var
*/
protected $upstream;

/**
* Generates an engine step for this type.
*
Expand Down
12 changes: 7 additions & 5 deletions classes/local/step/trigger_event.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ private function get_events_list() {
$eventlist = \tool_monitor\eventlist::get_all_eventlist();
$pluginlist = \tool_monitor\eventlist::get_plugin_list($eventlist);
$plugineventlist = [];
foreach ($pluginlist as $plugin => $pluginname) {
foreach ($eventlist[$plugin] as $event => $eventname) {
// Filter out events which cannot be triggered for some reason.
if (!$event::is_deprecated()) {
$plugineventlist[$event] = "{$pluginname}: {$eventname}";
foreach ($pluginlist as $plugintype => $plugins) {
foreach ($plugins as $plugin => $pluginname) {
foreach ($eventlist[$plugin] as $event => $eventname) {
// Filter out events which cannot be triggered for some reason.
if (!$event::is_deprecated()) {
$plugineventlist[$event] = "{$pluginname}: {$eventname}";
}
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions classes/step.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class step extends persistent {
/** @var array array for lazy loading step dependants */
private $dependents = null;

/** @var dataflow Dataflow */
protected $dataflow = null;

/** @var base_step step type */
protected $steptype;

/**
* Return the definition of the properties of this model.
*
Expand Down Expand Up @@ -495,7 +501,7 @@ public function upsert() {
// Update the local dependencies to the database.
$this->update_depends_on();

$this->steptype->on_save();
$this->get_steptype()->on_save();
$this->get_dataflow()->on_steps_save();

return $this;
Expand Down Expand Up @@ -628,7 +634,7 @@ protected function before_delete() {
$DB->delete_records('tool_dataflows_step_depends', ['stepid' => $this->id]);
$DB->delete_records('tool_dataflows_step_depends', ['dependson' => $this->id]);

$steptype = $this->steptype;
$steptype = $this->get_steptype();
if (isset($steptype)) {
$steptype->on_delete();
}
Expand Down Expand Up @@ -728,7 +734,7 @@ protected function validate_config() {
return new \lang_string('invalidyaml', 'tool_dataflows');
}

$validation = $this->steptype->validate_config($yaml);
$validation = $this->get_steptype()->validate_config($yaml);
if ($validation !== true) {
// NOTE: This will only return the first error as the persistent
// class expects the return value to be an instance of lang_string.
Expand All @@ -748,7 +754,7 @@ protected function validate_config() {
*/
protected function validate_link_count(int $count, string $inputoutput, string $flowconnector) {
$fn = "get_number_of_{$inputoutput}_{$flowconnector}s";
$steptype = $this->steptype;
$steptype = $this->get_steptype();
[$min, $max] = $steptype->$fn();
if ($inputoutput === 'output') {
$min = max($min, count($steptype->get_output_labels()));
Expand Down Expand Up @@ -778,7 +784,7 @@ protected function validate_links(array $deps, string $inputoutput) {
$count = count($deps);
$errors = [];

$steptype = $this->steptype;
$steptype = $this->get_steptype();

if ($count != 0) {
$dep = array_shift($deps);
Expand Down Expand Up @@ -877,7 +883,7 @@ public function has_side_effect(): bool {
if ($typevalidation !== true) {
return false;
}
return $this->steptype->has_side_effect();
return $this->get_steptype()->has_side_effect();
}

/**
Expand Down
33 changes: 33 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Hooks callbacks.
*
* @package tool_dataflows
* @copyright 2024 Catalyst IT Australia
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$callbacks = [
[
'hook' => \core\hook\after_config::class,
'callback' => '\tool_dataflows\local\hooks\after_config::callback',
'priority' => 0,
],
];
9 changes: 0 additions & 9 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
use tool_dataflows\local\formats\encoders;
use tool_dataflows\local\step;

/**
* Triggered as soon as practical on every moodle bootstrap after config has
* been loaded. The $USER object is available at this point too.
*
* NOTE: DO NOT REMOVE. This currently ensures all vendor libraries are loaded.
*/
function tool_dataflows_after_config() {
}

/**
* Returns a list of step types available for this plugin.
*
Expand Down
15 changes: 2 additions & 13 deletions tests/application_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function compatible_assertMatchesRegularExpression(string $pattern, strin
if (method_exists($this, 'assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression($pattern, $string, $message);
} else {
$this->assertRegExp($pattern, $string, $message);
$this->assertDoesNotMatchRegularExpression($pattern, $string, $message);
}
}

Expand All @@ -119,18 +119,7 @@ public function compatible_assertDoesNotMatchRegularExpression(string $pattern,
if (method_exists($this, 'assertDoesNotMatchRegularExpression')) {
$this->assertDoesNotMatchRegularExpression($pattern, $string, $message);
} else {
$this->assertNotRegExp($pattern, $string, $message);
}
}

/**
* Asserts that an error was expected
*/
public function compatible_expectError(): void {
if (method_exists($this, 'expectError')) {
$this->expectError();
} else {
$this->expectException(\PHPUnit\Framework\Error\Error::class);
$this->assertDoesNotMatchRegularExpression($pattern, $string, $message);
}
}
// @codingStandardsIgnoreEnd
Expand Down
18 changes: 9 additions & 9 deletions tests/tool_dataflows_connector_curl_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public function test_execute() {
$this->assertEquals('3d188fbf-d0b7-4d4e-ae4d-4b5548df824e', $result->uuid);

$this->assertEquals(200, $vars->httpcode);
$this->assertObjectHasAttribute('connecttime', $vars);
$this->assertObjectHasAttribute('totaltime', $vars);
$this->assertObjectHasAttribute('sizeupload', $vars);
$this->assertObjectHasProperty('connecttime', $vars);
$this->assertObjectHasProperty('totaltime', $vars);
$this->assertObjectHasProperty('sizeupload', $vars);

$testurl = $this->get_mock_url('/test_post.php');

Expand Down Expand Up @@ -115,9 +115,9 @@ public function test_execute() {
$vars = $engine->get_variables_root()->get('steps.connector.vars');

$this->assertEquals(200, $vars->httpcode);
$this->assertObjectHasAttribute('connecttime', $vars);
$this->assertObjectHasAttribute('totaltime', $vars);
$this->assertObjectHasAttribute('sizeupload', $vars);
$this->assertObjectHasProperty('connecttime', $vars);
$this->assertObjectHasProperty('totaltime', $vars);
$this->assertObjectHasProperty('sizeupload', $vars);

// Tests put method.
$stepdef->config = Yaml::dump([
Expand Down Expand Up @@ -145,9 +145,9 @@ public function test_execute() {

// PUT has no response body so it shouldn't be checked.
$this->assertEquals(200, $vars->httpcode);
$this->assertObjectHasAttribute('connecttime', $vars);
$this->assertObjectHasAttribute('totaltime', $vars);
$this->assertObjectHasAttribute('sizeupload', $vars);
$this->assertObjectHasProperty('connecttime', $vars);
$this->assertObjectHasProperty('totaltime', $vars);
$this->assertObjectHasProperty('sizeupload', $vars);

$expectedbash = "curl -s -X PUT {$testurl} --max-time 30 --data-raw 'data=moodletest'";
$this->assertEquals($expectedbash, $variables->dbgcommand);
Expand Down
31 changes: 31 additions & 0 deletions tests/tool_dataflows_event_processor_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,37 @@
*/
class tool_dataflows_event_processor_test extends \advanced_testcase {

/**
* Test workflow.
* @var \tool_dataflows\dataflow
*/
protected $dataflow;

/**
* Test writer.
* @var
*/
protected $writer;

/**
* Test reader.
* @var
*/
protected $reader;

/**
* Test course.
*
* @var \stdClass
*/
protected $course;

/**
* Test output path.
* @var
*/
protected $outputpath;

/**
* Set up before each test
*/
Expand Down
35 changes: 35 additions & 0 deletions tests/tool_dataflows_flow_sql_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_dataflows_flow_sql_test extends \advanced_testcase {
/**
* Test workflow.
* @var \tool_dataflows\dataflow
*/
protected $dataflow;

/**
* Test writer.
* @var
*/
protected $writer;

/**
* Test reader.
* @var
*/
protected $reader;

/**
* Test input path.
* @var false|string
*/
protected $inputpath;

/**
* Test output path.
* @var
*/
protected $outputpath;

/**
* Test flow step.
* @var \tool_dataflows\step
*/
protected $flow;

/**
* Set up before each test
Expand Down
Loading

0 comments on commit 9034f9c

Please sign in to comment.