Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9772b1fb9 | ||
|
|
3fa97bad31 | ||
|
|
bdaf1d35b2 | ||
|
|
7cfdf29600 | ||
|
|
bec8dcdc08 | ||
|
|
2ae949bbc3 | ||
|
|
de3c3a6553 | ||
|
|
05512c5440 | ||
|
|
91754489b0 | ||
|
|
f8b85a270c | ||
|
|
4bf6f61131 | ||
|
|
3da34ec7f1 | ||
|
|
4f342659d4 | ||
|
|
0bc809ba07 | ||
|
|
03d22ef096 | ||
|
|
1c87dae035 | ||
|
|
5639dc7b0f | ||
|
|
1ad4527c1d | ||
|
|
57cac60ab3 | ||
|
|
d4d105c018 | ||
|
|
3ea8f29329 | ||
|
|
c1077bc9c1 | ||
|
|
bc02d0dce2 | ||
|
|
93d788f046 | ||
|
|
29c12fa971 | ||
|
|
1e8cbe7f09 | ||
|
|
ad07800be9 | ||
|
|
f28b408b1e | ||
|
|
91fd140bd4 | ||
|
|
463aeaf043 | ||
|
|
97140dccf7 | ||
|
|
bf2cef3ea0 | ||
|
|
7b56375c05 | ||
|
|
b61e5a08be | ||
|
|
4a470056a7 | ||
|
|
688448b350 | ||
|
|
35358ea7cc | ||
|
|
97296b795a | ||
|
|
0fcec2738d | ||
|
|
e1372c6d34 | ||
|
|
098514660f | ||
|
|
07970f36e3 | ||
|
|
1e81988bf5 | ||
|
|
217c79d867 | ||
|
|
4c63223050 | ||
|
|
41a1acc36b | ||
|
|
9e1c2cca4e | ||
|
|
74c106aa87 | ||
|
|
700833b532 | ||
|
|
31ecf15e95 | ||
|
|
8afc94b51c | ||
|
|
2885dddccc | ||
|
|
0e4b7bc4d9 | ||
|
|
d6d13338e3 | ||
|
|
43ee70c01e | ||
|
|
6dfe28dab5 | ||
|
|
04e60b112b | ||
|
|
9e4c2dcbae | ||
|
|
1160a52753 | ||
|
|
af6ac9fb22 | ||
|
|
e1734746c0 | ||
|
|
21ad3135c8 | ||
|
|
f87b2c82c9 | ||
|
|
c25f4bada6 | ||
|
|
4f34a6db0f | ||
|
|
a7e41f77d2 | ||
|
|
6c4e47b395 | ||
|
|
3816d4128c | ||
|
|
fdaa591882 | ||
|
|
6b5c96a383 | ||
|
|
8ed2352fbe | ||
|
|
f613301f24 | ||
|
|
f51bb5714e | ||
|
|
065426b026 | ||
|
|
3a24fc34ca | ||
|
|
a95df3c6b1 |
+38
-32
@@ -1,35 +1,38 @@
|
|||||||
language: php
|
language: php
|
||||||
|
sudo: true
|
||||||
|
|
||||||
sudo: false
|
addons:
|
||||||
|
firefox: "latest-esr"
|
||||||
|
postgresql: "9.6"
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- "oracle-java8-installer"
|
||||||
|
- "oracle-java8-set-default"
|
||||||
|
|
||||||
os: "linux"
|
cache:
|
||||||
|
directories:
|
||||||
|
- "$HOME/.composer/cache"
|
||||||
|
- "$HOME/.npm"
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.6
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
|
- 7.2
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- DB=pgsql MOODLE_BRANCH=MOODLE_26_STABLE
|
global:
|
||||||
- DB=pgsql MOODLE_BRANCH=MOODLE_27_STABLE
|
- MOODLE_BRANCH=MOODLE_35_STABLE
|
||||||
- DB=pgsql MOODLE_BRANCH=MOODLE_28_STABLE
|
matrix:
|
||||||
- DB=pgsql MOODLE_BRANCH=MOODLE_29_STABLE
|
- DB=mysqli
|
||||||
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
|
- DB=pgsql
|
||||||
- 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 moodlerooms/moodle-plugin-ci ci ^1
|
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2
|
||||||
- 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:
|
||||||
@@ -40,31 +43,34 @@ 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 csslint
|
- moodle-plugin-ci validate
|
||||||
- moodle-plugin-ci shifter
|
- moodle-plugin-ci savepoints
|
||||||
- moodle-plugin-ci jshint
|
- moodle-plugin-ci mustache
|
||||||
|
- 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: deploy
|
- stage: test old
|
||||||
|
env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
|
||||||
|
php: 5.6
|
||||||
|
|
||||||
env:
|
- stage: deploy
|
||||||
- DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
|
php: 7.2
|
||||||
|
|
||||||
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
|
||||||
@@ -2,12 +2,23 @@
|
|||||||
[](https://github.com/valentineus/moodle-webhooks/releases)
|
[](https://github.com/valentineus/moodle-webhooks/releases)
|
||||||
[](https://travis-ci.org/valentineus/moodle-webhooks)
|
[](https://travis-ci.org/valentineus/moodle-webhooks)
|
||||||
[](https://www.codacy.com/app/valentineus/moodle-webhooks)
|
[](https://www.codacy.com/app/valentineus/moodle-webhooks)
|
||||||
[](https://gitter.im/valentineus/auth-link)
|
[](https://gitter.im/valentineus/moodle-webhooks)
|
||||||
|
|
||||||
Webhooks allow applications to subscribe to Moodle events.
|
Adding Webhooks to Moodle.
|
||||||
|
The Webhooks feature allows applications to receive real-time notification of changes to certain data.
|
||||||
|
|
||||||
**Attention!**:
|
Using Webhooks, your application will be able to receive notifications of changes to selected topics and their fields.
|
||||||
This plugin is in active development.
|
Because of this, you do not have to rely on continuous or even periodic requests to check for updates.
|
||||||
|
Notifications about Webhooks updates are sent as POST requests to the callback URL you specified.
|
||||||
|
Notifications can indicate the very fact of a field change or include a new value.
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* Use any number of services for notification;
|
||||||
|
* Customizing each external service;
|
||||||
|
* Interception of all events in the Moodle system;
|
||||||
|
* Use a secret phrase to authenticate requests;
|
||||||
|
* [JSON](https://en.wikipedia.org/wiki/JSON) - Format of outgoing data;
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,32 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Author: Valentin Popov
|
# Author: Valentin Popov
|
||||||
# Email: info@valentineus.link
|
# Email: info@valentineus.link
|
||||||
# Date: 2017-10-19
|
# Date: 2018-06-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"
|
||||||
|
|
||||||
# Build the package
|
# Current project
|
||||||
cd ..
|
PROJECT="local_webhooks"
|
||||||
mv "./moodle-webhooks" "./local_webhooks"
|
|
||||||
zip -9 -r "local_webhooks.zip" "local_webhooks" \
|
# Defining directories
|
||||||
-x "local_webhooks/.git*" \
|
DIRECTORY="$(pwd)"
|
||||||
-x "local_webhooks/.travis.yml" \
|
NAMEDIR="$(basename $DIRECTORY)"
|
||||||
-x "local_webhooks/build.sh"
|
TMPDIR="$(mktemp --directory)"
|
||||||
|
|
||||||
|
# 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
|
||||||
@@ -1,51 +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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a class for sending data.
|
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
|
|
||||||
defined("MOODLE_INTERNAL") || die();
|
|
||||||
|
|
||||||
class curl {
|
|
||||||
public function __construct() {
|
|
||||||
if (!function_exists("curl_init")) {
|
|
||||||
print_error("nocurl", "mnet");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function request($callback, $data) {
|
|
||||||
$ch = curl_init($callback->url);
|
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER,
|
|
||||||
array(
|
|
||||||
"Content-Type: application/" . $callback->type,
|
|
||||||
"Content-Length: " . strlen($data))
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 backup_performed extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "c";
|
||||||
|
$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("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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 backup_restored extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "u";
|
||||||
|
$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("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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 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.
|
||||||
|
*/
|
||||||
|
public static function get_name() {
|
||||||
|
return new \lang_string("answer", "moodle");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns description of what happened.
|
||||||
|
*/
|
||||||
|
public function get_description() {
|
||||||
|
return $this->other["status"];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL related to the action.
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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_added extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "c";
|
||||||
|
$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("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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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_deleted 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("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_updated extends \core\event\base {
|
||||||
|
/**
|
||||||
|
* Init method.
|
||||||
|
*/
|
||||||
|
protected function init() {
|
||||||
|
$this->data["crud"] = "u";
|
||||||
|
$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("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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,12 @@
|
|||||||
|
|
||||||
namespace local_webhooks;
|
namespace local_webhooks;
|
||||||
|
|
||||||
defined("MOODLE_INTERNAL") || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../lib.php");
|
||||||
|
require_once(__DIR__ . "/../locallib.php");
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/filelib.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines how to work with events.
|
* Defines how to work with events.
|
||||||
@@ -32,38 +37,20 @@ defined("MOODLE_INTERNAL") || die();
|
|||||||
* @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 events {
|
class handler {
|
||||||
/**
|
/**
|
||||||
* External handler.
|
* External handler.
|
||||||
*
|
*
|
||||||
* @param object $event
|
* @param object $event
|
||||||
*/
|
*/
|
||||||
public static function handler($event) {
|
public static function events($event) {
|
||||||
$enable = get_config("local_webhooks", "enable");
|
|
||||||
|
|
||||||
if (boolval($enable)) {
|
|
||||||
$data = $event->get_data();
|
$data = $event->get_data();
|
||||||
self::transmitter($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if ($callbacks = local_webhooks_get_list_records()) {
|
||||||
* Transmitter, processing event and services.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
*/
|
|
||||||
private static function transmitter($data) {
|
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$callbacks = $DB->get_recordset("local_webhooks_service");
|
|
||||||
|
|
||||||
if ($callbacks->valid()) {
|
|
||||||
foreach ($callbacks as $callback) {
|
foreach ($callbacks as $callback) {
|
||||||
self::handler_callback($data, $callback);
|
self::handler_callback($data, $callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$callbacks->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,16 +60,15 @@ class events {
|
|||||||
* @param object $callback
|
* @param object $callback
|
||||||
*/
|
*/
|
||||||
private static function handler_callback($data, $callback) {
|
private static function handler_callback($data, $callback) {
|
||||||
if ($callback->enable) {
|
global $CFG;
|
||||||
if (!empty($callback->events)) {
|
|
||||||
$events = unserialize(gzuncompress(base64_decode($callback->events)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (boolval($events[$data["eventname"]])) {
|
if (boolval($callback->enable)) {
|
||||||
/* Adding to the data token */
|
if (!empty($callback->events[$data["eventname"]])) {
|
||||||
if (boolval($callback->token)) {
|
$urlparse = parse_url($CFG->wwwroot);
|
||||||
|
|
||||||
|
$data["host"] = $urlparse['host'];
|
||||||
$data["token"] = $callback->token;
|
$data["token"] = $callback->token;
|
||||||
}
|
$data["extra"] = $callback->other;
|
||||||
|
|
||||||
self::send($data, $callback);
|
self::send($data, $callback);
|
||||||
}
|
}
|
||||||
@@ -96,17 +82,12 @@ class events {
|
|||||||
* @param object $callback
|
* @param object $callback
|
||||||
*/
|
*/
|
||||||
private static function send($data, $callback) {
|
private static function send($data, $callback) {
|
||||||
$curl = new curl();
|
$curl = new \curl();
|
||||||
$package = self::packup($data);
|
$curl->setHeader(array("Content-Type: application/" . $callback->type));
|
||||||
$curl::request($callback, $package);
|
$curl->post($callback->url, json_encode($data));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$response = $curl->getResponse();
|
||||||
* Packs the data for transmission.
|
\local_webhooks_events::response_answer($callback->id, $response);
|
||||||
*
|
return $response;
|
||||||
* @param array $data
|
|
||||||
*/
|
|
||||||
private static function packup($data) {
|
|
||||||
return json_encode($data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,23 +15,17 @@
|
|||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the form of editing the service.
|
* Defines forms.
|
||||||
*
|
*
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace local_webhooks;
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
defined("MOODLE_INTERNAL") || die();
|
|
||||||
|
|
||||||
require_once($CFG->libdir . "/formslib.php");
|
require_once($CFG->libdir . "/formslib.php");
|
||||||
|
|
||||||
use report_eventlist_list_generator;
|
|
||||||
use lang_string;
|
|
||||||
use moodleform;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description editing form definition.
|
* Description editing form definition.
|
||||||
*
|
*
|
||||||
@@ -46,63 +40,48 @@ class service_edit_form extends moodleform {
|
|||||||
parent::__construct($baseurl);
|
parent::__construct($baseurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unpacks data for display.
|
|
||||||
*
|
|
||||||
* @param object $record
|
|
||||||
*/
|
|
||||||
public function set_data($record) {
|
|
||||||
$record->events = unserialize(gzuncompress(base64_decode($record->events)));
|
|
||||||
return parent::set_data($record);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the standard structure of the form.
|
* Defines the standard structure of the form.
|
||||||
*/
|
*/
|
||||||
protected function definition() {
|
protected function definition() {
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
$size = array("size" => 60);
|
||||||
|
|
||||||
/* Form heading */
|
/* Form heading */
|
||||||
$mform->addElement("header", "editserviceheader",
|
$mform->addElement("header", "editserviceheader", new lang_string("service", "webservice"));
|
||||||
new lang_string("service", "webservice"));
|
|
||||||
|
|
||||||
/* Name of the service */
|
/* Name of the service */
|
||||||
$mform->addElement("text", "title",
|
$mform->addElement("text", "title", new lang_string("name", "moodle"), $size);
|
||||||
new lang_string("name", "moodle"),
|
|
||||||
array("size" => 60));
|
|
||||||
$mform->setType("title", PARAM_NOTAGS);
|
|
||||||
$mform->addRule("title", null, "required");
|
$mform->addRule("title", null, "required");
|
||||||
|
$mform->setType("title", PARAM_NOTAGS);
|
||||||
|
|
||||||
/* Callback address */
|
/* Callback address */
|
||||||
$mform->addElement("text", "url",
|
$mform->addElement("text", "url", new lang_string("url", "moodle"), $size);
|
||||||
new lang_string("url", "moodle"),
|
|
||||||
array("size" => 60));
|
|
||||||
$mform->setType("url", PARAM_URL);
|
|
||||||
$mform->addRule("url", null, "required");
|
$mform->addRule("url", null, "required");
|
||||||
|
$mform->setType("url", PARAM_URL);
|
||||||
|
|
||||||
/* Enabling the service */
|
/* Enabling the service */
|
||||||
$mform->addElement("advcheckbox", "enable",
|
$mform->addElement("advcheckbox", "enable", new lang_string("enable", "moodle"));
|
||||||
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",
|
$mform->addElement("text", "token", new lang_string("token", "webservice"), $size);
|
||||||
new lang_string("token", "webservice"),
|
|
||||||
array("size" => 60));
|
|
||||||
$mform->setType("token", PARAM_NOTAGS);
|
$mform->setType("token", PARAM_NOTAGS);
|
||||||
|
|
||||||
|
/* Additional information */
|
||||||
|
$mform->addElement("text", "other", new lang_string("sourceext", "plugin"), $size);
|
||||||
|
$mform->setType("other", PARAM_NOTAGS);
|
||||||
|
$mform->setAdvanced("other");
|
||||||
|
|
||||||
/* Content type */
|
/* Content type */
|
||||||
$mform->addElement("select", "type", "Content type",
|
$contenttype = array("json" => "application/json", "x-www-form-urlencoded" => "application/x-www-form-urlencoded");
|
||||||
array(
|
$mform->addElement("select", "type", "Content type", $contenttype);
|
||||||
"json" => "application/json",
|
|
||||||
"x-www-form-urlencoded" => "application/x-www-form-urlencoded"));
|
|
||||||
$mform->setAdvanced("type");
|
$mform->setAdvanced("type");
|
||||||
|
|
||||||
/* Form heading */
|
/* Form heading */
|
||||||
$mform->addElement("header", "editserviceheaderevent",
|
$mform->addElement("header", "editserviceheaderevent", new lang_string("edulevel", "moodle"));
|
||||||
new lang_string("edulevel", "moodle"));
|
|
||||||
|
|
||||||
/* List of events */
|
/* List of events */
|
||||||
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
||||||
@@ -110,8 +89,7 @@ class service_edit_form extends moodleform {
|
|||||||
|
|
||||||
/* Formation of the list of elements */
|
/* Formation of the list of elements */
|
||||||
foreach ($eventlist as $event) {
|
foreach ($eventlist as $event) {
|
||||||
$events[$event["component"]][] =&
|
$events[$event["component"]][] =& $mform->createElement("checkbox", $event["eventname"], $event["eventname"]);
|
||||||
$mform->createElement("checkbox", $event["eventname"], $event["eventname"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Displays groups of items */
|
/* Displays groups of items */
|
||||||
@@ -123,3 +101,35 @@ class service_edit_form extends moodleform {
|
|||||||
$this->add_action_buttons(true);
|
$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"));
|
||||||
|
|
||||||
|
/* 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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-4
@@ -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",
|
||||||
"eventname" => "*",
|
"eventname" => "*",
|
||||||
"callback" => "\local_webhooks\\events::handler",
|
|
||||||
"includefile" => null,
|
"includefile" => null,
|
||||||
"priority" => 200,
|
"internal" => true,
|
||||||
"internal" => true
|
"priority" => 200
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171026" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
|
<XMLDB PATH="local/webhooks/db" VERSION="2018061900" COMMENT="XMLDB file for Moodle" 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>
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
||||||
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
||||||
<FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
<FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
|
||||||
<FIELD NAME="events" TYPE="text" NOTNULL="true" SEQUENCE="false" />
|
<FIELD NAME="events" TYPE="text" NOTNULL="false" SEQUENCE="false" />
|
||||||
|
<FIELD NAME="other" TYPE="text" NOTNULL="false" SEQUENCE="false" />
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
|
||||||
|
|||||||
+22
-34
@@ -15,7 +15,7 @@
|
|||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service editor.
|
* Page for editing the service.
|
||||||
*
|
*
|
||||||
* @package local_webhooks
|
* @package local_webhooks
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
@@ -23,28 +23,25 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(__DIR__ . "/../../config.php");
|
require_once(__DIR__ . "/../../config.php");
|
||||||
require_once(__DIR__ . "/classes/forms.php");
|
require_once(__DIR__ . "/classes/service_form.php");
|
||||||
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
$idservice = optional_param("idservice", 0, PARAM_INT);
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
|
||||||
require_login();
|
/* Optional parameters */
|
||||||
|
$serviceid = optional_param("serviceid", 0, PARAM_INT);
|
||||||
|
|
||||||
/* Link generation */
|
/* Link generation */
|
||||||
$urlparameters = array("idservice" => $idservice);
|
$urlparameters = array("serviceid" => $serviceid);
|
||||||
$managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters);
|
|
||||||
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
|
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
|
||||||
$PAGE->set_url($baseurl, $urlparameters);
|
$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, array());
|
||||||
$context = context_system::instance();
|
$context = context_system::instance();
|
||||||
$PAGE->set_context($context);
|
|
||||||
|
|
||||||
/* Preparing a template for data */
|
|
||||||
$titlepage = new lang_string("externalservice", "webservice");
|
|
||||||
$servicerecord = new stdClass;
|
|
||||||
|
|
||||||
/* Create an editing form */
|
/* Create an editing form */
|
||||||
$mform = new \local_webhooks\service_edit_form($PAGE->url);
|
$mform = new service_edit_form($PAGE->url);
|
||||||
|
|
||||||
/* Cancel processing */
|
/* Cancel processing */
|
||||||
if ($mform->is_cancelled()) {
|
if ($mform->is_cancelled()) {
|
||||||
@@ -52,38 +49,29 @@ if ($mform->is_cancelled()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Getting the data */
|
/* Getting the data */
|
||||||
if ($idediting = boolval($idservice)) {
|
$servicerecord = new stdClass();
|
||||||
$servicerecord = $DB->get_record("local_webhooks_service", array("id" => $idservice), "*", MUST_EXIST);
|
if ($editing = boolval($serviceid)) {
|
||||||
|
$servicerecord = local_webhooks_get_record($serviceid);
|
||||||
$mform->set_data($servicerecord);
|
$mform->set_data($servicerecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Processing of received data */
|
/* Processing of received data */
|
||||||
if ($data = $mform->get_data()) {
|
if ($data = $mform->get_data()) {
|
||||||
/* Packing of data */
|
if ($editing) {
|
||||||
if (!empty($data->events)) {
|
$data->id = $serviceid;
|
||||||
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
|
local_webhooks_update_record($data, false);
|
||||||
}
|
redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice"));
|
||||||
|
|
||||||
if ($idediting) {
|
|
||||||
$data->id = $idservice;
|
|
||||||
$DB->update_record("local_webhooks_service", $data);
|
|
||||||
} else {
|
} else {
|
||||||
$DB->insert_record("local_webhooks_service", $data);
|
local_webhooks_update_record($data, true);
|
||||||
|
redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice"));
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect($managerservice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Page template */
|
|
||||||
$PAGE->set_pagelayout("admin");
|
|
||||||
$PAGE->set_heading($titlepage);
|
|
||||||
$PAGE->set_title($titlepage);
|
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
|
$titlepage = new lang_string("externalservice", "webservice");
|
||||||
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
|
|
||||||
$PAGE->navbar->add(new lang_string("managerservice", "local_webhooks"), $managerservice);
|
|
||||||
$PAGE->navbar->add($titlepage);
|
$PAGE->navbar->add($titlepage);
|
||||||
|
$PAGE->set_heading($titlepage);
|
||||||
|
$PAGE->set_title($titlepage);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
/* Displays the form */
|
/* Displays the form */
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service Management Manager.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../../config.php");
|
||||||
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
require_once($CFG->libdir . "/tablelib.php");
|
||||||
|
|
||||||
|
/* Optional parameters */
|
||||||
|
$backupservices = optional_param("getbackup", 0, PARAM_BOOL);
|
||||||
|
$deleteid = optional_param("deleteid", 0, PARAM_INT);
|
||||||
|
$hideshowid = optional_param("hideshowid", 0, PARAM_INT);
|
||||||
|
|
||||||
|
/* Link generation */
|
||||||
|
$editservice = "/local/webhooks/editservice.php";
|
||||||
|
$managerservice = "/local/webhooks/index.php";
|
||||||
|
$restorebackup = "/local/webhooks/restorebackup.php";
|
||||||
|
$baseurl = new moodle_url($managerservice);
|
||||||
|
|
||||||
|
/* Configure the context of the page */
|
||||||
|
admin_externalpage_setup("local_webhooks", "", null, $baseurl, array());
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
/* Delete the service */
|
||||||
|
if (boolval($deleteid)) {
|
||||||
|
local_webhooks_remove_record($deleteid);
|
||||||
|
redirect($PAGE->url, new lang_string("eventwebserviceservicedeleted", "webservice"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieving a list of services */
|
||||||
|
$callbacks = local_webhooks_get_list_records();
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Switching the status of the service */
|
||||||
|
if (boolval($hideshowid)) {
|
||||||
|
$callback = $callbacks[$hideshowid];
|
||||||
|
|
||||||
|
if (!empty($callback)) {
|
||||||
|
$callback->enable = !boolval($callback->enable);
|
||||||
|
local_webhooks_update_record($callback, false);
|
||||||
|
redirect($PAGE->url, new lang_string("eventwebserviceserviceupdated", "webservice"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The page title */
|
||||||
|
$titlepage = new lang_string("pluginname", "local_webhooks");
|
||||||
|
$PAGE->set_heading($titlepage);
|
||||||
|
$PAGE->set_title($titlepage);
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
|
/* Table declaration */
|
||||||
|
$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 (boolval($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);
|
||||||
|
echo $OUTPUT->single_button($addserviceurl, new lang_string("addaservice", "webservice"), "get");
|
||||||
|
|
||||||
|
/* Button to get a backup */
|
||||||
|
$backupurl = new moodle_url($managerservice, array("getbackup" => true));
|
||||||
|
echo $OUTPUT->single_button($backupurl, new lang_string("backup", "moodle"), "get");
|
||||||
|
|
||||||
|
/* Button for restoring settings */
|
||||||
|
$restorebackupurl = new moodle_url($restorebackup);
|
||||||
|
echo $OUTPUT->single_button($restorebackupurl, new lang_string("restore", "moodle"), "get");
|
||||||
|
|
||||||
|
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["managerservice"] = "Service management manager";
|
|
||||||
$string["pluginname"] = "WebHooks";
|
$string["pluginname"] = "WebHooks";
|
||||||
@@ -1,26 +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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strings for component "local_webhooks", language "ru".
|
|
||||||
*
|
|
||||||
* @package local_webhooks
|
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
$string["managerservice"] = "Менеджер управления службами";
|
|
||||||
$string["pluginname"] = "WebHooks";
|
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Library code used by the service control interfaces.
|
||||||
|
*
|
||||||
|
* @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__ . "/locallib.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting a list of all services.
|
||||||
|
*
|
||||||
|
* @param number $limitfrom
|
||||||
|
* @param number $limitnum
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function local_webhooks_get_list_records($limitfrom = 0, $limitnum = 0) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$listservices = $DB->get_records("local_webhooks_service", null, "id", "*", $limitfrom, $limitnum);
|
||||||
|
|
||||||
|
foreach ($listservices as $servicerecord) {
|
||||||
|
if (!empty($servicerecord->events)) {
|
||||||
|
$servicerecord->events = local_webhooks_unarchive_data($servicerecord->events);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $listservices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting information about the service.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
function local_webhooks_get_record($serviceid = 0) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$servicerecord = $DB->get_record("local_webhooks_service", array("id" => $serviceid), "*", MUST_EXIST);
|
||||||
|
|
||||||
|
if (!empty($servicerecord->events)) {
|
||||||
|
$servicerecord->events = local_webhooks_unarchive_data($servicerecord->events);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $servicerecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the database table.
|
||||||
|
*/
|
||||||
|
function local_webhooks_remove_list_records() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$DB->delete_records("local_webhooks_service", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the record.
|
||||||
|
*
|
||||||
|
* @param number $serviceid
|
||||||
|
*/
|
||||||
|
function local_webhooks_remove_record($serviceid = 0) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$DB->delete_records("local_webhooks_service", array("id" => $serviceid));
|
||||||
|
local_webhooks_events::service_deleted($serviceid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the record in the database.
|
||||||
|
*
|
||||||
|
* @param object $data
|
||||||
|
* @param boolean $insert
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function local_webhooks_update_record($data, $insert = true) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if (empty($data->events)) {
|
||||||
|
$data->events = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data->events = local_webhooks_archiving_data($data->events);
|
||||||
|
|
||||||
|
if (boolval($insert)) {
|
||||||
|
$result = $DB->insert_record("local_webhooks_service", $data, true, false);
|
||||||
|
local_webhooks_events::service_added($result);
|
||||||
|
} else {
|
||||||
|
$result = $DB->update_record("local_webhooks_service", $data, false);
|
||||||
|
local_webhooks_events::service_updated($data->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return boolval($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a backup copy of all the services.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function local_webhooks_create_backup() {
|
||||||
|
$listservices = local_webhooks_get_list_records();
|
||||||
|
$listservices = local_webhooks_archiving_data($listservices);
|
||||||
|
local_webhooks_events::backup_performed();
|
||||||
|
return $listservices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the data from the backup.
|
||||||
|
*
|
||||||
|
* @param string $data
|
||||||
|
*/
|
||||||
|
function local_webhooks_restore_backup($listservices = "") {
|
||||||
|
$listservices = local_webhooks_unarchive_data($listservices);
|
||||||
|
|
||||||
|
local_webhooks_remove_list_records();
|
||||||
|
|
||||||
|
foreach ($listservices as $servicerecord) {
|
||||||
|
local_webhooks_update_record($servicerecord, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
local_webhooks_events::backup_restored();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compress an array into a string.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function local_webhooks_archiving_data($data = array()) {
|
||||||
|
$result = base64_encode(gzcompress(serialize($data), 3));
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an array from a compressed string.
|
||||||
|
*
|
||||||
|
* @param string $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function local_webhooks_unarchive_data($data = "") {
|
||||||
|
$result = unserialize(gzuncompress(base64_decode($data)));
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
+144
@@ -0,0 +1,144 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classes of modules.
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of functions of the call of events
|
||||||
|
*
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class local_webhooks_events {
|
||||||
|
/**
|
||||||
|
* Call the event when creating a backup.
|
||||||
|
*/
|
||||||
|
public static function backup_performed() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
$event = local_webhooks\event\backup_performed::create(
|
||||||
|
array(
|
||||||
|
"context" => $context,
|
||||||
|
"objectid" => 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the event when restoring from a backup.
|
||||||
|
*/
|
||||||
|
public static function backup_restored() {
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
$event = local_webhooks\event\backup_restored::create(
|
||||||
|
array(
|
||||||
|
"context" => $context,
|
||||||
|
"objectid" => 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call event when the response is received from the service
|
||||||
|
*
|
||||||
|
* @param number $objectid Service ID
|
||||||
|
* @param array $response Server response
|
||||||
|
*/
|
||||||
|
public static function response_answer($objectid = 0, $response = array()) {
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
$status = "Error sending request";
|
||||||
|
if (!empty($response["HTTP/1.1"])) {
|
||||||
|
$status = $response["HTTP/1.1"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$event = local_webhooks\event\response_answer::create(
|
||||||
|
array(
|
||||||
|
"context" => $context,
|
||||||
|
"objectid" => $objectid,
|
||||||
|
"other" => array("status" => $status)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the event when the service is added.
|
||||||
|
*
|
||||||
|
* @param number $objectid Service ID
|
||||||
|
*/
|
||||||
|
public static function service_added($objectid = 0) {
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
$event = local_webhooks\event\service_added::create(
|
||||||
|
array(
|
||||||
|
"context" => $context,
|
||||||
|
"objectid" => $objectid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the event when the service is deleted.
|
||||||
|
*
|
||||||
|
* @param number $objectid Service ID
|
||||||
|
*/
|
||||||
|
public static function service_deleted($objectid = 0) {
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
$event = local_webhooks\event\service_deleted::create(
|
||||||
|
array(
|
||||||
|
"context" => $context,
|
||||||
|
"objectid" => $objectid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call event when the service is updated.
|
||||||
|
*
|
||||||
|
* @param number $objectid Service ID
|
||||||
|
*/
|
||||||
|
public static function service_updated($objectid = 0) {
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
$event = local_webhooks\event\service_updated::create(
|
||||||
|
array(
|
||||||
|
"context" => $context,
|
||||||
|
"objectid" => $objectid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$event->trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,105 +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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service Management Manager.
|
|
||||||
*
|
|
||||||
* @package local_webhooks
|
|
||||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once(__DIR__ . "/../../config.php");
|
|
||||||
require_once($CFG->libdir . "/tablelib.php");
|
|
||||||
|
|
||||||
$deleteservice = optional_param("deleteservice", 0, PARAM_INT);
|
|
||||||
|
|
||||||
require_login();
|
|
||||||
|
|
||||||
/* Link generation */
|
|
||||||
$managerservice = "/local/webhooks/managerservice.php";
|
|
||||||
$editservice = "/local/webhooks/editservice.php";
|
|
||||||
$baseurl = new moodle_url($managerservice);
|
|
||||||
$PAGE->set_url($baseurl);
|
|
||||||
|
|
||||||
/* Configure the context of the page */
|
|
||||||
$context = context_system::instance();
|
|
||||||
$PAGE->set_context($context);
|
|
||||||
|
|
||||||
/* Delete the service */
|
|
||||||
if ($deleteservice && confirm_sesskey()) {
|
|
||||||
$DB->delete_records("local_webhooks_service", array("id" => $deleteservice));
|
|
||||||
redirect($PAGE->url, new lang_string("deleted", "moodle"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Retrieving a list of services */
|
|
||||||
$select = null;
|
|
||||||
$callbacks = $DB->get_records_select("local_webhooks_service", $select, null, $DB->sql_order_by_text("id"));
|
|
||||||
|
|
||||||
/* Page template */
|
|
||||||
$titlepage = new lang_string("managerservice", "local_webhooks");
|
|
||||||
$PAGE->set_pagelayout("standard");
|
|
||||||
$PAGE->set_title($titlepage);
|
|
||||||
$PAGE->set_heading($titlepage);
|
|
||||||
|
|
||||||
/* The page title */
|
|
||||||
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
|
|
||||||
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
|
|
||||||
$PAGE->navbar->add($titlepage, $baseurl);
|
|
||||||
echo $OUTPUT->header();
|
|
||||||
|
|
||||||
/* Table declaration */
|
|
||||||
$table = new flexible_table("callbacks-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");
|
|
||||||
|
|
||||||
/* Link for editing */
|
|
||||||
$editlink = new moodle_url($editservice,
|
|
||||||
array("idservice" => $callback->id));
|
|
||||||
$edititem = $OUTPUT->action_icon($editlink,
|
|
||||||
new pix_icon("t/edit", get_string("edit")));
|
|
||||||
|
|
||||||
/* Link to remove */
|
|
||||||
$deletelink = new moodle_url($managerservice,
|
|
||||||
array("deleteservice" => $callback->id, "sesskey" => sesskey()));
|
|
||||||
$deleteitem = $OUTPUT->action_icon($deletelink,
|
|
||||||
new pix_icon("t/delete", get_string("delete")));
|
|
||||||
|
|
||||||
/* Adding data to the table */
|
|
||||||
$table->add_data(array($titlecallback, $urlcallback, $edititem . $deleteitem));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display the table */
|
|
||||||
$table->print_html();
|
|
||||||
|
|
||||||
/* Add service button */
|
|
||||||
$addurl = new moodle_url("/local/webhooks/editservice.php");
|
|
||||||
echo $OUTPUT->single_button($addurl,
|
|
||||||
new lang_string("addaservice", "webservice"), "get");
|
|
||||||
|
|
||||||
echo $OUTPUT->footer();
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the settings page.
|
||||||
|
*
|
||||||
|
* @package local_webhooks
|
||||||
|
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/../../config.php");
|
||||||
|
require_once(__DIR__ . "/classes/service_form.php");
|
||||||
|
require_once(__DIR__ . "/lib.php");
|
||||||
|
|
||||||
|
require_once($CFG->libdir . "/adminlib.php");
|
||||||
|
|
||||||
|
/* Link generation */
|
||||||
|
$baseurl = new moodle_url("/local/webhooks/restorebackup.php");
|
||||||
|
$managerservice = new moodle_url("/local/webhooks/index.php");
|
||||||
|
|
||||||
|
/* Configure the context of the page */
|
||||||
|
admin_externalpage_setup("local_webhooks", "", null, $baseurl, array());
|
||||||
|
$context = context_system::instance();
|
||||||
|
|
||||||
|
/* Create an editing form */
|
||||||
|
$mform = new service_backup_form($PAGE->url);
|
||||||
|
|
||||||
|
/* Cancel processing */
|
||||||
|
if ($mform->is_cancelled()) {
|
||||||
|
redirect($managerservice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Processing the received file */
|
||||||
|
if ($data = $mform->get_data()) {
|
||||||
|
$content = $mform->get_file_content("backupfile");
|
||||||
|
local_webhooks_restore_backup($content);
|
||||||
|
redirect($managerservice, new lang_string("restorefinished", "moodle"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The page title */
|
||||||
|
$titlepage = new lang_string("backup", "moodle");
|
||||||
|
$PAGE->navbar->add($titlepage);
|
||||||
|
$PAGE->set_heading($titlepage);
|
||||||
|
$PAGE->set_title($titlepage);
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
|
/* Displays the form */
|
||||||
|
$mform->display();
|
||||||
|
|
||||||
|
echo $OUTPUT->footer();
|
||||||
+5
-18
@@ -22,24 +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();
|
||||||
|
|
||||||
$settings = null;
|
|
||||||
if ($hassiteconfig) {
|
if ($hassiteconfig) {
|
||||||
$settings = new admin_settingpage("local_webhooks",
|
$ADMIN->add("server", new admin_externalpage("local_webhooks",
|
||||||
new lang_string("pluginname", "local_webhooks"));
|
new lang_string("pluginname", "local_webhooks"),
|
||||||
|
new moodle_url("/local/webhooks/index.php")
|
||||||
$ADMIN->add("localplugins", $settings);
|
));
|
||||||
|
|
||||||
$settings->add(new admin_setting_configcheckbox(
|
|
||||||
"local_webhooks/enable",
|
|
||||||
new lang_string("enable", "moodle"),
|
|
||||||
new lang_string("enablews", "webservice"),
|
|
||||||
false));
|
|
||||||
|
|
||||||
/* Link to the service manager */
|
|
||||||
$linktext = new lang_string("managerservice", "local_webhooks");
|
|
||||||
$linkurl = new moodle_url("/local/webhooks/managerservice.php");
|
|
||||||
$settings->add(new admin_setting_heading("local_webhooks_managerservice", null,
|
|
||||||
html_writer::link($linkurl, $linktext)));
|
|
||||||
}
|
}
|
||||||
+5
-4
@@ -22,9 +22,10 @@
|
|||||||
* @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->release = "0.4.0 (Build: 2017102620)";
|
|
||||||
$plugin->version = 2017102620;
|
$plugin->release = "3.0.1 (Build: 2018061900)";
|
||||||
|
$plugin->version = 2018061900;
|
||||||
$plugin->requires = 2016112900;
|
$plugin->requires = 2016112900;
|
||||||
$plugin->component = "local_webhooks";
|
$plugin->component = "local_webhooks";
|
||||||
$plugin->maturity = MATURITY_BETA;
|
$plugin->maturity = MATURITY_STABLE;
|
||||||
Reference in New Issue
Block a user