Compare commits
30
Commits
main
..
v4.0.0-rc.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17ae01ab71 | ||
|
|
28e1169be8 | ||
|
|
2126708201 | ||
|
|
0041667754 | ||
|
|
91bf79f030 | ||
|
|
7d1a0b9fec | ||
|
|
51007a0fb5 | ||
|
|
2eaa622161 | ||
|
|
3d4b78bd8b | ||
|
|
41185c6db4 | ||
|
|
7e1284bfe2 | ||
|
|
785a541d1c | ||
|
|
6e3bf072af | ||
|
|
2e57e732ba | ||
|
|
499f36d118 | ||
|
|
49516bea82 | ||
|
|
a6c6081139 | ||
|
|
9560267833 | ||
|
|
2057a1efb6 | ||
|
|
0cbf2bbb87 | ||
|
|
3e054dd94e | ||
|
|
54fb29c5ea | ||
|
|
78e9e435cc | ||
|
|
97711bb186 | ||
|
|
999ad9f472 | ||
|
|
82c7463e4a | ||
|
|
e0e9322644 | ||
|
|
7278ee951b | ||
|
|
01e2ba9f2f | ||
|
|
99868c158a |
+32
-38
@@ -1,38 +1,35 @@
|
|||||||
language: php
|
language: php
|
||||||
sudo: true
|
|
||||||
|
|
||||||
addons:
|
sudo: false
|
||||||
firefox: "latest-esr"
|
|
||||||
postgresql: "9.6"
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- "oracle-java8-installer"
|
|
||||||
- "oracle-java8-set-default"
|
|
||||||
|
|
||||||
cache:
|
os: "linux"
|
||||||
directories:
|
|
||||||
- "$HOME/.composer/cache"
|
|
||||||
- "$HOME/.npm"
|
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 7.0
|
- 5.6
|
||||||
- 7.1
|
- 7.1
|
||||||
- 7.2
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
- DB=pgsql MOODLE_BRANCH=MOODLE_26_STABLE
|
||||||
- MOODLE_BRANCH=MOODLE_35_STABLE
|
- DB=pgsql MOODLE_BRANCH=MOODLE_27_STABLE
|
||||||
matrix:
|
- DB=pgsql MOODLE_BRANCH=MOODLE_28_STABLE
|
||||||
- DB=mysqli
|
- DB=pgsql MOODLE_BRANCH=MOODLE_29_STABLE
|
||||||
- DB=pgsql
|
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
|
||||||
|
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
|
||||||
|
- DB=pgsql MOODLE_BRANCH=MOODLE_32_STABLE
|
||||||
|
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_26_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_27_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_28_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_29_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_30_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_31_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_32_STABLE
|
||||||
|
- DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- phpenv config-rm xdebug.ini
|
|
||||||
- nvm install 8.9
|
|
||||||
- nvm use 8.9
|
|
||||||
- cd ../..
|
- cd ../..
|
||||||
- composer selfupdate
|
- composer selfupdate
|
||||||
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2
|
- composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1
|
||||||
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
|
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@@ -43,34 +40,31 @@ script:
|
|||||||
- moodle-plugin-ci phpcpd
|
- moodle-plugin-ci phpcpd
|
||||||
- moodle-plugin-ci phpmd
|
- moodle-plugin-ci phpmd
|
||||||
- moodle-plugin-ci codechecker
|
- moodle-plugin-ci codechecker
|
||||||
- moodle-plugin-ci validate
|
- moodle-plugin-ci csslint
|
||||||
- moodle-plugin-ci savepoints
|
- moodle-plugin-ci shifter
|
||||||
- moodle-plugin-ci mustache
|
- moodle-plugin-ci jshint
|
||||||
- moodle-plugin-ci grunt
|
|
||||||
- moodle-plugin-ci phpunit
|
- moodle-plugin-ci phpunit
|
||||||
- moodle-plugin-ci behat
|
- moodle-plugin-ci behat
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- stage: test old
|
stage: deploy
|
||||||
env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
|
|
||||||
php: 5.6
|
|
||||||
|
|
||||||
- stage: deploy
|
env:
|
||||||
php: 7.2
|
- DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
|
||||||
|
|
||||||
|
php: 7.1
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- cd "$TRAVIS_REPO_SLUG"
|
- cd $TRAVIS_REPO_SLUG
|
||||||
- git stash --all
|
- git stash --all
|
||||||
- /bin/sh build.sh
|
- /bin/sh build.sh
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
api_key: $GITHUB_PROJECT_TOKEN
|
|
||||||
email: "info@valentineus.link"
|
|
||||||
file: "../build/*.zip"
|
|
||||||
file_glob: true
|
|
||||||
provider: releases
|
provider: releases
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
|
file: "../local_webhooks.zip"
|
||||||
|
email: "info@valentineus.link"
|
||||||
|
api_key: $GITHUB_PROJECT_TOKEN
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
@@ -20,27 +20,11 @@ Features:
|
|||||||
* Use a secret phrase to authenticate requests;
|
* Use a secret phrase to authenticate requests;
|
||||||
* [JSON](https://en.wikipedia.org/wiki/JSON) - Format of outgoing data;
|
* [JSON](https://en.wikipedia.org/wiki/JSON) - Format of outgoing data;
|
||||||
|
|
||||||
## Installation
|
## Documentation
|
||||||
|
|
||||||
Get the installation package in any of the available methods:
|
* [Install the plugin](docs/getting-started.md#installation).
|
||||||
|
* [User guide](docs/getting-started.md#user-guide).
|
||||||
* [GitHub Releases](https://github.com/valentineus/moodle-webhooks/releases).
|
* [Request format](docs/getting-started.md#request-format).
|
||||||
* [Compilation from the source code](#build).
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
Self-assembly package is as follows:
|
|
||||||
|
|
||||||
* Clone the repository:
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/valentineus/moodle-webhooks.git moodle-webhooks
|
|
||||||
```
|
|
||||||
|
|
||||||
* Run the build script:
|
|
||||||
```bash
|
|
||||||
cd ./moodle-webhooks
|
|
||||||
/bin/sh build.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,21 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Author: Valentin Popov
|
# Author: Valentin Popov
|
||||||
# Email: info@valentineus.link
|
# Email: info@valentineus.link
|
||||||
# Date: 2018-06-19
|
# Date: 2017-10-19
|
||||||
# Usage: /bin/sh ./build.sh
|
# Usage: /bin/sh build.sh
|
||||||
# Description: Build the final package for installation in Moodle.
|
# Description: Build the final package for installation in Moodle.
|
||||||
|
|
||||||
# Updating the Environment
|
# Updating the Environment
|
||||||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
export PATH="$PATH:/usr/local/scripts"
|
export PATH="$PATH:/usr/local/scripts"
|
||||||
|
|
||||||
# Current project
|
# Build the package
|
||||||
PROJECT="local_webhooks"
|
cd ..
|
||||||
|
mv "./moodle-webhooks" "./local_webhooks"
|
||||||
# Defining directories
|
zip -9 -r "local_webhooks.zip" "local_webhooks" \
|
||||||
DIRECTORY="$(pwd)"
|
-x "local_webhooks/.git*" \
|
||||||
NAMEDIR="$(basename $DIRECTORY)"
|
-x "local_webhooks/.travis.yml" \
|
||||||
TMPDIR="$(mktemp --directory)"
|
-x "local_webhooks/build.sh"
|
||||||
|
|
||||||
# Creating a Temporary Directory
|
|
||||||
cp --recursive --verbose "../$NAMEDIR" "$TMPDIR/$PROJECT"
|
|
||||||
mkdir --parents --verbose "$DIRECTORY/build"
|
|
||||||
cd "$TMPDIR"
|
|
||||||
|
|
||||||
# Creating an archive
|
|
||||||
zip -9 -r "$DIRECTORY/build/$PROJECT.zip" "$PROJECT" \
|
|
||||||
-x "$PROJECT/.git*" \
|
|
||||||
-x "$PROJECT/.travis.yml" \
|
|
||||||
-x "$PROJECT/build*"
|
|
||||||
|
|
||||||
# End of work
|
# End of work
|
||||||
exit 0
|
exit 0
|
||||||
@@ -24,11 +24,7 @@
|
|||||||
|
|
||||||
namespace local_webhooks\event;
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
use core\event\base;
|
|
||||||
use lang_string;
|
|
||||||
use moodle_url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -36,40 +32,34 @@ use moodle_url;
|
|||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class backup_performed extends base {
|
class backup_performed extends \core\event\base {
|
||||||
/**
|
|
||||||
* Return localised event name.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public static function get_name() {
|
|
||||||
return new lang_string('create', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns description of what happened.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public function get_description() {
|
|
||||||
return new lang_string('backup', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL related to the action.
|
|
||||||
*
|
|
||||||
* @throws \moodle_exception
|
|
||||||
*/
|
|
||||||
public function get_url() {
|
|
||||||
return new moodle_url('/local/webhooks/index.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method.
|
* Init method.
|
||||||
*/
|
*/
|
||||||
protected function init() {
|
protected function init() {
|
||||||
$this->data['crud'] = 'c';
|
$this->data["crud"] = "c";
|
||||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
$this->data['objecttable'] = 'local_webhooks_service';
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("create", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return new \lang_string("backup", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/index.php");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,7 @@
|
|||||||
|
|
||||||
namespace local_webhooks\event;
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
use core\event\base;
|
|
||||||
use lang_string;
|
|
||||||
use moodle_url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -36,40 +32,34 @@ use moodle_url;
|
|||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class backup_restored extends base {
|
class backup_restored extends \core\event\base {
|
||||||
/**
|
|
||||||
* Return localised event name.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public static function get_name() {
|
|
||||||
return new lang_string('update', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns description of what happened.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public function get_description() {
|
|
||||||
return new lang_string('backupfinished', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL related to the action.
|
|
||||||
*
|
|
||||||
* @throws \moodle_exception
|
|
||||||
*/
|
|
||||||
public function get_url() {
|
|
||||||
return new moodle_url('/local/webhooks/index.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method.
|
* Init method.
|
||||||
*/
|
*/
|
||||||
protected function init() {
|
protected function init() {
|
||||||
$this->data['crud'] = 'u';
|
$this->data["crud"] = "u";
|
||||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
$this->data['objecttable'] = 'local_webhooks_service';
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("update", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return new \lang_string("backupfinished", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/index.php");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,7 @@
|
|||||||
|
|
||||||
namespace local_webhooks\event;
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
use core\event\base;
|
|
||||||
use lang_string;
|
|
||||||
use moodle_url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -36,38 +32,34 @@ use moodle_url;
|
|||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class response_answer extends base {
|
class response_answer extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "r";
|
||||||
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return localised event name.
|
* Return localised event name.
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
public static function get_name() {
|
public static function get_name() {
|
||||||
return new lang_string('answer', 'moodle');
|
return new \lang_string("answer", "moodle");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns description of what happened.
|
* Returns description of what happened.
|
||||||
*/
|
*/
|
||||||
public function get_description() {
|
public function get_description() {
|
||||||
return $this->other['status'];
|
return $this->other["status"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get URL related to the action.
|
* Get URL related to the action.
|
||||||
*
|
|
||||||
* @throws \moodle_exception
|
|
||||||
*/
|
*/
|
||||||
public function get_url() {
|
public function get_url() {
|
||||||
return new moodle_url('/local/webhooks/editservice.php', array('serviceid' => $this->objectid));
|
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init method.
|
|
||||||
*/
|
|
||||||
protected function init() {
|
|
||||||
$this->data['crud'] = 'r';
|
|
||||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
|
||||||
$this->data['objecttable'] = 'local_webhooks_service';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,7 @@
|
|||||||
|
|
||||||
namespace local_webhooks\event;
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
use core\event\base;
|
|
||||||
use lang_string;
|
|
||||||
use moodle_url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -36,40 +32,34 @@ use moodle_url;
|
|||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class service_added extends base {
|
class service_added extends \core\event\base {
|
||||||
/**
|
|
||||||
* Return localised event name.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public static function get_name() {
|
|
||||||
return new lang_string('create', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns description of what happened.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public function get_description() {
|
|
||||||
return new lang_string('eventwebserviceservicecreated', 'webservice');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL related to the action.
|
|
||||||
*
|
|
||||||
* @throws \moodle_exception
|
|
||||||
*/
|
|
||||||
public function get_url() {
|
|
||||||
return new moodle_url('/local/webhooks/editservice.php', array('serviceid' => $this->objectid));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method.
|
* Init method.
|
||||||
*/
|
*/
|
||||||
protected function init() {
|
protected function init() {
|
||||||
$this->data['crud'] = 'c';
|
$this->data["crud"] = "c";
|
||||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
$this->data['objecttable'] = 'local_webhooks_service';
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("create", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return new \lang_string("eventwebserviceservicecreated", "webservice");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,7 @@
|
|||||||
|
|
||||||
namespace local_webhooks\event;
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
use core\event\base;
|
|
||||||
use lang_string;
|
|
||||||
use moodle_url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -36,40 +32,34 @@ use moodle_url;
|
|||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class service_deleted extends base {
|
class service_deleted extends \core\event\base {
|
||||||
/**
|
|
||||||
* Return localised event name.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public static function get_name() {
|
|
||||||
return new lang_string('deleted', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns description of what happened.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public function get_description() {
|
|
||||||
return new lang_string('eventwebserviceservicedeleted', 'webservice');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL related to the action.
|
|
||||||
*
|
|
||||||
* @throws \moodle_exception
|
|
||||||
*/
|
|
||||||
public function get_url() {
|
|
||||||
return new moodle_url('/local/webhooks/index.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method.
|
* Init method.
|
||||||
*/
|
*/
|
||||||
protected function init() {
|
protected function init() {
|
||||||
$this->data['crud'] = 'd';
|
$this->data["crud"] = "d";
|
||||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
$this->data['objecttable'] = 'local_webhooks_service';
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("deleted", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return new \lang_string("eventwebserviceservicedeleted", "webservice");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/index.php");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registration of the system of events.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines how to work with events.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class service_deletedall extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "d";
|
||||||
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("deleted", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return new \lang_string("deletecompletely", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/index.php");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,11 +24,7 @@
|
|||||||
|
|
||||||
namespace local_webhooks\event;
|
namespace local_webhooks\event;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
use core\event\base;
|
|
||||||
use lang_string;
|
|
||||||
use moodle_url;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -36,40 +32,34 @@ use moodle_url;
|
|||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class service_updated extends base {
|
class service_updated extends \core\event\base {
|
||||||
/**
|
|
||||||
* Return localised event name.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public static function get_name() {
|
|
||||||
return new lang_string('update', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns description of what happened.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
public function get_description() {
|
|
||||||
return new lang_string('eventwebserviceserviceupdated', 'webservice');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL related to the action.
|
|
||||||
*
|
|
||||||
* @throws \moodle_exception
|
|
||||||
*/
|
|
||||||
public function get_url() {
|
|
||||||
return new moodle_url('/local/webhooks/editservice.php', array('serviceid' => $this->objectid));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method.
|
* Init method.
|
||||||
*/
|
*/
|
||||||
protected function init() {
|
protected function init() {
|
||||||
$this->data['crud'] = 'u';
|
$this->data["crud"] = "u";
|
||||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||||
$this->data['objecttable'] = 'local_webhooks_service';
|
$this->data["objecttable"] = "local_webhooks_service";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return localised event name.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("update", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return new \lang_string("eventwebserviceserviceupdated", "webservice");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-59
@@ -24,20 +24,12 @@
|
|||||||
|
|
||||||
namespace local_webhooks;
|
namespace local_webhooks;
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
global $CFG;
|
require_once(__DIR__ . "/../lib.php");
|
||||||
|
|
||||||
require_once(__DIR__ . '/../lib.php');
|
|
||||||
require_once(__DIR__ . '/../locallib.php');
|
|
||||||
|
|
||||||
require_once($CFG->libdir . '/filelib.php');
|
|
||||||
|
|
||||||
use curl;
|
|
||||||
use local_webhooks_events;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines event handlers.
|
||||||
*
|
*
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
@@ -47,61 +39,16 @@ class handler {
|
|||||||
* External handler.
|
* External handler.
|
||||||
*
|
*
|
||||||
* @param object $event
|
* @param object $event
|
||||||
*
|
|
||||||
* @throws \dml_exception
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
public static function events($event) {
|
public static function events($event) {
|
||||||
$data = $event->get_data();
|
$data = $event->get_data();
|
||||||
|
|
||||||
if (!empty($callbacks = local_webhooks_get_list_records())) {
|
if ($callbacks = local_webhooks_get_list_records()) {
|
||||||
foreach ($callbacks as $callback) {
|
foreach ($callbacks as $callback) {
|
||||||
self::handler_callback($data, $callback);
|
if (boolval($callback->enable) && !empty($callback->events[$data["eventname"]])) {
|
||||||
|
local_webhooks_send_request($data, $callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes each callback.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param object $callback
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
|
||||||
private static function handler_callback($data, $callback) {
|
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
if ((bool) $callback->enable && !empty($callback->events[$data['eventname']])) {
|
|
||||||
$urlparse = parse_url($CFG->wwwroot);
|
|
||||||
|
|
||||||
$data['host'] = $urlparse['host'];
|
|
||||||
$data['token'] = $callback->token;
|
|
||||||
$data['extra'] = $callback->other;
|
|
||||||
|
|
||||||
self::send($data, $callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sending data to the node.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param object $callback
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
|
||||||
private static function send($data, $callback) {
|
|
||||||
$curl = new curl();
|
|
||||||
$curl->setHeader(array('Content-Type: application/' . $callback->type));
|
|
||||||
$curl->post($callback->url, json_encode($data));
|
|
||||||
|
|
||||||
$response = $curl->getResponse();
|
|
||||||
local_webhooks_events::response_answer($callback->id, $response);
|
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
<?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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Privacy Subsystem implementation for local_webhooks.
|
|
||||||
*
|
|
||||||
* @package local_webhooks
|
|
||||||
* @copyright 2020 Dmitrii Metelkin <dmitriim@catalyst-net.au>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace local_webhooks\privacy;
|
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
|
||||||
|
|
||||||
class provider implements
|
|
||||||
// This plugin does not store any personal user data.
|
|
||||||
\core_privacy\local\metadata\null_provider {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the language string identifier with the component's language
|
|
||||||
* file to explain why this plugin stores no data.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function get_reason() : string {
|
|
||||||
return 'privacy:metadata';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+73
-62
@@ -22,36 +22,11 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
require_once($CFG->libdir . '/formslib.php');
|
require_once(__DIR__ . "/../lib.php");
|
||||||
|
|
||||||
/**
|
require_once($CFG->libdir . "/formslib.php");
|
||||||
* Description of the form of restoration.
|
|
||||||
*
|
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
class service_backup_form extends moodleform {
|
|
||||||
/**
|
|
||||||
* Defines the standard structure of the form.
|
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
|
||||||
protected function definition() {
|
|
||||||
$mform =& $this->_form;
|
|
||||||
|
|
||||||
/* Form heading */
|
|
||||||
$mform->addElement('header', 'editserviceheader', new lang_string('restore', 'moodle'));
|
|
||||||
|
|
||||||
/* Download the file */
|
|
||||||
$mform->addElement('filepicker', 'backupfile', new lang_string('file', 'moodle'));
|
|
||||||
$mform->addRule('backupfile', null, 'required');
|
|
||||||
|
|
||||||
/* Control Panel */
|
|
||||||
$this->add_action_buttons(true, new lang_string('restore', 'moodle'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description editing form definition.
|
* Description editing form definition.
|
||||||
@@ -60,72 +35,108 @@ class service_backup_form extends moodleform {
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class service_edit_form extends moodleform {
|
class service_edit_form extends moodleform {
|
||||||
|
/**
|
||||||
|
* @param string $baseurl
|
||||||
|
*/
|
||||||
|
public function __construct($baseurl) {
|
||||||
|
parent::__construct($baseurl);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the standard structure of the form.
|
* Defines the standard structure of the form.
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
protected function definition() {
|
protected function definition() {
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
$size = ['size' => 60];
|
$size = array("size" => 60);
|
||||||
|
|
||||||
/* Form heading */
|
/* Form heading */
|
||||||
$mform->addElement('header', 'editserviceheader', new lang_string('service', 'webservice'));
|
$mform->addElement("header", "editserviceheader", new lang_string("service", "webservice"));
|
||||||
|
|
||||||
/* Name of the service */
|
/* Name of the service */
|
||||||
$mform->addElement('text', 'title', new lang_string('name', 'moodle'), $size);
|
$mform->addElement("text", "title", new lang_string("name", "moodle"), $size);
|
||||||
$mform->addRule('title', null, 'required');
|
$mform->addRule("title", null, "required");
|
||||||
$mform->setType('title', PARAM_NOTAGS);
|
$mform->setType("title", PARAM_NOTAGS);
|
||||||
|
|
||||||
/* Callback address */
|
/* Callback address */
|
||||||
$mform->addElement('text', 'url', new lang_string('url', 'moodle'), $size);
|
$mform->addElement("text", "url", new lang_string("url", "moodle"), $size);
|
||||||
$mform->addRule('url', null, 'required');
|
$mform->addRule("url", null, "required");
|
||||||
$mform->setType('url', PARAM_URL);
|
$mform->setType("url", PARAM_URL);
|
||||||
|
|
||||||
/* Enabling the service */
|
/* Enabling the service */
|
||||||
$mform->addElement('advcheckbox', 'enable', new lang_string('enable', 'moodle'));
|
$mform->addElement("advcheckbox", "enable", new lang_string("enable", "moodle"));
|
||||||
$mform->setType('enable', PARAM_BOOL);
|
$mform->setType("enable", PARAM_BOOL);
|
||||||
$mform->setDefault('enable', 1);
|
$mform->setDefault("enable", 1);
|
||||||
$mform->setAdvanced('enable');
|
$mform->setAdvanced("enable");
|
||||||
|
|
||||||
/* Token */
|
/* Token */
|
||||||
$mform->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
|
$mform->addElement("text", "token", new lang_string("token", "webservice"), $size);
|
||||||
$mform->setType('token', PARAM_NOTAGS);
|
$mform->setType("token", PARAM_NOTAGS);
|
||||||
|
|
||||||
/* Additional information */
|
/* Additional information */
|
||||||
$mform->addElement('text', 'other', new lang_string('sourceext', 'plugin'), $size);
|
$mform->addElement("text", "other", new lang_string("sourceext", "plugin"), $size);
|
||||||
$mform->setType('other', PARAM_NOTAGS);
|
$mform->setType("other", PARAM_NOTAGS);
|
||||||
$mform->setAdvanced('other');
|
$mform->setAdvanced("other");
|
||||||
|
|
||||||
/* Content type */
|
/* Content type */
|
||||||
$contenttype = [
|
$contenttype = array("json" => "application/json", "x-www-form-urlencoded" => "application/x-www-form-urlencoded");
|
||||||
'json' => 'application/json',
|
$mform->addElement("select", "type", "Content type", $contenttype);
|
||||||
'x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
|
$mform->setAdvanced("type");
|
||||||
];
|
|
||||||
|
|
||||||
$mform->addElement('select', 'type', 'Content type', $contenttype);
|
|
||||||
$mform->setAdvanced('type');
|
|
||||||
|
|
||||||
/* Form heading */
|
/* Form heading */
|
||||||
$mform->addElement('header', 'editserviceheaderevent', new lang_string('edulevel', 'moodle'));
|
$mform->addElement("header", "editserviceheaderevent", new lang_string("edulevel", "moodle"));
|
||||||
|
|
||||||
/* List of events */
|
/* List of events */
|
||||||
$eventlist = report_eventlist_list_generator::get_all_events_list();
|
$eventlist = local_webhooks_get_list_events();
|
||||||
$events = [];
|
$events = array();
|
||||||
|
|
||||||
/* Formation of the list of elements */
|
/* Formation of the list of elements */
|
||||||
foreach ($eventlist as $event) {
|
foreach ($eventlist as $event) {
|
||||||
/* Escaping event names */
|
$events[$event["component"]][] =& $mform->createElement("checkbox", $event["eventname"], $event["eventname"]);
|
||||||
$eventname = base64_encode($event['eventname']);
|
|
||||||
$events[$event['component']][] =& $mform->createElement('checkbox', $eventname, $event['eventname']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Displays groups of items */
|
/* Displays groups of items */
|
||||||
foreach ($events as $key => $event) {
|
foreach ($events as $key => $event) {
|
||||||
$mform->addGroup($event, 'events', $key, '<br />');
|
$mform->addGroup($event, "events", $key, "<br />", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Control Panel */
|
/* Control Panel */
|
||||||
$this->add_action_buttons();
|
$this->add_action_buttons(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of the form of restoration.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class service_backup_form extends moodleform {
|
||||||
|
/**
|
||||||
|
* @param string $baseurl
|
||||||
|
*/
|
||||||
|
public function __construct($baseurl) {
|
||||||
|
parent::__construct($baseurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the standard structure of the form.
|
||||||
|
*/
|
||||||
|
protected function definition() {
|
||||||
|
$mform =& $this->_form;
|
||||||
|
|
||||||
|
/* Form heading */
|
||||||
|
$mform->addElement("header", "editserviceheader", new lang_string("restore", "moodle"));
|
||||||
|
|
||||||
|
/* Flag for deleting existing data */
|
||||||
|
$mform->addElement("advcheckbox", "deleterecords", new lang_string("deleteall", "moodle"));
|
||||||
|
$mform->setType("deleterecords", PARAM_BOOL);
|
||||||
|
$mform->setDefault("deleterecords", 1);
|
||||||
|
|
||||||
|
/* Download the file */
|
||||||
|
$mform->addElement("filepicker", "backupfile", new lang_string("file", "moodle"));
|
||||||
|
$mform->addRule("backupfile", null, "required");
|
||||||
|
|
||||||
|
/* Control Panel */
|
||||||
|
$this->add_action_buttons(true, new lang_string("restore", "moodle"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the plugin tables.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/tablelib.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the main table of the plugin.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class local_webhooks_table extends table_sql {
|
||||||
|
/**
|
||||||
|
* Manager address.
|
||||||
|
*
|
||||||
|
* @var string $manager
|
||||||
|
*/
|
||||||
|
protected static $manager = "/local/webhooks/index.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editor's address.
|
||||||
|
*
|
||||||
|
* @var string $editor
|
||||||
|
*/
|
||||||
|
protected static $editor = "/local/webhooks/editservice.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param string $uniqueid The unique identifier of the table.
|
||||||
|
*/
|
||||||
|
public function __construct($uniqueid) {
|
||||||
|
parent::__construct($uniqueid);
|
||||||
|
$this->define_table_columns();
|
||||||
|
$this->define_table_configs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the basic settings of the table.
|
||||||
|
*/
|
||||||
|
public function define_table_configs() {
|
||||||
|
$this->set_sql("*", "{local_webhooks_service}", "1");
|
||||||
|
$this->collapsible(false);
|
||||||
|
$this->is_downloadable(false);
|
||||||
|
$this->no_sorting("actions");
|
||||||
|
$this->pageable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the main columns and table headers.
|
||||||
|
*/
|
||||||
|
public function define_table_columns() {
|
||||||
|
$columns = array(
|
||||||
|
"title",
|
||||||
|
"url",
|
||||||
|
"events",
|
||||||
|
"actions"
|
||||||
|
);
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
new lang_string("name", "moodle"),
|
||||||
|
new lang_string("url", "moodle"),
|
||||||
|
new lang_string("edulevel", "moodle"),
|
||||||
|
new lang_string("actions", "moodle")
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->define_columns($columns);
|
||||||
|
$this->define_headers($headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the display of a column with actions.
|
||||||
|
*
|
||||||
|
* @param object $row Data from the database.
|
||||||
|
* @return string Displayed data.
|
||||||
|
*/
|
||||||
|
public function col_actions($row) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
$hideshowicon = "t/show";
|
||||||
|
$hideshowstring = new lang_string("enable", "moodle");
|
||||||
|
if (boolval($row->enable)) {
|
||||||
|
$hideshowicon = "t/hide";
|
||||||
|
$hideshowstring = new lang_string("disable", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
$hideshowlink = new moodle_url(self::$manager, array("hideshowid" => $row->id, "sesskey" => sesskey()));
|
||||||
|
$hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($hideshowicon, $hideshowstring));
|
||||||
|
|
||||||
|
$editlink = new moodle_url(self::$editor, array("serviceid" => $row->id));
|
||||||
|
$edititem = $OUTPUT->action_icon($editlink, new pix_icon("t/edit", new lang_string("edit", "moodle")));
|
||||||
|
|
||||||
|
$deletelink = new moodle_url(self::$manager, array("deleteid" => $row->id, "sesskey" => sesskey()));
|
||||||
|
$deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon("t/delete", new lang_string("delete", "moodle")));
|
||||||
|
|
||||||
|
$html = $hideshowitem . $edititem . $deleteitem;
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the display of a column with events.
|
||||||
|
*
|
||||||
|
* @param object $row Data from the database.
|
||||||
|
* @return string Displayed data.
|
||||||
|
*/
|
||||||
|
public function col_events($row) {
|
||||||
|
$eventlist = local_webhooks_deserialization_data($row->events);
|
||||||
|
return count($eventlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the display of the column with the service name.
|
||||||
|
*
|
||||||
|
* @param object $row Data from the database.
|
||||||
|
* @return string Displayed data.
|
||||||
|
*/
|
||||||
|
public function col_title($row) {
|
||||||
|
$link = new moodle_url(self::$editor, array("serviceid" => $row->id));
|
||||||
|
$html = html_writer::link($link, $row->title);
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-7
@@ -22,14 +22,14 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
$observers = array(
|
$observers = array(
|
||||||
array(
|
array(
|
||||||
'callback' => '\local_webhooks\handler::events',
|
"callback" => "\local_webhooks\\handler::events",
|
||||||
'eventname' => '*',
|
"eventname" => "*",
|
||||||
'includefile' => null,
|
"includefile" => null,
|
||||||
'internal' => true,
|
"internal" => true,
|
||||||
'priority' => 200,
|
"priority" => 200
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="local/webhooks/db" VERSION="2018061900" COMMENT="XMLDB file for Moodle"
|
<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171029" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
|
|
||||||
<TABLES>
|
<TABLES>
|
||||||
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
|
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
|
||||||
<FIELDS>
|
<FIELDS>
|
||||||
|
|||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file registers the plugin's external functions.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
$functions = array(
|
||||||
|
"local_webhooks_change_status" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "change_status",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Change the status of the service.",
|
||||||
|
"type" => "write"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_get_record" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "get_record",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Get the record from the database.",
|
||||||
|
"type" => "read"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_get_list_records" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "get_list_records",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Get all records from the database.",
|
||||||
|
"type" => "read"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_get_list_events" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "get_list_events",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Get a list of all system events.",
|
||||||
|
"type" => "read"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_create_record" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "create_record",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Create an entry in the database.",
|
||||||
|
"type" => "write"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_update_record" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "update_record",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Update the record in the database.",
|
||||||
|
"type" => "write"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_delete_record" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "delete_record",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Delete the record from the database.",
|
||||||
|
"type" => "write"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_delete_all_records" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "delete_all_records",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Delete all records from the database.",
|
||||||
|
"type" => "write"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_create_backup" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "create_backup",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Create a backup.",
|
||||||
|
"type" => "read"
|
||||||
|
),
|
||||||
|
|
||||||
|
"local_webhooks_restore_backup" => array(
|
||||||
|
"classname" => "local_webhooks_external",
|
||||||
|
"methodname" => "restore_backup",
|
||||||
|
"classpath" => "local/webhooks/externallib.php",
|
||||||
|
"description" => "Restore from a backup.",
|
||||||
|
"type" => "write"
|
||||||
|
)
|
||||||
|
);
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps track of upgrades to the 'local_webhooks' plugin.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../lib.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to upgrade 'local_webhooks'.
|
||||||
|
*
|
||||||
|
* @param number $oldversion
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function xmldb_local_webhooks_upgrade($oldversion) {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
/* Update from version 3.0.0 */
|
||||||
|
if ($oldversion < 2017112600) {
|
||||||
|
$rs = $DB->get_recordset("local_webhooks_service", null, "id", "*", 0, 0);
|
||||||
|
foreach ($rs as $record) {
|
||||||
|
if (!empty($record->events)) {
|
||||||
|
$record->events = unserialize(gzuncompress(base64_decode($record->events)));
|
||||||
|
local_webhooks_update_record($record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$rs->close();
|
||||||
|
upgrade_plugin_savepoint(true, 2017112600, "local", "webhooks");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
# Getting Started
|
||||||
|
|
||||||
|
## Navigation
|
||||||
|
|
||||||
|
* [Installation](#installation)
|
||||||
|
* [Build](#build)
|
||||||
|
* [User guide](#user-guide)
|
||||||
|
* [Guide to the manager](#guide-to-the-manager)
|
||||||
|
* [Guide to the editor](#guide-to-the-editor)
|
||||||
|
* [Request format](#request-format)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Get the installation package in any of the available methods:
|
||||||
|
|
||||||
|
* [GitHub Releases](https://github.com/valentineus/moodle-webhooks/releases).
|
||||||
|
* [Compilation from the source code](#build).
|
||||||
|
|
||||||
|
### Build
|
||||||
|
|
||||||
|
Self-assembly package is as follows:
|
||||||
|
|
||||||
|
* Clone the repository:
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/valentineus/moodle-webhooks.git moodle-webhooks
|
||||||
|
```
|
||||||
|
|
||||||
|
* Run the build script:
|
||||||
|
```bash
|
||||||
|
cd ./moodle-webhooks
|
||||||
|
/bin/sh build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## User guide
|
||||||
|
|
||||||
|
After you install the plug-in, the Service Manager appears on the `Server` tab in the administration panel.
|
||||||
|
|
||||||
|
To open the page, go:
|
||||||
|
`Site administration` ->
|
||||||
|
`Server` ->
|
||||||
|
`WebHooks`.
|
||||||
|
|
||||||
|
### Guide to the manager
|
||||||
|
|
||||||
|
The main window looks like this:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
On the main page you can see the list of services and manage each service separately.
|
||||||
|
|
||||||
|
Column description
|
||||||
|
* "**Name**" shows the name of the service.
|
||||||
|
* "**URL**" indicates the address of the service to which notifications are received.
|
||||||
|
* "**Actions**" allows you to enable / disable the service, edit and delete.
|
||||||
|
|
||||||
|
Description of control buttons:
|
||||||
|
* "**Add service**" opens a page for creating a new service.
|
||||||
|
* "**Backup**" loads the backup file of the service list.
|
||||||
|
* "**Restore**" redirects the data recovery page from the backup.
|
||||||
|
|
||||||
|
### Guide to the editor
|
||||||
|
|
||||||
|
During the editing and creation of the service, this page opens:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Description of fields:
|
||||||
|
* "**Name**" stores an arbitrary name for the service.
|
||||||
|
* "**URL**" stores the address of the service to which notifications will be sent as a POST request.
|
||||||
|
* "**Token**" allows you to specify an individual key that will allow an external service to identify requests.
|
||||||
|
* "**Advanced**" stores a large string passed to the service.
|
||||||
|
This can be useful for some services or users.
|
||||||
|
* "**Content Type**" allows you to configure the type of outbound requests if there are compatibility issues.
|
||||||
|
|
||||||
|
The "**All events**" list contains a list of all events registered in the system.
|
||||||
|
The selected events will notify the service.
|
||||||
|
|
||||||
|
## Request format
|
||||||
|
|
||||||
|
Events come in
|
||||||
|
[JSON](https://en.wikipedia.org/wiki/JSON)
|
||||||
|
format.
|
||||||
|
|
||||||
|
An example of an observed course event:
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
"eventname": "\\core\\event\\course_viewed",
|
||||||
|
"component": "core",
|
||||||
|
"action": "viewed",
|
||||||
|
"target": "course",
|
||||||
|
"objecttable": null,
|
||||||
|
"objectid": null,
|
||||||
|
"crud": "r",
|
||||||
|
"edulevel": 2,
|
||||||
|
"contextid": 2,
|
||||||
|
"contextlevel": 50,
|
||||||
|
"contextinstanceid": "1",
|
||||||
|
"userid": "2",
|
||||||
|
"courseid": "1",
|
||||||
|
"relateduserid": null,
|
||||||
|
"anonymous": 0,
|
||||||
|
"other": null,
|
||||||
|
"timecreated": 1512961456,
|
||||||
|
"host": "localhost",
|
||||||
|
"token": "",
|
||||||
|
"extra": ""
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
[Detailed description of the fields](https://docs.moodle.org/dev/Event_2#Properties).
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 165 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
+17
-41
@@ -22,22 +22,22 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(__DIR__ . '/../../config.php');
|
require_once(__DIR__ . "/../../config.php");
|
||||||
require_once(__DIR__ . '/classes/service_form.php');
|
require_once(__DIR__ . "/classes/service_form.php");
|
||||||
require_once(__DIR__ . '/lib.php');
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
require_once($CFG->libdir . '/adminlib.php');
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
|
||||||
/* Optional parameters */
|
/* Optional parameters */
|
||||||
$serviceid = optional_param('serviceid', 0, PARAM_INT);
|
$serviceid = optional_param("serviceid", 0, PARAM_INT);
|
||||||
|
|
||||||
/* Link generation */
|
/* Link generation */
|
||||||
$urlparameters = array('serviceid' => $serviceid);
|
$urlparameters = array("serviceid" => $serviceid);
|
||||||
$baseurl = new moodle_url('/local/webhooks/editservice.php', $urlparameters);
|
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
|
||||||
$managerservice = new moodle_url('/local/webhooks/index.php');
|
$managerservice = new moodle_url("/local/webhooks/index.php");
|
||||||
|
|
||||||
/* Configure the context of the page */
|
/* Configure the context of the page */
|
||||||
admin_externalpage_setup('local_webhooks', '', null, $baseurl);
|
admin_externalpage_setup("local_webhooks", "", null, $baseurl, array());
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
|
||||||
/* Create an editing form */
|
/* Create an editing form */
|
||||||
@@ -50,50 +50,25 @@ if ($mform->is_cancelled()) {
|
|||||||
|
|
||||||
/* Getting the data */
|
/* Getting the data */
|
||||||
$servicerecord = new stdClass();
|
$servicerecord = new stdClass();
|
||||||
if (($editing = (bool) $serviceid) === true) {
|
if ($editing = boolval($serviceid)) {
|
||||||
$servicerecord = local_webhooks_get_record($serviceid);
|
$servicerecord = local_webhooks_get_record($serviceid);
|
||||||
|
|
||||||
if (is_array($servicerecord->events)) {
|
|
||||||
$events = array();
|
|
||||||
|
|
||||||
/* Escaping event names */
|
|
||||||
foreach ($servicerecord->events as $eventname => $eventstatus) {
|
|
||||||
$eventname = base64_encode($eventname);
|
|
||||||
$events[$eventname] = $eventstatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
$servicerecord->events = $events;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->set_data($servicerecord);
|
$mform->set_data($servicerecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Processing of received data */
|
/* Processing of received data */
|
||||||
if (!empty($data = $mform->get_data())) {
|
if ($data = $mform->get_data()) {
|
||||||
if (is_array($data->events)) {
|
|
||||||
$events = array();
|
|
||||||
|
|
||||||
/* Deciphering event names */
|
|
||||||
foreach ($data->events as $eventname => $eventstatus) {
|
|
||||||
$eventname = (string) base64_decode($eventname);
|
|
||||||
$events[$eventname] = $eventstatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data->events = $events;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($editing) {
|
if ($editing) {
|
||||||
$data->id = $serviceid;
|
$data->id = $serviceid;
|
||||||
local_webhooks_update_record($data, false);
|
|
||||||
redirect($managerservice, new lang_string('eventwebserviceserviceupdated', 'webservice'));
|
|
||||||
} else {
|
|
||||||
local_webhooks_update_record($data);
|
local_webhooks_update_record($data);
|
||||||
redirect($managerservice, new lang_string('eventwebserviceservicecreated', 'webservice'));
|
} else {
|
||||||
|
local_webhooks_create_record($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redirect($managerservice, new lang_string("changessaved", "moodle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$titlepage = new lang_string('externalservice', 'webservice');
|
$titlepage = new lang_string("externalservice", "webservice");
|
||||||
$PAGE->navbar->add($titlepage);
|
$PAGE->navbar->add($titlepage);
|
||||||
$PAGE->set_heading($titlepage);
|
$PAGE->set_heading($titlepage);
|
||||||
$PAGE->set_title($titlepage);
|
$PAGE->set_title($titlepage);
|
||||||
@@ -102,4 +77,5 @@ echo $OUTPUT->header();
|
|||||||
/* Displays the form */
|
/* Displays the form */
|
||||||
$mform->display();
|
$mform->display();
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
+589
@@ -0,0 +1,589 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file defines the plugin's external functions.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/externallib.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* External functions.
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class local_webhooks_external extends external_api {
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function change_status_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
"serviceid" => new external_value(PARAM_INT, "Service identifier.")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the status of the service.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
* @return boolean
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function change_status($serviceid = 0) {
|
||||||
|
$parameters = self::validate_parameters(self::change_status_parameters(), array("serviceid" => $serviceid));
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = local_webhooks_change_status($parameters["serviceid"]);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function change_status_returns() {
|
||||||
|
return new external_value(PARAM_BOOL, "The result of the operation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_record_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
"serviceid" => new external_value(PARAM_INT, "Service identifier.")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the record from the database.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
* @return array
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_record($serviceid = 0) {
|
||||||
|
$parameters = self::validate_parameters(self::get_record_parameters(), array("serviceid" => $serviceid));
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$service = array();
|
||||||
|
if ($record = local_webhooks_get_record($parameters["serviceid"])) {
|
||||||
|
$service["enable"] = $record->enable;
|
||||||
|
$service["id"] = $record->id;
|
||||||
|
$service["other"] = $record->other;
|
||||||
|
$service["title"] = $record->title;
|
||||||
|
$service["token"] = $record->token;
|
||||||
|
$service["type"] = $record->type;
|
||||||
|
$service["url"] = $record->url;
|
||||||
|
|
||||||
|
$service["events"] = array();
|
||||||
|
foreach ($record->events as $key => $value) {
|
||||||
|
$service["events"][] = array("name" => $key, "value" => $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_record_returns() {
|
||||||
|
return new external_single_structure(
|
||||||
|
array(
|
||||||
|
"id" => new external_value(PARAM_INT, "Service identifier."),
|
||||||
|
"enable" => new external_value(PARAM_INT, "Service status."),
|
||||||
|
"title" => new external_value(PARAM_TEXT, "Name of the service."),
|
||||||
|
"url" => new external_value(PARAM_URL, "URL address."),
|
||||||
|
"type" => new external_value(PARAM_TEXT, "Header type."),
|
||||||
|
"token" => new external_value(PARAM_TEXT, "Authorization key.", VALUE_OPTIONAL),
|
||||||
|
"other" => new external_value(PARAM_TEXT, "Additional field.", VALUE_OPTIONAL),
|
||||||
|
"events" => new external_multiple_structure(
|
||||||
|
new external_single_structure(
|
||||||
|
array(
|
||||||
|
"name" => new external_value(PARAM_TEXT, "Event name."),
|
||||||
|
"value" => new external_value(PARAM_INT, "Observation status.")
|
||||||
|
)
|
||||||
|
), "Observed events.", VALUE_OPTIONAL
|
||||||
|
)
|
||||||
|
), "Record about the service."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_list_records_parameters() {
|
||||||
|
return new external_function_parameters(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all records from the database.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_list_records() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
if ($listrecords = local_webhooks_get_list_records()) {
|
||||||
|
foreach ($listrecords as $index => $record) {
|
||||||
|
$result[$index]["enable"] = $record->enable;
|
||||||
|
$result[$index]["id"] = $record->id;
|
||||||
|
$result[$index]["other"] = $record->other;
|
||||||
|
$result[$index]["title"] = $record->title;
|
||||||
|
$result[$index]["token"] = $record->token;
|
||||||
|
$result[$index]["type"] = $record->type;
|
||||||
|
$result[$index]["url"] = $record->url;
|
||||||
|
|
||||||
|
$result[$index]["events"] = array();
|
||||||
|
foreach ($record->events as $key => $value) {
|
||||||
|
$result[$index]["events"][] = array("name" => $key, "value" => $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_list_records_returns() {
|
||||||
|
return new external_multiple_structure(
|
||||||
|
new external_single_structure(
|
||||||
|
array(
|
||||||
|
"id" => new external_value(PARAM_INT, "Service identifier."),
|
||||||
|
"enable" => new external_value(PARAM_INT, "Service status."),
|
||||||
|
"title" => new external_value(PARAM_TEXT, "Name of the service."),
|
||||||
|
"url" => new external_value(PARAM_URL, "URL address."),
|
||||||
|
"type" => new external_value(PARAM_TEXT, "Header type."),
|
||||||
|
"token" => new external_value(PARAM_TEXT, "Authorization key.", VALUE_OPTIONAL),
|
||||||
|
"other" => new external_value(PARAM_TEXT, "Additional field.", VALUE_OPTIONAL),
|
||||||
|
"events" => new external_multiple_structure(
|
||||||
|
new external_single_structure(
|
||||||
|
array(
|
||||||
|
"name" => new external_value(PARAM_TEXT, "Event name."),
|
||||||
|
"value" => new external_value(PARAM_INT, "Observation status.")
|
||||||
|
)
|
||||||
|
), "Observed events.", VALUE_OPTIONAL
|
||||||
|
)
|
||||||
|
), "Record about the service."
|
||||||
|
), "List of services."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_list_events_parameters() {
|
||||||
|
return new external_function_parameters(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all system events.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_list_events() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
if ($eventlist = local_webhooks_get_list_events()) {
|
||||||
|
foreach ($eventlist as $item) {
|
||||||
|
$result[] = $item["eventname"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function get_list_events_returns() {
|
||||||
|
return new external_multiple_structure(
|
||||||
|
new external_value(PARAM_TEXT, "Event name.")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function create_record_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
"service" => new external_single_structure(
|
||||||
|
array(
|
||||||
|
"enable" => new external_value(PARAM_BOOL, "Service status.", VALUE_OPTIONAL),
|
||||||
|
"title" => new external_value(PARAM_TEXT, "Name of the service."),
|
||||||
|
"url" => new external_value(PARAM_URL, "URL address."),
|
||||||
|
"type" => new external_value(PARAM_TEXT, "Header type.", VALUE_OPTIONAL),
|
||||||
|
"token" => new external_value(PARAM_TEXT, "Authorization key.", VALUE_OPTIONAL),
|
||||||
|
"other" => new external_value(PARAM_TEXT, "Additional field.", VALUE_OPTIONAL),
|
||||||
|
"events" => new external_multiple_structure(
|
||||||
|
new external_single_structure(
|
||||||
|
array(
|
||||||
|
"name" => new external_value(PARAM_TEXT, "Event name."),
|
||||||
|
"value" => new external_value(PARAM_INT, "Observation status.")
|
||||||
|
)
|
||||||
|
), "Observed events.", VALUE_OPTIONAL
|
||||||
|
)
|
||||||
|
), "Record about the service."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an entry in the database.
|
||||||
|
*
|
||||||
|
* @param array $service
|
||||||
|
* @return number
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function create_record($service = array()) {
|
||||||
|
$parameters = self::validate_parameters(self::create_record_parameters(), array("service" => $service));
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$record = new stdClass();
|
||||||
|
$record->other = $parameters["service"]["other"];
|
||||||
|
$record->title = $parameters["service"]["title"];
|
||||||
|
$record->token = $parameters["service"]["token"];
|
||||||
|
$record->url = $parameters["service"]["url"];
|
||||||
|
|
||||||
|
$record->enable = !empty($parameters["service"]["enable"]) ? $parameters["service"]["enable"] : false;
|
||||||
|
$record->type = !empty($parameters["service"]["type"]) ? $parameters["service"]["type"] : "json";
|
||||||
|
|
||||||
|
$record->events = array();
|
||||||
|
foreach ($parameters["service"]["events"] as $value) {
|
||||||
|
$record->events[$value["name"]] = $value["value"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = local_webhooks_create_record($record);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function create_record_returns() {
|
||||||
|
return new external_value(PARAM_INT, "Service identifier.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function update_record_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
"id" => new external_value(PARAM_INT, "Service identifier."),
|
||||||
|
"service" => new external_single_structure(
|
||||||
|
array(
|
||||||
|
"enable" => new external_value(PARAM_BOOL, "Service status.", VALUE_OPTIONAL),
|
||||||
|
"title" => new external_value(PARAM_TEXT, "Name of the service.", VALUE_OPTIONAL),
|
||||||
|
"url" => new external_value(PARAM_URL, "URL address.", VALUE_OPTIONAL),
|
||||||
|
"type" => new external_value(PARAM_TEXT, "Header type.", VALUE_OPTIONAL),
|
||||||
|
"token" => new external_value(PARAM_TEXT, "Authorization key.", VALUE_OPTIONAL),
|
||||||
|
"other" => new external_value(PARAM_TEXT, "Additional field.", VALUE_OPTIONAL),
|
||||||
|
"events" => new external_multiple_structure(
|
||||||
|
new external_single_structure(
|
||||||
|
array(
|
||||||
|
"name" => new external_value(PARAM_TEXT, "Event name."),
|
||||||
|
"value" => new external_value(PARAM_INT, "Observation status.")
|
||||||
|
)
|
||||||
|
), "Observed events.", VALUE_OPTIONAL
|
||||||
|
)
|
||||||
|
), "Record about the service."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the record in the database.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
* @param array $service
|
||||||
|
* @return boolean
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function update_record($serviceid = 0, $service = array()) {
|
||||||
|
$parameters = self::validate_parameters(self::update_record_parameters(), array("id" => $serviceid, "service" => $service));
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
if ($record = local_webhooks_get_record($parameters["id"])) {
|
||||||
|
$record->enable = !empty($parameters["service"]["enable"]) ? $parameters["service"]["enable"] : $record->enable;
|
||||||
|
$record->other = !empty($parameters["service"]["other"]) ? $parameters["service"]["other"] : $record->other;
|
||||||
|
$record->title = !empty($parameters["service"]["title"]) ? $parameters["service"]["title"] : $record->title;
|
||||||
|
$record->token = !empty($parameters["service"]["token"]) ? $parameters["service"]["token"] : $record->token;
|
||||||
|
$record->type = !empty($parameters["service"]["type"]) ? $parameters["service"]["type"] : $record->type;
|
||||||
|
$record->url = !empty($parameters["service"]["url"]) ? $parameters["service"]["url"] : $record->url;
|
||||||
|
|
||||||
|
if (!empty($parameters["service"]["events"])) {
|
||||||
|
$record->events = array();
|
||||||
|
foreach ($parameters["service"]["events"] as $value) {
|
||||||
|
$record->events[$value["name"]] = $value["value"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = local_webhooks_update_record($record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function update_record_returns() {
|
||||||
|
return new external_value(PARAM_BOOL, "The result of the operation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function delete_record_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
"serviceid" => new external_value(PARAM_INT, "Service identifier.")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the record from the database.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
* @return boolean
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function delete_record($serviceid = 0) {
|
||||||
|
$parameters = self::validate_parameters(self::delete_record_parameters(), array("serviceid" => $serviceid));
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = local_webhooks_delete_record($parameters["serviceid"]);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function delete_record_returns() {
|
||||||
|
return new external_value(PARAM_BOOL, "The result of the operation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function delete_all_records_parameters() {
|
||||||
|
return new external_function_parameters(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all records from the database.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function delete_all_records() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = local_webhooks_delete_all_records();
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function delete_all_records_returns() {
|
||||||
|
return new external_value(PARAM_BOOL, "The result of the operation.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function create_backup_parameters() {
|
||||||
|
return new external_function_parameters(array());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a backup.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function create_backup() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$result = local_webhooks_create_backup();
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function create_backup_returns() {
|
||||||
|
return new external_value(PARAM_TEXT, "Backup copy.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method parameters.
|
||||||
|
*
|
||||||
|
* @return external_function_parameters
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function restore_backup_parameters() {
|
||||||
|
return new external_function_parameters(
|
||||||
|
array(
|
||||||
|
"options" => new external_single_structure(
|
||||||
|
array(
|
||||||
|
"backup" => new external_value(PARAM_TEXT, "Backup copy."),
|
||||||
|
"deleterecords" => new external_value(PARAM_BOOL, "Delete existing records.", VALUE_OPTIONAL)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore from a backup.
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
* @since Moodle 2.9 Options available
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function restore_backup($options = array()) {
|
||||||
|
$parameters = self::validate_parameters(self::restore_backup_parameters(), array("options" => $options));
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
self::validate_context($context);
|
||||||
|
|
||||||
|
$deleterecords = !empty($parameters["options"]["deleterecords"]) ? boolval($parameters["options"]["deleterecords"]) : false;
|
||||||
|
local_webhooks_restore_backup($parameters["options"]["backup"], $deleterecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of method result value.
|
||||||
|
*
|
||||||
|
* @return external_description
|
||||||
|
* @since Moodle 2.2
|
||||||
|
*/
|
||||||
|
public static function restore_backup_returns() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,125 +22,79 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(__DIR__ . '/../../config.php');
|
require_once(__DIR__ . "/../../config.php");
|
||||||
require_once(__DIR__ . '/lib.php');
|
require_once(__DIR__ . "/classes/webhooks_table.php");
|
||||||
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
require_once($CFG->libdir . '/adminlib.php');
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
require_once($CFG->libdir . '/tablelib.php');
|
|
||||||
|
|
||||||
/* Optional parameters */
|
/* Optional parameters */
|
||||||
$backupservices = optional_param('getbackup', 0, PARAM_BOOL);
|
$backupservices = optional_param("getbackup", 0, PARAM_BOOL);
|
||||||
$deleteid = optional_param('deleteid', 0, PARAM_INT);
|
$deleteall = optional_param("deleteall", 0, PARAM_INT);
|
||||||
$hideshowid = optional_param('hideshowid', 0, PARAM_INT);
|
$deleteid = optional_param("deleteid", 0, PARAM_INT);
|
||||||
|
$hideshowid = optional_param("hideshowid", 0, PARAM_INT);
|
||||||
|
|
||||||
/* Link generation */
|
/* Link generation */
|
||||||
$editservice = '/local/webhooks/editservice.php';
|
$editservice = "/local/webhooks/editservice.php";
|
||||||
$managerservice = '/local/webhooks/index.php';
|
$managerservice = "/local/webhooks/index.php";
|
||||||
$restorebackup = '/local/webhooks/restorebackup.php';
|
$restorebackup = "/local/webhooks/restorebackup.php";
|
||||||
$baseurl = new moodle_url($managerservice);
|
$baseurl = new moodle_url($managerservice);
|
||||||
|
|
||||||
/* Configure the context of the page */
|
/* Configure the context of the page */
|
||||||
admin_externalpage_setup('local_webhooks', '', null, $baseurl);
|
admin_externalpage_setup("local_webhooks", "", null, $baseurl, array());
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
|
||||||
/* Delete the service */
|
/* Delete the service */
|
||||||
if ((bool) $deleteid) {
|
if (!empty($deleteid) && confirm_sesskey()) {
|
||||||
local_webhooks_remove_record($deleteid);
|
local_webhooks_delete_record($deleteid);
|
||||||
redirect($PAGE->url, new lang_string('eventwebserviceservicedeleted', 'webservice'));
|
redirect($PAGE->url, new lang_string("deleted", "moodle"));
|
||||||
}
|
|
||||||
|
|
||||||
/* Retrieving a list of services */
|
|
||||||
$callbacks = local_webhooks_get_list_records();
|
|
||||||
|
|
||||||
/* Upload settings as a file */
|
|
||||||
if ((bool) $backupservices) {
|
|
||||||
$filecontent = local_webhooks_create_backup();
|
|
||||||
$filename = 'webhooks_' . date('U') . '.backup';
|
|
||||||
send_file($filecontent, $filename, 0, 0, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switching the status of the service */
|
/* Switching the status of the service */
|
||||||
if ((bool) $hideshowid) {
|
if (!empty($hideshowid) && confirm_sesskey()) {
|
||||||
$callback = $callbacks[$hideshowid];
|
local_webhooks_change_status($hideshowid);
|
||||||
|
redirect($PAGE->url, new lang_string("changessaved", "moodle"));
|
||||||
if (!empty($callback)) {
|
|
||||||
$callback->enable = !(bool) $callback->enable;
|
|
||||||
local_webhooks_update_record($callback, false);
|
|
||||||
redirect($PAGE->url, new lang_string('eventwebserviceserviceupdated', 'webservice'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Deletes all data */
|
||||||
|
if (boolval($deleteall) && confirm_sesskey()) {
|
||||||
|
local_webhooks_delete_all_records();
|
||||||
|
redirect($PAGE->url, new lang_string("deleted", "moodle"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Upload settings as a file */
|
||||||
|
if (boolval($backupservices)) {
|
||||||
|
$filecontent = local_webhooks_create_backup();
|
||||||
|
$filename = "webhooks_" . date("U") . ".backup";
|
||||||
|
send_file($filecontent, $filename, 0, 0, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$titlepage = new lang_string('pluginname', 'local_webhooks');
|
$titlepage = new lang_string("pluginname", "local_webhooks");
|
||||||
$PAGE->set_heading($titlepage);
|
$PAGE->set_heading($titlepage);
|
||||||
$PAGE->set_title($titlepage);
|
$PAGE->set_title($titlepage);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
/* Table declaration */
|
/* Adds the add button */
|
||||||
$table = new flexible_table('webhooks-service-table');
|
|
||||||
|
|
||||||
/* Customize the table */
|
|
||||||
$table->define_columns(
|
|
||||||
array(
|
|
||||||
'title',
|
|
||||||
'url',
|
|
||||||
'actions',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$table->define_headers(
|
|
||||||
array(
|
|
||||||
new lang_string('name', 'moodle'),
|
|
||||||
new lang_string('url', 'moodle'),
|
|
||||||
new lang_string('actions', 'moodle'),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$table->define_baseurl($baseurl);
|
|
||||||
$table->setup();
|
|
||||||
|
|
||||||
foreach ($callbacks as $callback) {
|
|
||||||
/* Filling of information columns */
|
|
||||||
$titlecallback = html_writer::div($callback->title, 'title');
|
|
||||||
$urlcallback = html_writer::div($callback->url, 'url');
|
|
||||||
|
|
||||||
/* Defining service status */
|
|
||||||
$hideshowicon = 't/show';
|
|
||||||
$hideshowstring = new lang_string('enable', 'moodle');
|
|
||||||
if ((bool) $callback->enable) {
|
|
||||||
$hideshowicon = 't/hide';
|
|
||||||
$hideshowstring = new lang_string('disable', 'moodle');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Link to enable / disable the service */
|
|
||||||
$hideshowlink = new moodle_url($managerservice, array('hideshowid' => $callback->id));
|
|
||||||
$hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($hideshowicon, $hideshowstring));
|
|
||||||
|
|
||||||
/* Link for editing */
|
|
||||||
$editlink = new moodle_url($editservice, array('serviceid' => $callback->id));
|
|
||||||
$edititem = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', new lang_string('edit', 'moodle')));
|
|
||||||
|
|
||||||
/* Link to remove */
|
|
||||||
$deletelink = new moodle_url($managerservice, array('deleteid' => $callback->id));
|
|
||||||
$deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', new lang_string('delete', 'moodle')));
|
|
||||||
|
|
||||||
/* Adding data to the table */
|
|
||||||
$table->add_data(array($titlecallback, $urlcallback, $hideshowitem . $edititem . $deleteitem));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display the table */
|
|
||||||
$table->print_html();
|
|
||||||
|
|
||||||
/* Add service button */
|
|
||||||
$addserviceurl = new moodle_url($editservice);
|
$addserviceurl = new moodle_url($editservice);
|
||||||
echo $OUTPUT->single_button($addserviceurl, new lang_string('addaservice', 'webservice'), 'get');
|
echo $OUTPUT->single_button($addserviceurl, new lang_string("add", "moodle"));
|
||||||
|
|
||||||
/* Button to get a backup */
|
/* Adds a delete button */
|
||||||
$backupurl = new moodle_url($managerservice, array('getbackup' => true));
|
$deleteallurl = new moodle_url($managerservice, array("deleteall" => true, "sesskey" => sesskey()));
|
||||||
echo $OUTPUT->single_button($backupurl, new lang_string('backup', 'moodle'), 'get');
|
echo $OUTPUT->single_button($deleteallurl, new lang_string("deleteall", "moodle"), "get");
|
||||||
|
|
||||||
/* Button for restoring settings */
|
/* Adds a backup button */
|
||||||
|
$backupurl = new moodle_url($managerservice, array("getbackup" => true));
|
||||||
|
echo $OUTPUT->single_button($backupurl, new lang_string("backup", "moodle"), "get");
|
||||||
|
|
||||||
|
/* Adds a restore button */
|
||||||
$restorebackupurl = new moodle_url($restorebackup);
|
$restorebackupurl = new moodle_url($restorebackup);
|
||||||
echo $OUTPUT->single_button($restorebackupurl, new lang_string('restore', 'moodle'), 'get');
|
echo $OUTPUT->single_button($restorebackupurl, new lang_string("restore", "moodle"));
|
||||||
|
|
||||||
|
/* Displays the table */
|
||||||
|
$table = new local_webhooks_table("local-webhooks-table");
|
||||||
|
$table->define_baseurl($baseurl);
|
||||||
|
$table->out(25, true);
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
@@ -22,5 +22,4 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['pluginname'] = 'WebHooks';
|
$string["pluginname"] = "WebHooks";
|
||||||
$string['privacy:metadata'] = 'WebHooks does not store any personal data.';
|
|
||||||
@@ -15,169 +15,218 @@
|
|||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Library code used by the service control interfaces.
|
* This file contains the functions used by the plugin.
|
||||||
*
|
*
|
||||||
* @package local_webhooks
|
* @package local_webhooks
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
require_once(__DIR__ . '/locallib.php');
|
require_once(__DIR__ . "/locallib.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getting a list of all services.
|
* Change the status of the service.
|
||||||
*
|
*
|
||||||
* @param int $limitfrom
|
* @param number $serviceid
|
||||||
* @param int $limitnum
|
* @return boolean
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_get_list_records($limitfrom = 0, $limitnum = 0) {
|
function local_webhooks_change_status($serviceid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$listservices = $DB->get_records('local_webhooks_service', null, 'id', '*', $limitfrom, $limitnum);
|
$result = false;
|
||||||
|
if ($record = local_webhooks_get_record($serviceid)) {
|
||||||
foreach ($listservices as $servicerecord) {
|
$record->enable = !boolval($record->enable);
|
||||||
if (!empty($servicerecord->events)) {
|
$result = local_webhooks_update_record($record);
|
||||||
$servicerecord->events = local_webhooks_unarchive_data($servicerecord->events);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $listservices;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getting information about the service.
|
* Get the record from the database.
|
||||||
*
|
|
||||||
* @param int $serviceid
|
|
||||||
*
|
*
|
||||||
|
* @param number $serviceid
|
||||||
* @return object
|
* @return object
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_get_record($serviceid = 0) {
|
function local_webhooks_get_record($serviceid) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$servicerecord = $DB->get_record('local_webhooks_service', array('id' => $serviceid), '*', MUST_EXIST);
|
$servicerecord = $DB->get_record("local_webhooks_service", array("id" => $serviceid), "*", MUST_EXIST);
|
||||||
|
|
||||||
if (!empty($servicerecord->events)) {
|
if (!empty($servicerecord->events)) {
|
||||||
$servicerecord->events = local_webhooks_unarchive_data($servicerecord->events);
|
$servicerecord->events = local_webhooks_deserialization_data($servicerecord->events);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $servicerecord;
|
return $servicerecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the database table.
|
* Get all records from the database.
|
||||||
*
|
*
|
||||||
* @throws \dml_exception
|
* @param number $limitfrom
|
||||||
|
* @param number $limitnum
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
function local_webhooks_remove_list_records() {
|
function local_webhooks_get_list_records($limitfrom = 0, $limitnum = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$DB->delete_records('local_webhooks_service');
|
$listrecords = $DB->get_records("local_webhooks_service", null, "id", "*", $limitfrom, $limitnum);
|
||||||
|
|
||||||
|
foreach ($listrecords as $servicerecord) {
|
||||||
|
if (!empty($servicerecord->events)) {
|
||||||
|
$servicerecord->events = local_webhooks_deserialization_data($servicerecord->events);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $listrecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the record.
|
* Get a list of all system events.
|
||||||
*
|
*
|
||||||
* @param int $serviceid
|
* @return array
|
||||||
*
|
|
||||||
* @throws \dml_exception
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_remove_record($serviceid = 0) {
|
function local_webhooks_get_list_events() {
|
||||||
|
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
||||||
|
return $eventlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an entry in the database.
|
||||||
|
*
|
||||||
|
* @param object $record
|
||||||
|
* @return number
|
||||||
|
*/
|
||||||
|
function local_webhooks_create_record($record) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$DB->delete_records('local_webhooks_service', array('id' => $serviceid));
|
if (!empty($record->events)) {
|
||||||
local_webhooks_events::service_deleted($serviceid);
|
$record->events = local_webhooks_serialization_data($record->events);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $DB->insert_record("local_webhooks_service", $record, true, false);
|
||||||
|
local_webhooks_events::service_added($result);
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the record in the database.
|
* Update the record in the database.
|
||||||
*
|
*
|
||||||
* @param object $data
|
* @param object $data
|
||||||
* @param boolean $insert
|
|
||||||
*
|
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws \dml_exception
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_update_record($data, $insert = true) {
|
function local_webhooks_update_record($record) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
if (empty($data->events)) {
|
if (empty($record->id)) {
|
||||||
$data->events = array();
|
print_error("missingparam", "error", null, "id");
|
||||||
}
|
}
|
||||||
|
|
||||||
$data->events = local_webhooks_archiving_data($data->events);
|
$record->events = !empty($record->events) ? local_webhooks_serialization_data($record->events) : null;
|
||||||
|
$result = $DB->update_record("local_webhooks_service", $record, false);
|
||||||
if ((bool) $insert) {
|
local_webhooks_events::service_updated($record->id);
|
||||||
$result = $DB->insert_record('local_webhooks_service', $data);
|
return boolval($result);
|
||||||
local_webhooks_events::service_added($result);
|
|
||||||
} else {
|
|
||||||
$result = $DB->update_record('local_webhooks_service', $data);
|
|
||||||
local_webhooks_events::service_updated($data->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (bool) $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a backup copy of all the services.
|
* Delete the record from the database.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function local_webhooks_delete_record($serviceid) {
|
||||||
|
global $DB;
|
||||||
|
$result = $DB->delete_records("local_webhooks_service", array("id" => $serviceid));
|
||||||
|
local_webhooks_events::service_deleted($serviceid);
|
||||||
|
return boolval($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all records from the database.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function local_webhooks_delete_all_records() {
|
||||||
|
global $DB;
|
||||||
|
$result = $DB->delete_records("local_webhooks_service", null);
|
||||||
|
local_webhooks_events::service_deletedall();
|
||||||
|
return boolval($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a backup.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \dml_exception
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_create_backup() {
|
function local_webhooks_create_backup() {
|
||||||
$listservices = local_webhooks_get_list_records();
|
$listrecords = local_webhooks_get_list_records();
|
||||||
$listservices = local_webhooks_archiving_data($listservices);
|
$result = local_webhooks_serialization_data($listrecords);
|
||||||
local_webhooks_events::backup_performed();
|
local_webhooks_events::backup_performed();
|
||||||
|
return $result;
|
||||||
return $listservices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore the data from the backup.
|
* Restore from a backup.
|
||||||
*
|
*
|
||||||
* @param string $listservices
|
* @param string $data
|
||||||
*
|
|
||||||
* @throws \dml_exception
|
|
||||||
* @throws \coding_exception
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_restore_backup($listservices = '') {
|
function local_webhooks_restore_backup($data, $deleterecords = false) {
|
||||||
$listservices = local_webhooks_unarchive_data($listservices);
|
$listrecords = local_webhooks_deserialization_data($data);
|
||||||
|
|
||||||
local_webhooks_remove_list_records();
|
if (boolval($deleterecords)) {
|
||||||
|
local_webhooks_delete_all_records();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($listservices as $servicerecord) {
|
foreach ($listrecords as $servicerecord) {
|
||||||
local_webhooks_update_record($servicerecord);
|
local_webhooks_create_record($servicerecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
local_webhooks_events::backup_restored();
|
local_webhooks_events::backup_restored();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compress an array into a string.
|
* Send the event remotely to the service.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $event
|
||||||
*
|
* @param object $callback
|
||||||
* @return string
|
* @return array
|
||||||
*/
|
*/
|
||||||
function local_webhooks_archiving_data(array $data = array()) {
|
function local_webhooks_send_request($event, $callback) {
|
||||||
return base64_encode(gzcompress(serialize($data), 3));
|
global $CFG;
|
||||||
|
|
||||||
|
$event["host"] = parse_url($CFG->wwwroot)["host"];
|
||||||
|
$event["token"] = $callback->token;
|
||||||
|
$event["extra"] = $callback->other;
|
||||||
|
|
||||||
|
$curl = new curl();
|
||||||
|
$curl->setHeader(array("Content-Type: application/" . $callback->type));
|
||||||
|
$curl->post($callback->url, json_encode($event));
|
||||||
|
|
||||||
|
$response = $curl->getResponse();
|
||||||
|
local_webhooks_events::response_answer($callback->id, $response);
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an array from a compressed string.
|
* Data serialization.
|
||||||
|
*
|
||||||
|
* @param array|object $data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function local_webhooks_serialization_data($data) {
|
||||||
|
$result = serialize($data);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data deserialization.
|
||||||
*
|
*
|
||||||
* @param string $data
|
* @param string $data
|
||||||
*
|
* @return array|object
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
function local_webhooks_unarchive_data($data = '') {
|
function local_webhooks_deserialization_data($data) {
|
||||||
return unserialize(gzuncompress(base64_decode($data)));
|
$result = unserialize($data);
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
+23
-66
@@ -22,7 +22,7 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of functions of the call of events
|
* Description of functions of the call of events
|
||||||
@@ -33,121 +33,78 @@ defined('MOODLE_INTERNAL') || die();
|
|||||||
class local_webhooks_events {
|
class local_webhooks_events {
|
||||||
/**
|
/**
|
||||||
* Call the event when creating a backup.
|
* Call the event when creating a backup.
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
public static function backup_performed() {
|
public static function backup_performed() {
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
$event = local_webhooks\event\backup_performed::create(array("context" => $context, "objectid" => 0));
|
||||||
$event = local_webhooks\event\backup_performed::create(
|
|
||||||
array(
|
|
||||||
'context' => $context,
|
|
||||||
'objectid' => 0,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the event when restoring from a backup.
|
* Call the event when restoring from a backup.
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
public static function backup_restored() {
|
public static function backup_restored() {
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
$event = local_webhooks\event\backup_restored::create(array("context" => $context, "objectid" => 0));
|
||||||
$event = local_webhooks\event\backup_restored::create(
|
|
||||||
array(
|
|
||||||
'context' => $context,
|
|
||||||
'objectid' => 0,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call event when the response is received from the service
|
* Call event when the response is received from the service
|
||||||
*
|
*
|
||||||
* @param int $objectid Service ID
|
* @param number $objectid Service ID
|
||||||
* @param array $response Server response
|
* @param array $response Server response
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
public static function response_answer($objectid = 0, array $response = array()) {
|
public static function response_answer($objectid = 0, $response = array()) {
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
$status = "Error sending request";
|
||||||
$status = 'Error sending request';
|
if (!empty($response["HTTP/1.1"])) {
|
||||||
if (!empty($response['HTTP/1.1'])) {
|
$status = $response["HTTP/1.1"];
|
||||||
$status = $response['HTTP/1.1'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = local_webhooks\event\response_answer::create(
|
$event = local_webhooks\event\response_answer::create(array("context" => $context, "objectid" => $objectid, "other" => array("status" => $status)));
|
||||||
array(
|
|
||||||
'context' => $context,
|
|
||||||
'objectid' => $objectid,
|
|
||||||
'other' => array('status' => $status),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the event when the service is added.
|
* Call the event when the service is added.
|
||||||
*
|
*
|
||||||
* @param int $objectid Service ID
|
* @param number $objectid Service ID
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
public static function service_added($objectid = 0) {
|
public static function service_added($objectid = 0) {
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
$event = local_webhooks\event\service_added::create(array("context" => $context, "objectid" => $objectid));
|
||||||
$event = local_webhooks\event\service_added::create(
|
|
||||||
compact('context', 'objectid')
|
|
||||||
);
|
|
||||||
|
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the event when the service is deleted.
|
* Call the event when the service is deleted.
|
||||||
*
|
*
|
||||||
* @param int $objectid Service ID
|
* @param number $objectid Service ID
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
public static function service_deleted($objectid = 0) {
|
public static function service_deleted($objectid = 0) {
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
$event = local_webhooks\event\service_deleted::create(array("context" => $context, "objectid" => $objectid));
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
$event = local_webhooks\event\service_deleted::create(
|
/**
|
||||||
compact('context', 'objectid')
|
* Call the event when all services are deleted.
|
||||||
);
|
*/
|
||||||
|
public static function service_deletedall() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
$event = local_webhooks\event\service_deletedall::create(array("context" => $context, "objectid" => 0));
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call event when the service is updated.
|
* Call event when the service is updated.
|
||||||
*
|
*
|
||||||
* @param int $objectid Service ID
|
* @param number $objectid Service ID
|
||||||
*
|
|
||||||
* @throws \coding_exception
|
|
||||||
* @throws \dml_exception
|
|
||||||
*/
|
*/
|
||||||
public static function service_updated($objectid = 0) {
|
public static function service_updated($objectid = 0) {
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
$event = local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $objectid));
|
||||||
$event = local_webhooks\event\service_updated::create(
|
|
||||||
compact('context', 'objectid')
|
|
||||||
);
|
|
||||||
|
|
||||||
$event->trigger();
|
$event->trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-12
@@ -22,18 +22,18 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(__DIR__ . '/../../config.php');
|
require_once(__DIR__ . "/../../config.php");
|
||||||
require_once(__DIR__ . '/classes/service_form.php');
|
require_once(__DIR__ . "/classes/service_form.php");
|
||||||
require_once(__DIR__ . '/lib.php');
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
require_once($CFG->libdir . '/adminlib.php');
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
|
||||||
/* Link generation */
|
/* Link generation */
|
||||||
$baseurl = new moodle_url('/local/webhooks/restorebackup.php');
|
$baseurl = new moodle_url("/local/webhooks/restorebackup.php");
|
||||||
$managerservice = new moodle_url('/local/webhooks/index.php');
|
$managerservice = new moodle_url("/local/webhooks/index.php");
|
||||||
|
|
||||||
/* Configure the context of the page */
|
/* Configure the context of the page */
|
||||||
admin_externalpage_setup('local_webhooks', '', null, $baseurl);
|
admin_externalpage_setup("local_webhooks", "", null, $baseurl, array());
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
|
|
||||||
/* Create an editing form */
|
/* Create an editing form */
|
||||||
@@ -45,14 +45,14 @@ if ($mform->is_cancelled()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Processing the received file */
|
/* Processing the received file */
|
||||||
if (!empty($data = $mform->get_data())) {
|
if ($data = $mform->get_data()) {
|
||||||
$content = $mform->get_file_content('backupfile');
|
$content = $mform->get_file_content("backupfile");
|
||||||
local_webhooks_restore_backup($content);
|
local_webhooks_restore_backup($content, $data->deleterecords);
|
||||||
redirect($managerservice, new lang_string('restorefinished', 'moodle'));
|
redirect($managerservice, new lang_string("restorefinished", "moodle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$titlepage = new lang_string('backup', 'moodle');
|
$titlepage = new lang_string("backup", "moodle");
|
||||||
$PAGE->navbar->add($titlepage);
|
$PAGE->navbar->add($titlepage);
|
||||||
$PAGE->set_heading($titlepage);
|
$PAGE->set_heading($titlepage);
|
||||||
$PAGE->set_title($titlepage);
|
$PAGE->set_title($titlepage);
|
||||||
@@ -61,4 +61,5 @@ echo $OUTPUT->header();
|
|||||||
/* Displays the form */
|
/* Displays the form */
|
||||||
$mform->display();
|
$mform->display();
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
echo $OUTPUT->footer();
|
echo $OUTPUT->footer();
|
||||||
+5
-10
@@ -22,16 +22,11 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
/* @var \admin_root $ADMIN */
|
|
||||||
|
|
||||||
if ($hassiteconfig) {
|
if ($hassiteconfig) {
|
||||||
$ADMIN->add(
|
$ADMIN->add("server", new admin_externalpage("local_webhooks",
|
||||||
'server', new admin_externalpage(
|
new lang_string("pluginname", "local_webhooks"),
|
||||||
'local_webhooks',
|
new moodle_url("/local/webhooks/index.php")
|
||||||
new lang_string('pluginname', 'local_webhooks'),
|
));
|
||||||
new moodle_url('/local/webhooks/index.php')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
+7
-6
@@ -22,10 +22,11 @@
|
|||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
|
|
||||||
$plugin->component = 'local_webhooks';
|
$plugin->release = "4.0.0-rc.1 (Build: 2017122900)";
|
||||||
$plugin->maturity = MATURITY_STABLE;
|
$plugin->version = 2017122900;
|
||||||
$plugin->release = '3.0.5 (Build: 2020051600)';
|
$plugin->requires = 2016112900;
|
||||||
$plugin->requires = 2019052000;
|
$plugin->component = "local_webhooks";
|
||||||
$plugin->version = 2020051600;
|
$plugin->maturity = MATURITY_RC;
|
||||||
|
$plugin->dependencies = array("report_eventlist" => 2016120500);
|
||||||
Reference in New Issue
Block a user