Skip to content

Commit

Permalink
issue #33: support for Moodle 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriim committed Nov 19, 2024
1 parent b396d1e commit 0a99ead
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 24 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/catalyst/moodle-tool_s3logs/ci/master)
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/catalyst/moodle-tool_s3logs/ci/MOODLE_405_STABLE)


# Moodle to Amazon S3 Log Archiver #
Expand All @@ -14,13 +14,17 @@ The plugin functionality runs as a Moodle scheduled task.
## Supported Moodle Versions
This plugin currently supports Moodle:

* 3.5+
| Moodle version | Branch |
|-------------------|-------------------|
| Moodle 4.5+ | MOODLE_405_STABLE |
| Moodle 3.5 to 4.1 | master |



## Installation

1. Get the code and copy/ install it to: `<moodledir>/admin/tool/s3logs`
2. This plugin also depends on *local_aws* get the code from `https://github.com/catalyst/moodle-local_aws` and copy/ install it into `<moodledir>/local/aws`
3. Run the upgrade: `sudo -u www-data php admin/cli/upgrade` **Note:** the user may be different to www-data on your system.
2. Run the upgrade: `sudo -u www-data php admin/cli/upgrade` **Note:** the user may be different to www-data on your system.

## Configuration
1. Configure the plugin in *Site administration > Plugins > Admin Tools > S3 log archiver*.
Expand Down
68 changes: 68 additions & 0 deletions classes/admin_settings_aws_region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.

namespace tool_s3logs;

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

require_once($CFG->dirroot . '/lib/adminlib.php');

/**
* Admin setting for a list of AWS regions.
*
* @package tool_s3logs
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_settings_aws_region extends \admin_setting_configtext {

/**
* Return part of form with setting.
*
* @param mixed $data array or string depending on setting
* @param string $query
* @return string
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;

$default = $this->get_defaultsetting();
$options = [];
// We do require() not require_once() here, as the file returns a value and we may need to get
// this value more than once.
$all = require($CFG->dirroot . '/lib/aws-sdk/src/data/endpoints.json.php');
$ends = $all['partitions'][0]['regions'];
if ($ends) {
foreach ($ends as $key => $value) {
$options[] = [
'value' => $key,
'label' => $key . ' - ' . $value['description'],
];
}
}

$context = [
'list' => $this->get_full_name(),
'name' => $this->get_full_name(),
'id' => $this->get_id(),
'value' => $data,
'size' => $this->size,
'options' => $options,
];
$element = $OUTPUT->render_from_template('tool_s3logs/setting_aws_region', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
}
13 changes: 1 addition & 12 deletions classes/local/client/s3_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* S3 Client helper class.
*
* @package tool_s3logs
* @copyright 2017 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_s3logs\local\client;

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

require_once($CFG->dirroot . '/local/aws/sdk/aws-autoloader.php');

use Aws\S3\S3Client;

/**
Expand Down Expand Up @@ -103,7 +92,7 @@ private function set_client() {
$settings['credentials'] = ['key' => $this->config->keyid, 'secret' => $this->config->secretkey];
}

$this->client = S3Client::factory($settings);
$this->client = new S3Client($settings);
}
}

Expand Down
2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

use tool_s3logs\local\client\s3_client;
use local_aws\admin_settings_aws_region;
use tool_s3logs\admin_settings_aws_region;

global $PAGE;

Expand Down
50 changes: 50 additions & 0 deletions templates/setting_aws_region.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{!
This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
}}
{{!
@template tool_s3logs/setting_aws_region
Admin aws region setting template.
Context variables required for this template:
* list - form list name
* name - form element name
* id - element id
* value - element value
* size - element size
* options - list of data list options: label, value.
Example context (json):
{
"list": "test",
"name": "test",
"id": "test0",
"value": "A tall, dark stranger will have more fun than you.",
"size": "21",
"options": [ { "label": "eu-north-1 - Europe (Stockholm)", "value": "eu-north-1" } ]
}
}}
{{!
Setting config aws region
}}
<div class="form-text defaultsnext">
<input type="text" list="{{list}}" name="{{name}}" value="{{value}}" size="{{size}}" id="{{id}}" class="form-control text-ltr" {{#readonly}}disabled{{/readonly}}>
<datalist id="{{list}}">
{{#options}}
<option value="{{value}}" label="{{label}}"></option>
{{/options}}
</datalist>
</div>
11 changes: 4 additions & 7 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'tool_s3logs';
$plugin->version = 2022081101;
$plugin->release = 2022081101;
$plugin->requires = 2017051509;
$plugin->version = 2024111900;
$plugin->release = 2024111900;
$plugin->requires = 2024100700;
$plugin->maturity = MATURITY_STABLE;
$plugin->supported = [35, 401];
$plugin->dependencies = array(
'local_aws' => 2017030100
);
$plugin->supported = [405, 405];

0 comments on commit 0a99ead

Please sign in to comment.