From 5d942ccbb23b2688c13c5490362d7bcab6ca516c Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 9 Sep 2018 05:00:43 +0400 Subject: Delete unnecessary files Signed-off-by: Valentin Popov --- db/caches.php | 31 ------ docs/getting-started.md | 111 ------------------ docs/screenshots/editservice.jpg | Bin 168551 -> 0 bytes docs/screenshots/managerservice.jpg | Bin 124492 -> 0 bytes locallib.php | 216 ------------------------------------ 5 files changed, 358 deletions(-) delete mode 100644 db/caches.php delete mode 100644 docs/getting-started.md delete mode 100644 docs/screenshots/editservice.jpg delete mode 100644 docs/screenshots/managerservice.jpg delete mode 100644 locallib.php diff --git a/db/caches.php b/db/caches.php deleted file mode 100644 index 270354c..0000000 --- a/db/caches.php +++ /dev/null @@ -1,31 +0,0 @@ -. - -/** - * Definition of the plug-in cache. - * - * @package local_webhooks - * @copyright 2017 "Valentin Popov" - * @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 - ) -); \ No newline at end of file diff --git a/docs/getting-started.md b/docs/getting-started.md deleted file mode 100644 index a70e09c..0000000 --- a/docs/getting-started.md +++ /dev/null @@ -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). \ No newline at end of file diff --git a/docs/screenshots/editservice.jpg b/docs/screenshots/editservice.jpg deleted file mode 100644 index 875a62d..0000000 Binary files a/docs/screenshots/editservice.jpg and /dev/null differ diff --git a/docs/screenshots/managerservice.jpg b/docs/screenshots/managerservice.jpg deleted file mode 100644 index e251807..0000000 Binary files a/docs/screenshots/managerservice.jpg and /dev/null differ diff --git a/locallib.php b/locallib.php deleted file mode 100644 index d615c6a..0000000 --- a/locallib.php +++ /dev/null @@ -1,216 +0,0 @@ -. - -/** - * Classes of modules. - * - * @package local_webhooks - * @copyright 2017 "Valentin Popov" - * @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" - * @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(); - } -} \ No newline at end of file -- cgit v1.2.3