Delete unnecessary files

Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
Valentin Popov 2018-09-09 05:00:43 +04:00
parent 05ce3e0664
commit 5d942ccbb2
Signed by: Valentin Popov
GPG Key ID: 269A00ACA90A8EA3
5 changed files with 0 additions and 358 deletions

View File

@ -1,31 +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/>.
/**
* Definition of the plug-in cache.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$definitions = array(
"webhooks_services" => array(
"mode" => cache_store::MODE_APPLICATION,
"requiredataguarantee" => true,
"staticacceleration" => true
)
);

View File

@ -1,111 +0,0 @@
# 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:
![Service Manager](screenshots/managerservice.jpg)
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:
![Service Editor](screenshots/editservice.jpg)
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.

Before

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 KiB

View File

@ -1,216 +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/>.
/**
* 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();
define("LOCAL_WEBHOOKS_NAME_CACHE_REPOSITORY", "webhooks_services");
define("LOCAL_WEBHOOKS_NAME_PLUGIN", "local_webhooks");
/**
* Get data from the cache by key.
*
* @param string $eventname
* @return array
*/
function local_webhooks_cache_get($eventname) {
$cache = cache::make(LOCAL_WEBHOOKS_NAME_PLUGIN, LOCAL_WEBHOOKS_NAME_CACHE_REPOSITORY);
return $cache->get($eventname);
}
/**
* Update the data in the cache by key.
*
* @param string $eventname
* @param array $recordlist
* @return boolean
*/
function local_webhooks_cache_set($eventname, $recordlist = array()) {
$cache = cache::make(LOCAL_WEBHOOKS_NAME_PLUGIN, LOCAL_WEBHOOKS_NAME_CACHE_REPOSITORY);
return $cache->set($eventname, $recordlist);
}
/**
* Delete the data in the cache by key.
*
* @param string $eventname
* @return boolean
*/
function local_webhooks_cache_delete($eventname) {
$cache = cache::make(LOCAL_WEBHOOKS_NAME_PLUGIN, LOCAL_WEBHOOKS_NAME_CACHE_REPOSITORY);
return $cache->delete($eventname);
}
/**
* Clear the cache of the plugin.
*
* @return boolean
*/
function local_webhooks_cache_reset() {
$cache = cache::make(LOCAL_WEBHOOKS_NAME_PLUGIN, LOCAL_WEBHOOKS_NAME_CACHE_REPOSITORY);
return $cache->purge();
}
/**
* Forms a list of events for the specified service.
*
* @param number $serviceid
* @param number $limitfrom
* @param number $limitnum
* @return array
*/
function local_webhooks_get_list_events_for_service($serviceid, $limitfrom = 0, $limitnum = 0) {
global $DB;
$rs = $DB->get_recordset(LOCAL_WEBHOOKS_TABLE_EVENTS, array("serviceid" => $serviceid), "id", "*", $limitfrom, $limitnum);
$events = array();
foreach ($rs as $record) {
$events[$record->name] = $record->status;
}
$rs->close();
return $events;
}
/**
* Adds all events to the database.
*
* @param number $serviceid
* @param array $events
* @return boolean
*/
function local_webhooks_insert_events_for_service($serviceid, $events) {
global $DB;
$records = array();
foreach ($events as $eventname => $eventstatus) {
$event = new stdClass();
$event->name = $eventname;
$event->status = $eventstatus;
$event->serviceid = $serviceid;
$records[] = $event;
}
local_webhooks_delete_events_for_service($serviceid);
return $DB->insert_records(LOCAL_WEBHOOKS_TABLE_EVENTS, $records);
}
/**
* Deleting all the events linked to the given service.
*
* @param number $serviceid
* @return boolean
*/
function local_webhooks_delete_events_for_service($serviceid) {
global $DB;
return $DB->delete_records(LOCAL_WEBHOOKS_TABLE_EVENTS, array("serviceid" => $serviceid));
}
/**
* 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 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();
}
/**
* 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();
}
}