Compare commits

...
Author SHA1 Message Date
Valentin Popov 040d7540d7 Reworked the main page
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-12 04:58:59 +04:00
Valentin Popov 9c2eefcaa5 Added a class table for list services
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-12 04:51:19 +04:00
Valentin Popov 98aecd35ce Added final improvements for external functions
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-12 03:34:03 +04:00
Valentin Popov c42e13d182 Fixed violations CI
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-11 13:54:14 +04:00
Valentin Popov 7dc023b05a Added external function update existing service
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-11 03:45:50 +04:00
Valentin Popov 3a865453a4 Added external function get the event's list
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-11 02:40:47 +04:00
Valentin Popov 747055f9d1 Added external function add service
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-11 00:57:18 +04:00
Valentin Popov ed0ce52060 Added external function delete service
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-11 00:17:20 +04:00
Valentin Popov 6b18cffc97 Added external function get the list services
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 23:45:18 +04:00
Valentin Popov 0cbc05d52b Added exact other tests
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 22:43:32 +04:00
Valentin Popov ae2f31261d Added exact test get record by an event
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 22:12:01 +04:00
Valentin Popov 46711c9942 Added correct test delete record
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 15:34:57 +04:00
Valentin Popov e84ac6859a Renamed a classes function "delete_service"
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 15:22:48 +04:00
Valentin Popov e550237b4b Renamed a classes function "update_service"
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 15:20:56 +04:00
Valentin Popov db2d98d210 Renamed a classes function "create_service"
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 15:19:18 +04:00
Valentin Popov 5b0dba4980 Added external function get service
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-10 14:22:56 +04:00
Valentin Popov d441f44698 Added get a total count records
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-09 20:35:59 +04:00
Valentin Popov cb6d5c7e13 Added sort fields
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-09 19:09:36 +04:00
Valentin Popov da306feae3 Added a minor fix
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-08 03:06:28 +04:00
Valentin Popov 9a1b781107 Fixed error's list with CI
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-08 02:54:48 +04:00
Valentin Popov 8bf6ed8122 Added function get an event's list
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-08 02:47:19 +04:00
Valentin Popov e2627eaf86 Fixed errors from CI
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-08 01:17:40 +04:00
Valentin Popov eb4b9b69f8 Added worked a class observer
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-06 05:47:03 +04:00
Valentin Popov bde135499d Added a new class for processing events
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-06 04:46:09 +04:00
Valentin Popov 4806fad728 Did a deep refactoring main class in the plugin
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-06 04:27:01 +04:00
Valentin Popov 654eade42b Added description record's class
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-06 00:10:26 +04:00
Valentin Popov 3f50d21a7f Primary test cases the library
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-05 17:18:08 +04:00
Valentin Popov 08a54b0e9f Primary test function for add, update and delete
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-05-05 16:15:38 +04:00
Valentin Popov 6f6d50776c Created a worked upgrade mechanism
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-04-28 17:54:09 +04:00
Valentin Popov 7ae31a6eee Created a worked upgrade mechanism
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-04-28 17:53:22 +04:00
Valentin Popov 0fe3b14f29 Fixed errors CI config
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-04-28 14:31:51 +04:00
Valentin Popov 0cdfc1b1cf Disable a tests old version
Signed-off-by: Valentin Popov <info@valentineus.link>
2019-04-28 14:17:31 +04:00
Valentin Popov a2bc4b735c Removal of excess conversion
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-29 02:44:17 +04:00
Valentin Popov 0a44411f98 External service search function by event
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-29 02:43:09 +04:00
Valentin Popov b8e61c44ac External function of getting these services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-29 02:30:45 +04:00
Valentin Popov 6c31017c8d External function to get service data
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-29 02:27:57 +04:00
Valentin Popov 00309285ba Connecting external reading services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-29 01:39:05 +04:00
Valentin Popov ad5fb98070 Fix 'Line exceeds 132 characters'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-26 14:31:00 +04:00
Valentin Popov 09c54f6627 Update from version 4.0.0-rc.*
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-26 05:20:18 +04:00
Valentin Popov a01ad5f97c Update from version 3.*
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-26 04:42:26 +04:00
Valentin Popov d8f5be6670 Moodle style fixes
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-22 04:04:35 +04:00
Valentin Popov 99c835a63d Correction of implicit style errors
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-22 03:48:04 +04:00
Valentin Popov 14e5a16a33 Update file template
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-22 03:02:00 +04:00
Valentin Popov 1352b5ee79 Code style fix
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-10-22 02:59:06 +04:00
Valentin Popov f3b5ab5616 Updating the autotest file
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-25 07:52:01 +04:00
Valentin Popov f28ff05598 Removing the page restoring backups
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-25 07:39:58 +04:00
Valentin Popov 7892ecc2fd Updating the language file
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 18:41:40 +04:00
Valentin Popov 5115697a62 Comments added
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 18:36:28 +04:00
Valentin Popov 68a1928a4c Redesigned page of the service editor
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 18:29:50 +04:00
Valentin Popov 6e82b7cc19 Removing old web services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 18:07:50 +04:00
Valentin Popov 36ddf415c4 Reducing nesting in the code
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 18:05:02 +04:00
Valentin Popov 67cf87d17c Correction of the file name
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 17:59:58 +04:00
Valentin Popov dc4bc38f80 Removing old event recorders
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-20 17:46:42 +04:00
Valentin Popov 73f45578b3 Correction of checks
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 21:47:37 +04:00
Valentin Popov c18d7107b9 Formatting the code on the settings page
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 21:13:57 +04:00
Valentin Popov 1701c9cf97 Adapted homepage
* The work of basic functions has been restored.
* The control buttons are moved down.
* Removed redundant functionality:
  * Backup data.
  * Delete all records.
  * Restore from a backup.

Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 21:09:12 +04:00
Valentin Popov d0e7af84ff A reworked table for displaying a list of services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 05:33:14 +04:00
Valentin Popov aae3ea70b2 Fix table version
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 05:08:26 +04:00
Valentin Popov 16305051a9 TODO and function type change
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 05:04:36 +04:00
Valentin Popov 5d942ccbb2 Delete unnecessary files
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 05:00:43 +04:00
Valentin Popov 05ce3e0664 Task handler from the list
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 04:57:04 +04:00
Valentin Popov 17b9cfde78 Service search function on the event
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 04:38:27 +04:00
Valentin Popov 270c04a603 Minor fixes to the function 'get_services'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 04:29:38 +04:00
Valentin Popov 2194bc4a01 Refactoring the event handler
Event processing is asynchronous.  For asynchronous processing, events
are added to the job queue.

Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-09 03:23:12 +04:00
Valentin Popov 5884a58f54 Added TODO
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-08 18:13:45 +04:00
Valentin Popov 472f85850a Basic function of getting a list of all services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-08 16:06:39 +04:00
Valentin Popov 816110da62 Basic function of obtaining data about the service
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-08 15:46:57 +04:00
Valentin Popov 295da67a0a Formatting the code
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-08 15:23:37 +04:00
Valentin Popov 7d2e288b70 Realization of the basic functionality
* Function of adding a service to the database.
* Function of updating the service in the database.
* Function of removing the service from the database.

Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-07 15:27:59 +04:00
Valentin Popov fa86c0329f Updating the table structure
* Fixed bug with 'XMLDB PATH'.  The latest update to Moodle includes
a strict check.
* Remotely the status field in the event table.  The logic is
simplified, if there is an event subscription, the event is stored in
a table.  There are no subscriptions, no events in the table.

Signed-off-by: Valentin Popov <info@valentineus.link>
2018-09-07 14:36:17 +04:00
Valentin Popov 9ee0af7e28 Reworked the event handler
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-21 08:13:13 +04:00
Valentin Popov 9006e6b9dd Renamed function search services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-21 08:12:22 +04:00
Valentin Popov 2b791958a7 Redesigned cache name
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-21 07:48:01 +04:00
Valentin Popov 4833a44b51 Redesigned feature a list of services
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-21 07:46:03 +04:00
Valentin Popov d7185f5925 Minor bug fixed
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-20 04:42:44 +04:00
Valentin Popov 975c6f8d20 Checking arguments is added
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-20 04:31:14 +04:00
Valentin Popov 092d0436e8 Comments have been added
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-20 04:23:13 +04:00
Valentin Popov 27e7f48f36 Updated description
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-20 04:19:08 +04:00
Valentin Popov 41a6a89ac8 Updated the status change function
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-20 04:13:47 +04:00
Valentin Popov 279fca5ed1 Added cache to the search function
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-20 03:58:45 +04:00
Valentin Popov 5036ef261c The function 'local_webhooks_get_total_count' is deleted
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:53:32 +04:00
Valentin Popov 6aed41d675 Fixed the name of the constant
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:52:44 +04:00
Valentin Popov 25f1756835 The internal functions 'local_webhooks_serialization_data' and 'local_webhooks_deserialization_data' are deleted
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:50:55 +04:00
Valentin Popov 490b8bb170 Update function 'local_webhooks_restore_backup'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:43:23 +04:00
Valentin Popov 95c54f8262 Update function 'local_webhooks_create_backup'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:34:19 +04:00
Valentin Popov 6a83be960e Update function 'local_webhooks_search_record'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:17:22 +04:00
Valentin Popov 82842e5ed8 Update function 'local_webhooks_change_status'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 01:01:42 +04:00
Valentin Popov 98c33a639a Added function 'local_webhooks_delete_all_records'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:52:51 +04:00
Valentin Popov 98e5a6470d Added function 'local_webhooks_delete_record'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:48:12 +04:00
Valentin Popov e8b59e7b0d Update function 'local_webhooks_get_list_records'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:25:55 +04:00
Valentin Popov 46b6022269 Added variables
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:18:28 +04:00
Valentin Popov 2bd5e80b10 Rewritten 'local_webhooks_get_record' feature
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:16:08 +04:00
Valentin Popov af4224e8db Renaming internal functions
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:10:56 +04:00
Valentin Popov 79fe101e1b Added function 'local_webhooks_get_list_events_for_service'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-13 00:08:18 +04:00
Valentin Popov b12c850a2f Fix: Global variable
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 23:52:38 +04:00
Valentin Popov 57a870f56f Update function 'local_webhooks_create_record'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 23:48:00 +04:00
Valentin Popov 639276c33d Added function 'local_webhooks_update_record'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 23:45:35 +04:00
Valentin Popov 0d9fe62ec6 The function 'local_webhooks_insert_event' is replaced by the function 'local_webhooks_insert_events'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 23:38:14 +04:00
Valentin Popov 2b7e419f8f Added internal function 'local_webhooks_insert_event'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 23:29:02 +04:00
Valentin Popov adb9a1e69c Added internal function 'local_webhooks_delete_events'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 23:23:57 +04:00
Valentin Popov 2c013b3230 The function 'local_webhooks_create_record' was rewritten for new storage
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 22:50:40 +04:00
Valentin Popov f3dc13ac91 Service edit form is focused on the new standard
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 22:09:36 +04:00
Valentin Popov 4d69ca0da6 The revised structure of information storage
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 21:54:39 +04:00
Valentin Popov f220e057bd The web service 'local_webhooks_get_list_records' has been expanded
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 14:48:20 +04:00
Valentin Popov 422cbfd57d New parameters of function 'local_webhooks_get_list_records' have been added
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 14:38:33 +04:00
Valentin Popov e0a43273a3 Added constants to the cache
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 14:20:30 +04:00
Valentin Popov cce50b316d Delete the variable
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 03:42:08 +04:00
Valentin Popov 55b1a6b5a9 Delimiter
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 03:30:57 +04:00
Valentin Popov 6a711bfc48 Fixed a potential performance hole
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 03:24:38 +04:00
Valentin Popov 9ada0cfe74 Using a constant
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 02:29:32 +04:00
Valentin Popov 0a07c2ab22 Added a new function 'local_webhooks_get_total_count'
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 02:05:27 +04:00
Valentin Popov 0e94634c49 Updated description
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 01:45:08 +04:00
Valentin Popov d29ee546a2 Renaming a variable
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-12 01:44:01 +04:00
Valentin Popov 27fe9e412b Fixed table in the latest version of Moodle
Signed-off-by: Valentin Popov <info@valentineus.link>
2018-03-11 22:31:15 +04:00
Valentin Popov 9cf4fc575c Correction of spaces 2018-02-25 01:32:29 +04:00
Valentin Popov f3c2ebbe4d Correcting a stupid mistake 2018-02-25 01:27:40 +04:00
Valentin Popov 8f25379f32 Change version 2018-02-25 01:21:50 +04:00
Valentin Popov 90897b0e7d General refactoring of the web services code 2018-02-25 01:19:19 +04:00
Valentin Popov 685d9ee15e Change version 2018-02-22 12:58:37 +04:00
Valentin Popov db500cddce Fix 'invalid OPTIONAL value specified' 2018-02-22 12:55:20 +04:00
Valentin Popov 85bcb64e37 Added general list functions 2018-02-22 12:44:50 +04:00
Valentin Popov 1736128dbf Adding the function of forming events 2018-02-22 12:37:59 +04:00
Valentin Popov 5cdd8de9e3 Small code refactoring 2018-02-20 15:40:50 +04:00
Valentin Popov b6ddc8bd40 Some variables have been removed 2018-02-20 15:17:27 +04:00
Valentin Popov f10786bfb0 Update function 'local_webhooks_create_record' 2018-02-20 14:38:36 +04:00
Valentin Popov 899b129d23 The extension is added to the event handler 2018-02-19 15:26:27 +04:00
Valentin Popov dd19065313 The extension is added to external functions 2018-02-19 15:25:49 +04:00
Valentin Popov 3a2bddeea4 The search function is expanded 2018-02-19 15:24:34 +04:00
Valentin Popov a41dbbb950 Transferring internal functions to the internal library 2018-02-19 13:44:11 +04:00
Valentin Popov a68882140b An external service search function is declared 2018-02-19 13:38:27 +04:00
Valentin Popov 43f0bf98d2 Added external functions to find services 2018-02-19 13:37:27 +04:00
Valentin Popov 95c4cf061a Rename the function to reset the cache 2018-02-19 13:15:14 +04:00
Valentin Popov a1099245b5 Cache description added 2018-02-19 13:06:06 +04:00
Valentin Popov 66b5928e6e Added clearing the cache when changing data 2018-02-19 12:36:09 +04:00
Valentin Popov 4f75d9c5c8 Event handler is rewritten to work with the cache 2018-02-18 22:05:58 +04:00
Valentin Popov 29bdbc7456 Added a service search function that contains the specified event 2018-02-18 21:37:43 +04:00
Valentin Popov ebf76795da Change the location of the functions for working with the cache 2018-02-18 21:28:46 +04:00
Valentin Popov 53c49b69de Added functions for working with the cache 2018-02-18 20:01:55 +04:00
Valentin Popov f392fd42d9 Update the PHP version for testing. 2018-02-18 18:05:33 +04:00
Valentin Popov 67f8d73a15 Update versions of Moodle for testing. 2018-02-18 18:02:23 +04:00
Valentin Popov 22b7569f71 Correct the check for 'sesskey'. 2018-02-18 17:58:59 +04:00
Valentin Popov fa74622268 Links to the editor contain sesskey 2018-01-04 15:38:55 +04:00
Valentin Popov 9b7426fb20 Check the sesskey on the editor page 2018-01-04 15:35:27 +04:00
Valentin Popov 283c64f62e Check the sesskey on the recovery page 2018-01-04 15:34:51 +04:00
Valentin Popov 17ae01ab71 Change version 2017-12-29 14:29:39 +04:00
Valentin Popov 28e1169be8 Added correct update from old versions 2017-12-29 14:25:49 +04:00
Valentin Popov 2126708201 An additional column is added 2017-12-27 21:03:09 +04:00
Valentin Popov 0041667754 Refactoring the handler class 2017-12-27 20:45:31 +04:00
Valentin Popov 91bf79f030 Added function to send the request 2017-12-27 20:43:36 +04:00
Valentin Popov 7d1a0b9fec Updated the function to update the record 2017-12-27 20:30:27 +04:00
Valentin Popov 51007a0fb5 Register a new external function 2017-12-27 19:52:21 +04:00
Valentin Popov 2eaa622161 Added external function display a list of events 2017-12-27 19:51:34 +04:00
Valentin Popov 3d4b78bd8b Added the function of receiving all the events 2017-12-27 16:01:48 +04:00
Valentin Popov 41185c6db4 Reconstructed external restore function from the backup 2017-12-27 15:47:36 +04:00
Valentin Popov 7e1284bfe2 Edit the result of the function 2017-12-27 15:29:58 +04:00
Valentin Popov 785a541d1c Registration of external plug-in functions is added 2017-12-27 15:27:55 +04:00
Valentin Popov 6e3bf072af Added external plugin functions 2017-12-27 15:26:59 +04:00
Valentin Popov 2e57e732ba Fixed the text of the button 2017-12-22 18:58:27 +04:00
Valentin Popov 499f36d118 Integration of the event system into functions 2017-12-21 12:06:20 +04:00
Valentin Popov 49516bea82 Refactoring the system of events 2017-12-21 11:48:43 +04:00
Valentin Popov a6c6081139 Edit translation 2017-12-21 11:36:42 +04:00
Valentin Popov 9560267833 Refactoring the editor code 2017-12-21 11:31:58 +04:00
Valentin Popov 2057a1efb6 The functional was updated to a new form 2017-12-21 11:14:40 +04:00
Valentin Popov 0cbf2bbb87 The data recovery form has been extended 2017-12-21 11:12:40 +04:00
Valentin Popov 3e054dd94e Updated package dependencies 2017-12-21 11:11:24 +04:00
Valentin Popov 54fb29c5ea Correction on the main page 2017-12-21 10:01:37 +04:00
Valentin Popov 78e9e435cc Refactoring function code plugins 2017-12-21 09:59:14 +04:00
Valentin Popov 97711bb186 Added function to change the status of the service 2017-12-19 14:50:30 +04:00
Valentin Popov 999ad9f472 Refactoring the main page 2017-12-19 14:39:40 +04:00
Valentin Popov 82c7463e4a A class was added to display the table 2017-12-19 14:15:07 +04:00
Valentin Popov e0e9322644 Additions to the description file 2017-12-11 07:47:51 +04:00
Valentin Popov 7278ee951b Changes to the User's Guide 2017-12-11 07:43:17 +04:00
Valentin Popov 01e2ba9f2f User guide 2017-12-11 07:37:49 +04:00
Valentin Popov 99868c158a Screenshots for documentation 2017-12-11 07:37:09 +04:00
Valentin Popov bdaf1d35b2 Change version 2017-11-26 11:20:22 +04:00
Valentin Popov 7cfdf29600 Local class for calling events 2017-11-26 11:15:50 +04:00
Valentin Popov bec8dcdc08 Update event registration classes 2017-11-23 22:00:36 +04:00
Valentin Popov 2ae949bbc3 Adding a logging system 2017-11-23 21:55:40 +04:00
Valentin Popov de3c3a6553 Correcting errors, adding a logging system 2017-11-23 21:54:50 +04:00
Valentin Popov 05512c5440 Repeated refactoring of the event handler 2017-11-23 19:29:36 +04:00
Valentin Popov 91754489b0 Renaming a file 2017-11-23 18:57:22 +04:00
Valentin Popov f8b85a270c Refactoring the code of the event handler 2017-11-23 18:54:31 +04:00
Valentin Popov 4bf6f61131 External backup function 2017-11-23 18:44:30 +04:00
Valentin Popov 3da34ec7f1 Fix the link 2017-11-23 18:12:42 +04:00
Valentin Popov 4f342659d4 Updating external functions 2017-11-23 18:11:33 +04:00
Valentin Popov 0bc809ba07 Refactoring the backup recovery code 2017-11-23 18:09:56 +04:00
Valentin Popov 03d22ef096 Refactoring the code for creating forms 2017-11-23 17:58:29 +04:00
Valentin Popov 1c87dae035 Refactoring the service manager code 2017-11-23 17:56:59 +04:00
Valentin Popov 5639dc7b0f Refactoring the code of the service editor 2017-11-23 17:37:41 +04:00
Valentin Popov 1ad4527c1d External code of the library 2017-11-23 17:24:40 +04:00
Valentin Popov 57cac60ab3 Code refactoring 2017-11-22 13:59:02 +04:00
Valentin Popov d4d105c018 Change version 2017-11-18 08:35:16 +04:00
Valentin Popov 3ea8f29329 Adding event calls 2017-11-18 08:34:23 +04:00
Valentin Popov c1077bc9c1 Service deletion event 2017-11-18 08:33:04 +04:00
Valentin Popov bc02d0dce2 Service update event 2017-11-18 08:32:03 +04:00
Valentin Popov 93d788f046 Service creation event 2017-11-18 08:30:38 +04:00
Valentin Popov 29c12fa971 Renaming an event 2017-11-18 08:29:21 +04:00
Valentin Popov 1e8cbe7f09 Recovery event 2017-11-18 08:26:49 +04:00
Valentin Popov ad07800be9 Backup event 2017-11-18 08:25:05 +04:00
Valentin Popov f28b408b1e Added hostname to the request 2017-11-18 07:34:38 +04:00
Valentin Popov 91fd140bd4 Change version 2017-11-18 06:40:10 +04:00
Valentin Popov 463aeaf043 Correcting the page template 2017-11-18 06:37:58 +04:00
Valentin Popov 97140dccf7 Aesthetics in the code 2017-11-18 06:31:25 +04:00
Valentin Popov bf2cef3ea0 Recovery algorithm 2017-11-18 05:41:28 +04:00
Valentin Popov 7b56375c05 Form class loading a backup 2017-11-18 04:56:33 +04:00
Valentin Popov b61e5a08be Generate another backup file 2017-11-17 20:14:01 +04:00
Valentin Popov 4a470056a7 Template of the restore settings page 2017-11-17 19:58:45 +04:00
Valentin Popov 688448b350 Added backup function 2017-11-17 18:24:59 +04:00
Valentin Popov 35358ea7cc Updating pages for a new section 2017-11-15 10:49:36 +04:00
Valentin Popov 97296b795a Updated the event handler 2017-11-15 10:46:09 +04:00
Valentin Popov 0fcec2738d Update the settings file 2017-11-15 10:43:51 +04:00
Valentin Popov e1372c6d34 Change version 2017-10-29 12:57:39 +04:00
Valentin Popov 098514660f Edit translation 2017-10-29 12:56:45 +04:00
Valentin Popov 07970f36e3 Processor additional field 2017-10-29 11:32:50 +04:00
Valentin Popov 1e81988bf5 Change version 2017-10-29 11:26:26 +04:00
Valentin Popov 217c79d867 Additional field in the database 2017-10-29 11:25:23 +04:00
Valentin Popov 4c63223050 Adding an additional field 2017-10-29 11:24:15 +04:00
Valentin Popov 41a1acc36b Bug Fix 2017-10-27 12:59:21 +04:00
Valentin Popov 9e1c2cca4e Additional check of variables 2017-10-27 12:51:58 +04:00
Valentin Popov 74c106aa87 Change version 2017-10-27 12:45:25 +04:00
Valentin Popov 700833b532 Simplification of the class 2017-10-27 12:41:48 +04:00
Valentin Popov 31ecf15e95 Filtering for possible errors 2017-10-27 12:41:15 +04:00
Valentin Popov 8afc94b51c Renaming a variable 2017-10-27 12:28:20 +04:00
Valentin Popov 2885dddccc Edit translation 2017-10-27 12:25:07 +04:00
Valentin Popov 0e4b7bc4d9 Event registration is added 2017-10-27 12:22:55 +04:00
Valentin Popov d6d13338e3 Grinding of the final class 2017-10-27 12:16:21 +04:00
Valentin Popov 43ee70c01e Deleting an additional table 2017-10-27 12:11:25 +04:00
Valentin Popov 6dfe28dab5 The described class for simple journaling 2017-10-27 12:10:16 +04:00
Valentin Popov 04e60b112b Additional table 2017-10-27 11:28:10 +04:00
Valentin Popov 9e4c2dcbae Rename a class 2017-10-27 10:57:40 +04:00
Valentin Popov 1160a52753 Rename the handler class 2017-10-27 08:51:27 +04:00
Valentin Popov af6ac9fb22 A small correction of logic 2017-10-27 08:04:23 +04:00
Valentin Popov e1734746c0 Change version 2017-10-26 18:57:01 +04:00
Valentin Popov 21ad3135c8 Bug fix 2017-10-26 18:28:34 +04:00
Valentin Popov f87b2c82c9 Maximum minimization of internal transfer 2017-10-26 18:25:48 +04:00
Valentin Popov c25f4bada6 Updating layers of external pages 2017-10-26 18:18:31 +04:00
Valentin Popov 4f34a6db0f Refactoring the class displaying the form of the editor 2017-10-26 17:41:16 +04:00
Valentin Popov a7e41f77d2 Refactoring the code to work with events 2017-10-26 17:34:34 +04:00
Valentin Popov 6c4e47b395 Bug fix 2017-10-26 17:31:08 +04:00
Valentin Popov 3816d4128c Minor corrections 2017-10-26 17:30:02 +04:00
Valentin Popov fdaa591882 Refactoring the editor code 2017-10-26 17:25:30 +04:00
Valentin Popov 6b5c96a383 Refactoring the configuration file code 2017-10-26 17:11:34 +04:00
Valentin Popov 8ed2352fbe Refactoring the service manager code 2017-10-26 17:09:15 +04:00
Valentin Popov f613301f24 Correcting the error if there is no value 2017-10-26 16:33:40 +04:00
Valentin Popov f51bb5714e Supplemented description 2017-10-26 11:35:49 +04:00
Valentin Popov 065426b026 Refactoring of data sending 2017-10-26 11:07:01 +04:00
Valentin Popov 3a24fc34ca Small improvements cURL 2017-10-26 10:38:35 +04:00
Valentin Popov a95df3c6b1 Set page layout 2017-10-26 10:15:47 +04:00
Valentin Popov 2744e4fb80 Change version 2017-10-26 09:49:40 +04:00
Valentin Popov 5179a7ec05 Header type processing 2017-10-26 09:48:08 +04:00
Valentin Popov 18a5d23d07 Correction of transmitted parameters 2017-10-26 09:44:44 +04:00
Valentin Popov f43b3f2fd3 Adding an additional field to the database 2017-10-26 09:37:10 +04:00
Valentin Popov ea30d3ca56 Adding the field 'Content type' 2017-10-26 09:35:56 +04:00
Valentin Popov e86542d8f7 Fix for errors with empty values 2017-10-26 09:21:52 +04:00
Valentin Popov dab55b9562 Change the variable 2017-10-26 09:20:32 +04:00
Valentin Popov c2cd361171 We save even more memory 2017-10-26 08:38:08 +04:00
Valentin Popov eaee6b7c81 Change version 2017-10-26 08:02:33 +04:00
Valentin Popov 282e3bcaf1 Add a token to the request 2017-10-26 08:01:16 +04:00
Valentin Popov c037edbc58 Added a field to the database for the security key 2017-10-26 07:51:42 +04:00
Valentin Popov 2c4c05acd6 The form for the security key has been added 2017-10-26 07:50:30 +04:00
26 changed files with 2544 additions and 602 deletions
+31 -47
View File
@@ -1,35 +1,41 @@
language: php
sudo: true
sudo: false
addons:
firefox: "latest-esr"
postgresql: "9.6"
os: "linux"
apt:
packages:
- "mysql-client-5.6"
- "mysql-client-core-5.6"
- "mysql-server-5.6"
- "openjdk-8-jre-headless"
cache:
directories:
- "$HOME/.composer/cache"
- "$HOME/.npm"
php:
- 5.6
- 7.1
- "7.0"
- "7.1"
- "7.2"
env:
- DB=pgsql MOODLE_BRANCH=MOODLE_26_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_27_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_28_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_29_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_30_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_32_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_26_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_27_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_28_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_29_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_30_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_31_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_32_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
matrix:
- MOODLE_BRANCH=MOODLE_35_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_35_STABLE DB=pgsql
- MOODLE_BRANCH=MOODLE_36_STABLE DB=mysqli
- MOODLE_BRANCH=MOODLE_36_STABLE DB=pgsql
before_install:
- phpenv config-rm xdebug.ini
- nvm install 8.9
- nvm use 8.9
- cd ../..
- 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"
install:
@@ -40,31 +46,9 @@ script:
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci csslint
- moodle-plugin-ci shifter
- moodle-plugin-ci jshint
- moodle-plugin-ci validate
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpunit
- moodle-plugin-ci behat
jobs:
include:
stage: deploy
env:
- DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE
php: 7.1
before_deploy:
- cd $TRAVIS_REPO_SLUG
- git stash --all
- /bin/sh build.sh
deploy:
provider: releases
skip_cleanup: true
file: "../local_webhooks.zip"
email: "info@valentineus.link"
api_key: $GITHUB_PROJECT_TOKEN
on:
tags: true
+17 -22
View File
@@ -2,34 +2,29 @@
[![GitHub Release](https://img.shields.io/github/release/valentineus/moodle-webhooks.svg)](https://github.com/valentineus/moodle-webhooks/releases)
[![Build Status](https://travis-ci.org/valentineus/moodle-webhooks.svg?branch=master)](https://travis-ci.org/valentineus/moodle-webhooks)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/376ab669f2d3436884015554f686a915)](https://www.codacy.com/app/valentineus/moodle-webhooks)
[![Gitter Badge](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/valentineus/auth-link)
[![Gitter Badge](https://badges.gitter.im/Join%20Chat.svg)](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!**:
This plugin is in active development.
Using Webhooks, your application will be able to receive notifications of changes to selected topics and their fields.
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.
## Installation
Features:
Get the installation package in any of the available methods:
* 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;
* [GitHub Releases](https://github.com/valentineus/moodle-webhooks/releases).
* [Compilation from the source code](#build).
## Documentation
## 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
```
* [Install the plugin](docs/getting-started.md#installation).
* [User guide](docs/getting-started.md#user-guide).
* [Request format](docs/getting-started.md#request-format).
## License
-51
View File
@@ -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($url, $data) {
$ch = curl_init($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/json",
"Content-Length: " . strlen($data))
);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace local_webhooks\event;
defined('MOODLE_INTERNAL') || die();
use core\event\base as event;
use core\task\manager;
use local_webhooks\task\notify;
use function defined;
/**
* Class observer.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks\event
*/
final class observer {
/**
* Main handler for events.
*
* @param \core\event\base $event
*/
public static function handler(event $event) {
$task = new notify();
$task->set_custom_data($event->get_data());
manager::queue_adhoc_task($task);
}
}
-105
View File
@@ -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/>.
/**
* The event handler.
*
* @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();
/**
* 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 events {
/**
* External handler.
*
* @param object $event
*/
public static function handler($event) {
$config = get_config("local_webhooks");
if (boolval($config->enable)) {
$data = $event->get_data();
self::transmitter($data);
}
}
/**
* 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) {
self::handler_callback($data, $callback);
}
}
$callbacks->close();
}
/**
* Processes each callback.
*
* @param array $data
* @param object $callback
*/
private static function handler_callback($data, $callback) {
if ($callback->enable) {
$events = unserialize(gzuncompress(base64_decode($callback->events)));
if (boolval($events[$data["eventname"]])) {
self::send($data, $callback);
}
}
}
/**
* Sending data to the node.
*
* @param array $data
* @param object $callback
*/
private static function send($data, $callback) {
$curl = new curl();
$package = self::packup($data);
$curl::request($callback->url, $package);
}
/**
* Packs the data for transmission.
*
* @param array $data
*/
private static function packup($data) {
return json_encode($data);
}
}
-112
View File
@@ -1,112 +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/>.
/**
* Defines the form of editing the service.
*
* @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();
require_once($CFG->libdir . "/formslib.php");
use report_eventlist_list_generator;
use lang_string;
use moodleform;
/**
* Description editing form definition.
*
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class service_edit_form extends moodleform {
/**
* @param string $baseurl
*/
public function __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.
*/
protected function definition() {
$mform =& $this->_form;
/* Form heading */
$mform->addElement("header", "editserviceheader",
new lang_string("service", "webservice"));
/* Name of the service */
$mform->addElement("text", "title",
new lang_string("name", "moodle"),
array("size" => 60));
$mform->setType("title", PARAM_NOTAGS);
$mform->addRule("title", null, "required");
/* Callback address */
$mform->addElement("text", "url",
new lang_string("url", "moodle"),
array("size" => 60));
$mform->setType("url", PARAM_URL);
$mform->addRule("url", null, "required");
/* Enabling the service */
$mform->addElement("checkbox", "enable",
new lang_string("enable", "moodle"));
$mform->setType("enable", PARAM_BOOL);
$mform->setDefault("enable", 1);
$mform->setAdvanced("enable");
/* Form heading */
$mform->addElement("header", "editserviceheaderevent",
new lang_string("edulevel", "moodle"));
/* List of events */
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
$events = array();
/* Formation of the list of elements */
foreach ($eventlist as $event) {
$events[$event["component"]][] =&
$mform->createElement("advcheckbox", $event["eventname"], $event["eventname"]);
}
/* Displays groups of items */
foreach ($events as $key => $event) {
$mform->addGroup($event, "events", $key, "<br />", true);
}
/* Control Panel */
$this->add_action_buttons(true);
}
}
+361
View File
@@ -0,0 +1,361 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace local_webhooks\local;
defined('MOODLE_INTERNAL') || die();
define('LW_TABLE_EVENTS', 'local_webhooks_events');
define('LW_TABLE_SERVICES', 'local_webhooks_service');
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/classes/local/record.php');
use coding_exception;
use core_component;
use ReflectionClass;
use function define;
use function defined;
use function is_array;
use function is_int;
use function is_object;
use function is_string;
use function strlen;
/**
* The main class for the plugin.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks\local
*/
final class api {
/**
* Create a new record in the database.
*
* @param \local_webhooks\local\record $record
*
* @return int
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function add_service(record $record): int {
global $DB;
$id = $DB->insert_record(LW_TABLE_SERVICES, $record);
if (is_int($id) && is_array($record->events)) {
$DB->insert_records(LW_TABLE_EVENTS, array_map(static function (string $name) use ($id) {
return ['name' => $name, 'serviceid' => $id];
}, $record->events));
}
if (!is_int($id)) {
throw new coding_exception('Variable \'id\' must be type \'Integer\'');
}
return $id;
}
/**
* Delete an existing record in the database.
*
* @param int $id
*
* @return bool
*
* @throws \dml_exception
*/
public static function del_service(int $id): bool {
global $DB;
$DB->delete_records(LW_TABLE_EVENTS, ['serviceid' => $id]);
return $DB->delete_records(LW_TABLE_SERVICES, ['id' => $id]);
}
/**
* Get an event's list.
*
* @return array
*
* @throws \ReflectionException
*/
public static function get_events(): array {
return array_merge(self::get_core_events_list(), self::get_non_core_event_list());
}
/**
* Get an existing record from the database.
*
* @param int $id
*
* @return \local_webhooks\local\record
*
* @throws \dml_exception
*/
public static function get_service(int $id): record {
global $DB;
$record = $DB->get_record(LW_TABLE_SERVICES, ['id' => $id], '*', MUST_EXIST);
$events = $DB->get_records(LW_TABLE_EVENTS, ['serviceid' => $id]);
$service = new record();
$service->events = array_column($events, 'name');
$service->header = $record->header;
$service->id = $record->id;
$service->name = $record->name;
$service->point = $record->point;
$service->status = $record->status;
$service->token = $record->token;
return $service;
}
/**
* Get list records from the database.
*
* @param array|null $conditions
* @param string|null $sort
* @param int|null $from
* @param int|null $limit
*
* @return array
*
* @throws \dml_exception
*/
public static function get_services(array $conditions = null, string $sort = null, int $from = null, int $limit = null): array {
global $DB;
$records = $DB->get_records(LW_TABLE_SERVICES, $conditions ?? [], $sort ?? '', '*', $from ?? 0, $limit ?? 0);
$services = [];
foreach ($records as $record) {
if (!is_object($record)) {
continue;
}
$events = $DB->get_records(LW_TABLE_EVENTS, ['serviceid' => $record->id]);
$service = new record();
$service->events = array_column($events, 'name');
$service->header = $record->header;
$service->id = $record->id;
$service->name = $record->name;
$service->point = $record->point;
$service->status = $record->status;
$service->token = $record->token;
$services[] = $service;
}
return $services;
}
/**
* Get list records from the database by the event's name.
*
* @param string $name
*
* @return \local_webhooks\local\record[]
*
* @throws \dml_exception
*/
public static function get_services_by_event(string $name): array {
global $DB;
$events = $DB->get_records(LW_TABLE_EVENTS, ['name' => $name]);
$services = [];
foreach ($events as $event) {
if (!is_object($event)) {
continue;
}
$services[] = self::get_service($event->serviceid);
}
return $services;
}
/**
* Get a total count of existing records.
*
* @return int
*
* @throws \dml_exception
*/
public static function get_total_count(): int {
global $DB;
return $DB->count_records(LW_TABLE_SERVICES);
}
/**
* Update an existing record in the database.
*
* @param \local_webhooks\local\record $service
*
* @return bool
*
* @throws \coding_exception
* @throws \dml_exception
*/
public static function set_service(record $service): bool {
global $DB;
$result = $DB->update_record(LW_TABLE_SERVICES, $service);
$DB->delete_records(LW_TABLE_EVENTS, ['serviceid' => $service->id]);
if ($result && is_array($service->events)) {
$DB->insert_records(LW_TABLE_EVENTS, array_map(static function (string $name) use ($service) {
return ['name' => $name, 'serviceid' => $service->id];
}, $service->events));
}
return $result;
}
/**
* Get a system's events list.
*
* @return array
*
* @throws \ReflectionException
*/
private static function get_core_events_list(): array {
global $CFG;
$debugdeveloper = $CFG->debugdeveloper;
$debugdisplay = $CFG->debugdisplay;
$debuglevel = $CFG->debug;
$CFG->debug = 0;
$CFG->debugdeveloper = false;
$CFG->debugdisplay = false;
$directory = $CFG->libdir . '/classes/event';
$events = [];
$files = self::get_file_list($directory);
if (isset($files['unknown_logged'])) {
unset($files['unknown_logged']);
}
foreach (array_keys($files) as $file) {
$name = '\\core\\event\\' . $file;
if (method_exists($name, 'get_static_info')) {
$class = new ReflectionClass($name);
if ($file !== 'manager' && !$class->isAbstract()) {
$events[$name] = $name::get_static_info();
}
}
}
$CFG->debug = $debuglevel;
$CFG->debugdeveloper = $debugdeveloper;
$CFG->debugdisplay = $debugdisplay;
return $events;
}
/**
* Get a file's list in the directory.
*
* @param string $directory
*
* @return array
*/
private static function get_file_list(string $directory): array {
global $CFG;
$files = [];
$root = $CFG->dirroot;
if (is_dir($directory) && is_readable($directory)) {
$handle = opendir($directory);
if ($handle) {
foreach (scandir($directory, SCANDIR_SORT_NONE) as $file) {
if ($file !== '.' && $file !== '..' && strrpos($directory, $root) !== false) {
$location = substr($directory, strlen($root));
$eventname = substr($file, 0, -4);
if (is_string($eventname)) {
$files[$eventname] = $location . '/' . $file;
}
}
}
}
}
return $files;
}
/**
* Get a plugins' events list.
*
* @return array
*
* @throws \ReflectionException
*/
private static function get_non_core_event_list(): array {
global $CFG;
$debugdeveloper = $CFG->debugdeveloper;
$debugdisplay = $CFG->debugdisplay;
$debuglevel = $CFG->debug;
$CFG->debug = 0;
$CFG->debugdeveloper = false;
$CFG->debugdisplay = false;
$events = [];
foreach (array_keys(core_component::get_plugin_types()) as $type) {
foreach (core_component::get_plugin_list($type) as $plugin => $directory) {
$directory .= '/classes/event';
$files = self::get_file_list($directory);
if (isset($files['unknown_logged'])) {
unset($files['unknown_logged']);
}
foreach (array_keys($files) as $file) {
$name = '\\' . $type . '_' . $plugin . '\\event\\' . $file;
if (method_exists($name, 'get_static_info')) {
$class = new ReflectionClass($name);
if ($type . '_' . $plugin !== 'logstore_legacy' && !$class->isAbstract()) {
$events[$name] = $name::get_static_info();
}
}
}
}
}
$CFG->debug = $debuglevel;
$CFG->debugdeveloper = $debugdeveloper;
$CFG->debugdisplay = $debugdisplay;
return $events;
}
}
+95
View File
@@ -0,0 +1,95 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace local_webhooks\local;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use function defined;
/**
* It's a class description record.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks\local
*/
final class record extends stdClass {
/**
* List of some events.
*
* @var array|null
*/
public $events;
/**
* Type of the package.
*
* @var string
*/
public $header;
/**
* A unique identifier of the service.
*
* @var int|null
*/
public $id;
/**
* Name of the service.
*
* @var string
*/
public $name;
/**
* Url's an endpoint to send notifications.
*
* @var string
*/
public $point;
/**
* Status activity of the service.
*
* @var bool
*/
public $status;
/**
* Secret key of the service.
*
* @var string
*/
public $token;
/**
* Classes constructor.
*
* @param array|null $conditions
*/
public function __construct(array $conditions = null) {
$this->events = $conditions['events'] ?? null;
$this->header = $conditions['header'] ?? null;
$this->id = $conditions['id'] ?? null;
$this->name = $conditions['name'] ?? null;
$this->point = $conditions['point'] ?? null;
$this->status = $conditions['status'] ?? null;
$this->token = $conditions['token'] ?? null;
}
}
+184
View File
@@ -0,0 +1,184 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace local_webhooks\output;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/classes/local/api.php');
require_once($CFG->libdir . '/tablelib.php');
use html_writer;
use lang_string;
use local_webhooks\local\api;
use moodle_url;
use pix_icon;
use stdClass;
use table_sql;
use function defined;
use function is_int;
/**
* Class table for list services.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks\output
*/
final class services_table extends table_sql {
/**
* URL editor page.
*
* @var string
*/
private static $editorpage = '/local/webhooks/service.php';
/**
* URL main page.
*
* @var string
*/
private static $mainpage = '/local/webhooks/index.php';
/**
* Class constructor.
*
* @param string $uniqueid
*
* @throws \coding_exception
*/
public function __construct(string $uniqueid) {
parent::__construct($uniqueid);
$this->define_table_columns();
$this->define_table_configs();
}
/**
* Define the action column.
*
* @param \stdClass $row
*
* @return string
*
* @throws \coding_exception
* @throws \moodle_exception
*/
public function col_actions(stdClass $row): string {
global $OUTPUT;
$deletelink = new moodle_url(self::$mainpage, ['deleteid' => $row->id, 'sesskey' => sesskey()]);
$deleteitem = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', new lang_string('delete', 'moodle')));
$editlink = new moodle_url(self::$editorpage, ['serviceid' => $row->id, 'sesskey' => sesskey()]);
$edititem = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', new lang_string('edit', 'moodle')));
$hideshowlink = new moodle_url(self::$mainpage, ['hideshowid' => $row->id, 'sesskey' => sesskey()]);
$hideshowitem = $OUTPUT->action_icon($hideshowlink, new pix_icon($row->status ? 't/hide' : 't/show', $row->status
? new lang_string('disable', 'moodle')
: new lang_string('enable', 'moodle')
));
return $hideshowitem . $edititem . $deleteitem;
}
/**
* Define the events column.
*
* @param \stdClass $row
*
* @return int
*/
public function col_events(stdClass $row): int {
$total = count($row->events);
return is_int($total) ? $total : 0;
}
/**
* Define the name column.
*
* @param \stdClass $row
*
* @return string
*
* @throws \moodle_exception
*/
public function col_name(stdClass $row): string {
$link = new moodle_url(self::$editorpage, [
'serviceid' => $row->id,
'sesskey' => sesskey(),
]);
return html_writer::link($link, $row->name);
}
/**
* Config table's columns.
*
* @throws \coding_exception
*/
public function define_table_columns() {
$this->define_columns([
'name',
'point',
'events',
'actions',
]);
$this->define_headers([
new lang_string('name', 'moodle'),
new lang_string('url', 'moodle'),
new lang_string('edulevel', 'moodle'),
new lang_string('actions', 'moodle'),
]);
}
/**
* Config table.
*/
public function define_table_configs() {
$this->collapsible(false);
$this->is_downloadable(false);
$this->no_sorting('actions');
$this->no_sorting('events');
$this->pageable(true);
}
/**
* The query for the database.
*
* @param int $pagesize
* @param bool $useinitialsbar
*
* @throws \dml_exception
*/
public function query_db($pagesize, $useinitialsbar = true) {
$this->pagesize($pagesize, $pagesize + 1);
$sort = (string) $this->get_sql_sort();
$this->rawdata = api::get_services(null, $sort, $this->get_page_start(), $this->get_page_size());
$total = api::get_total_count();
$this->pagesize($pagesize, $total);
if ($useinitialsbar) {
$this->initialbars($total > $pagesize);
}
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace local_webhooks\task;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/classes/local/api.php');
use core\task\adhoc_task;
use curl;
use local_webhooks\local\api;
use local_webhooks\local\record;
use function defined;
use function is_object;
use function is_string;
/**
* Class for processing events.
*
* @package local_webhooks\task
*/
final class notify extends adhoc_task {
/**
* Debug information.
*
* @var array
*/
public $debug;
/**
* Process an event.
*
* @throws \dml_exception
*/
public function execute() {
$event = $this->get_custom_data();
if (!is_object($event) || !isset($event->eventname) || !is_string($event->eventname)) {
return;
}
foreach (api::get_services_by_event($event->eventname) as $service) {
if (!is_object($service)) {
continue;
}
if (!$service->status) {
continue;
}
$this->post($service, array_merge((array) $event, [
'token' => $service->token,
]));
}
}
/**
* Send a request for the service.
*
* @param \local_webhooks\local\record $service
* @param array $data
*/
public function post(record $service, array $data) {
$curl = new curl();
$curl->setHeader(['Content-Type: ' . $service->header]);
$curl->post($service->point, json_encode($data));
if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) {
$this->debug = array_merge($this->debug ?? [], [
compact('data', 'service'),
]);
}
}
}
+105
View File
@@ -0,0 +1,105 @@
<?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/>.
/**
* Defines forms.
*
* @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/local/webhooks/lib.php');
require_once($CFG->libdir . '/formslib.php');
/**
* Description editing form definition.
*
* @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks
*/
class local_webhooks_service_edit_form extends moodleform {
/**
* @param string $baseurl
*/
public function __construct($baseurl) {
parent::__construct($baseurl);
}
/**
* Defines the standard structure of the form.
*
* @throws \coding_exception
*/
protected function definition() {
$mform =& $this->_form;
$size = array('size' => 60);
/* Form heading */
$mform->addElement('header', 'edit-service-header-main', new lang_string('service', 'webservice'));
/* Name of the service */
$mform->addElement('text', 'name', new lang_string('name', 'moodle'), $size);
$mform->addRule('name', null, 'required');
$mform->setType('name', PARAM_RAW);
/* Callback address */
$mform->addElement('text', 'point', new lang_string('url', 'moodle'), $size);
$mform->addRule('point', null, 'required');
$mform->setType('point', PARAM_URL);
/* Enabling the service */
$mform->addElement('advcheckbox', 'status', new lang_string('enable', 'moodle'));
$mform->setType('status', PARAM_BOOL);
$mform->setDefault('status', 1);
$mform->setAdvanced('status');
/* Token */
$mform->addElement('text', 'token', new lang_string('token', 'webservice'), $size);
$mform->addRule('token', null, 'required');
$mform->setType('token', PARAM_RAW);
/* Content type */
$contenttype = array(
'application/json' => 'application/json',
'application/x-www-form-urlencoded' => 'application/x-www-form-urlencoded',
);
$mform->addElement('select', 'header', 'Content-Type', $contenttype);
$mform->setAdvanced('header');
/* Form heading */
$mform->addElement('header', 'edit-service-header-event', new lang_string('edulevel', 'moodle'));
/* List of events */
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
$events = array();
foreach ($eventlist as $event) {
$events[$event['component']][] =& $mform->createElement('checkbox', $event['eventname'], $event['eventname']);
}
foreach ($events as $key => $event) {
$mform->addGroup($event, 'events', $key, '<br />', true);
}
/* Control Panel */
$this->add_action_buttons(true);
}
}
+9 -13
View File
@@ -15,21 +15,17 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Interception of all events in the system.
* Registration of observers for events.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined("MOODLE_INTERNAL") || die();
defined('MOODLE_INTERNAL') || die();
$observers = array(
array(
"eventname" => "*",
"callback" => "\local_webhooks\\events::handler",
"includefile" => null,
"priority" => 200,
"internal" => true
)
);
$observers = [
[
'callback' => '\local_webhooks\event\observer::handler',
'eventname' => '*',
],
];
+22 -6
View File
@@ -1,17 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171025" 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="2018090700" COMMENT="XMLDB file for Moodle local/webhooks"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
<TABLES>
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
<TABLE NAME="local_webhooks_service" COMMENT="Storing created services.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="enable" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
<FIELD NAME="title" TYPE="text" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="events" TYPE="text" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="header" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" DEFAULT="application/json" COMMENT="Type of outgoing header." />
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Name of the service." />
<FIELD NAME="point" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Point of delivery of notifications." />
<FIELD NAME="status" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Current status of the service." />
<FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Token for verification of requests." />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="local_webhooks_events" COMMENT="Storing of viewed events.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Name of the service." />
<FIELD NAME="serviceid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Service ID." />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
+74
View File
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file registers the plugin's external functions.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$functions = [
'local_webhooks_add_service' => [
'classname' => 'local_webhooks_external',
'classpath' => 'local/webhooks/externallib.php',
'description' => 'Add a new service.',
'methodname' => 'add_service',
'type' => 'write',
],
'local_webhooks_del_service' => [
'classname' => 'local_webhooks_external',
'classpath' => 'local/webhooks/externallib.php',
'description' => 'Delete the existing service.',
'methodname' => 'del_service',
'type' => 'write',
],
'local_webhooks_get_events' => [
'classname' => 'local_webhooks_external',
'classpath' => 'local/webhooks/externallib.php',
'description' => 'Get the event\'s list.',
'methodname' => 'get_events',
'type' => 'read',
],
'local_webhooks_get_service' => [
'classname' => 'local_webhooks_external',
'classpath' => 'local/webhooks/externallib.php',
'description' => 'Get data by service.',
'methodname' => 'get_service',
'type' => 'read',
],
'local_webhooks_get_services' => [
'classname' => 'local_webhooks_external',
'classpath' => 'local/webhooks/externallib.php',
'description' => 'Get the service\'s list.',
'methodname' => 'get_services',
'type' => 'read',
],
'local_webhooks_set_service' => [
'classname' => 'local_webhooks_external',
'classpath' => 'local/webhooks/externallib.php',
'description' => 'Update the existing service.',
'methodname' => 'set_service',
'type' => 'write',
],
];
+11 -9
View File
@@ -14,13 +14,15 @@
// 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
*/
defined('MOODLE_INTERNAL') || die();
$string["managerservice"] = "Менеджер управления службами";
$string["pluginname"] = "WebHooks";
/**
* Function to upgrade 'local_webhooks'.
*
* @param int $oldversion
*
* @return bool
*/
function xmldb_local_webhooks_upgrade(int $oldversion) {
return true;
}
-94
View File
@@ -1,94 +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 editor.
*
* @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/forms.php");
$idservice = optional_param("idservice", 0, PARAM_INT);
require_login();
/* Link generation */
$urlparameters = array("idservice" => $idservice);
$managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters);
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
$PAGE->set_url($baseurl, $urlparameters);
/* Configure the context of the page */
$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 */
$mform = new \local_webhooks\service_edit_form($PAGE->url);
/* Cancel processing */
if ($mform->is_cancelled()) {
redirect($managerservice);
}
/* Getting the data */
if ($idediting = boolval($idservice)) {
$servicerecord = $DB->get_record("local_webhooks_service", array("id" => $idservice), "*", MUST_EXIST);
$mform->set_data($servicerecord);
}
/* Processing of received data */
if ($data = $mform->get_data()) {
if (empty($data->enable)) {
$data->enable = 0;
}
/* Packing of data */
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
if ($idediting) {
$data->id = $idservice;
$DB->update_record("local_webhooks_service", $data);
} else {
$DB->insert_record("local_webhooks_service", $data);
}
redirect($managerservice);
}
/* Page template */
$PAGE->set_pagelayout("admin");
$PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
/* The page title */
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
$PAGE->navbar->add(new lang_string("managerservice", "local_webhooks"), $managerservice);
$PAGE->navbar->add($titlepage);
echo $OUTPUT->header();
/* Displays the form */
$mform->display();
echo $OUTPUT->footer();
+366
View File
@@ -0,0 +1,366 @@
<?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/>.
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/classes/local/api.php');
require_once($CFG->libdir . '/externallib.php');
use local_webhooks\local\api;
use local_webhooks\local\record;
/**
* WebHooks external functions.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class local_webhooks_external extends external_api {
/**
* Add a new service.
*
* @param array $conditions
*
* @return int
*
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function add_service(array $conditions): int {
$parameters = self::validate_parameters(self::add_service_parameters(), [
'record' => array_filter($conditions),
]);
$context = context_system::instance();
self::validate_context($context);
$parameters = array_filter($parameters['record']);
$record = new record($parameters);
return api::add_service($record);
}
/**
* Returns description of the method parameters.
*
* @return \external_function_parameters
*/
public static function add_service_parameters(): external_function_parameters {
return new external_function_parameters([
'record' => new external_single_structure([
'events' => new external_multiple_structure(
new external_value(PARAM_RAW, 'The event\'s name.'), 'The service\'s list events.', false
),
'header' => new external_value(PARAM_RAW, 'The request\'s header or type', false, 'application/json'),
'name' => new external_value(PARAM_RAW, 'The service\'s name.'),
'point' => new external_value(PARAM_URL, 'The service\'s endpoint.'),
'status' => new external_value(PARAM_BOOL, 'The service\'s status.', false, true),
'token' => new external_value(PARAM_RAW, 'The service\'s secret key.'),
], 'The new service\'s data.'),
]);
}
/**
* Returns description of the method result value.
*
* @return \external_value
*/
public static function add_service_returns(): external_value {
return new external_value(PARAM_INT, 'The service\'s ID.');
}
/**
* Delete the existing service.
*
* @param int $serviceid
*
* @return bool
*
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function del_service(int $serviceid): bool {
$parameters = self::validate_parameters(self::del_service_parameters(), [
'serviceid' => $serviceid,
]);
$context = context_system::instance();
self::validate_context($context);
return api::del_service($parameters['serviceid']);
}
/**
* Returns description of the method parameters.
*
* @return \external_function_parameters
*/
public static function del_service_parameters(): external_function_parameters {
return new external_function_parameters([
'serviceid' => new external_value(PARAM_INT, 'The service\'s ID.'),
]);
}
/**
* Returns description of the method result value.
*
* @return \external_value
*/
public static function del_service_returns(): external_value {
return new external_value(PARAM_BOOL, 'The result operation.');
}
/**
* Get the event's list.
*
* @return array
*
* @throws \ReflectionException
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function get_events(): array {
$context = context_system::instance();
self::validate_context($context);
return api::get_events();
}
/**
* Returns description of the method parameters.
*
* @return \external_function_parameters
*/
public static function get_events_parameters(): external_function_parameters {
return new external_function_parameters([]);
}
/**
* Returns description of the method result value.
*
* @return \external_multiple_structure
*/
public static function get_events_returns(): external_multiple_structure {
return new external_multiple_structure(
new external_single_structure([
'action' => new external_value(PARAM_ALPHANUMEXT, 'The action name.'),
'component' => new external_value(PARAM_COMPONENT, 'The component name.'),
'crud' => new external_value(PARAM_ALPHA, 'The transaction type.'),
'edulevel' => new external_value(PARAM_INT, 'The level of educational value.'),
'eventname' => new external_value(PARAM_RAW, 'The event name.'),
'objecttable' => new external_value(PARAM_RAW, 'The database table name.'),
'target' => new external_value(PARAM_RAW, 'The target on which the action.'),
], 'The event\'s data.'), 'The event\'s list.'
);
}
/**
* Get data by service.
*
* @param int $serviceid
*
* @return \local_webhooks\local\record
*
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function get_service(int $serviceid): record {
$parameters = self::validate_parameters(self::get_service_parameters(), [
'serviceid' => $serviceid,
]);
$context = context_system::instance();
self::validate_context($context);
return api::get_service($parameters['serviceid']);
}
/**
* Returns description of the method parameters.
*
* @return \external_function_parameters
*/
public static function get_service_parameters(): external_function_parameters {
return new external_function_parameters([
'serviceid' => new external_value(PARAM_INT, 'The service\'s ID.'),
]);
}
/**
* Returns description of the method result value.
*
* @return \external_single_structure
*/
public static function get_service_returns(): external_single_structure {
return new external_single_structure([
'events' => new external_multiple_structure(
new external_value(PARAM_RAW, 'The event\'s name.'), 'The service\'s list events.'
),
'header' => new external_value(PARAM_RAW, 'The request\'s header or type'),
'id' => new external_value(PARAM_INT, 'The service\'s ID.'),
'name' => new external_value(PARAM_RAW, 'The service\'s name.'),
'point' => new external_value(PARAM_URL, 'The service\'s endpoint.'),
'status' => new external_value(PARAM_BOOL, 'The service\'s status.'),
'token' => new external_value(PARAM_RAW, 'The service\'s secret key.'),
], 'The service\'s data.');
}
/**
* Get the service's list.
*
* @param array|null $conditions
* @param string|null $sort
* @param int|null $from
* @param int|null $limit
*
* @return array
*
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function get_services(array $conditions = null, string $sort = null, int $from = null, int $limit = null): array {
$parameters = self::validate_parameters(self::get_services_parameters(), [
'conditions' => $conditions ?? [],
'from' => $from,
'limit' => $limit,
'sort' => $sort,
]);
$context = context_system::instance();
self::validate_context($context);
return api::get_services(
array_filter($parameters['conditions']),
$parameters['sort'],
$parameters['from'],
$parameters['limit']
);
}
/**
* Returns description of the method parameters.
*
* @return \external_function_parameters
*/
public static function get_services_parameters(): external_function_parameters {
return new external_function_parameters([
'conditions' => new external_single_structure([
'header' => new external_value(PARAM_RAW, 'The request\'s header or type', false),
'name' => new external_value(PARAM_RAW, 'The service\'s name.', false),
'point' => new external_value(PARAM_URL, 'The service\'s endpoint.', false),
'status' => new external_value(PARAM_BOOL, 'The service\'s status.', false),
'token' => new external_value(PARAM_RAW, 'The service\'s secret key.', false),
], 'SQL conditions.', false),
'sort' => new external_value(PARAM_RAW, 'SQL sort parameters.', false),
'from' => new external_value(PARAM_INT, 'The start index.', false),
'limit' => new external_value(PARAM_INT, 'The count elements.', false),
]);
}
/**
* Returns description of the method result value.
*
* @return \external_multiple_structure
*/
public static function get_services_returns(): external_multiple_structure {
return new external_multiple_structure(
new external_single_structure([
'events' => new external_multiple_structure(
new external_value(PARAM_RAW, 'The event\'s name.'), 'The service\'s list events.'
),
'header' => new external_value(PARAM_RAW, 'The request\'s header or type'),
'id' => new external_value(PARAM_INT, 'The service\'s ID.'),
'name' => new external_value(PARAM_RAW, 'The service\'s name.'),
'point' => new external_value(PARAM_URL, 'The service\'s endpoint.'),
'status' => new external_value(PARAM_BOOL, 'The service\'s status.'),
'token' => new external_value(PARAM_RAW, 'The service\'s secret key.'),
], 'The service\'s data.'), 'The service\'s list.'
);
}
/**
* Update the existing service.
*
* @param array $conditions
*
* @return bool
*
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public static function set_service(array $conditions): bool {
$conditions = array_filter($conditions);
$conditions['events'] = $conditions['events'] ?? [];
$parameters = self::validate_parameters(self::set_service_parameters(), [
'record' => $conditions,
]);
$context = context_system::instance();
self::validate_context($context);
$parameters = array_filter($parameters['record']);
$record = api::get_service($parameters['id']);
foreach ($parameters as $index => $value) {
if (property_exists($record, $index)) {
$record->$index = $value;
}
}
return api::set_service($record);
}
/**
* Returns description of the method parameters.
*
* @return \external_function_parameters
*/
public static function set_service_parameters(): external_function_parameters {
return new external_function_parameters([
'record' => new external_single_structure([
'events' => new external_multiple_structure(
new external_value(PARAM_RAW, 'The event\'s name.'), 'The service\'s list events.', false
),
'header' => new external_value(PARAM_RAW, 'The request\'s header or type', false),
'id' => new external_value(PARAM_INT, 'The service\'s ID.'),
'name' => new external_value(PARAM_RAW, 'The service\'s name.', false),
'point' => new external_value(PARAM_URL, 'The service\'s endpoint.', false),
'status' => new external_value(PARAM_BOOL, 'The service\'s status.', false),
'token' => new external_value(PARAM_RAW, 'The service\'s secret key.', false),
], 'The new service\'s data.'),
]);
}
/**
* Returns description of the method result value.
*
* @return \external_value
*/
public static function set_service_returns(): external_value {
return new external_value(PARAM_BOOL, 'The result operation.');
}
}
+76
View File
@@ -0,0 +1,76 @@
<?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/>.
require_once(dirname(__DIR__, 2) . '/config.php');
global $CFG;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/local/webhooks/classes/local/api.php');
require_once($CFG->dirroot . '/local/webhooks/classes/output/services_table.php');
require_once($CFG->libdir . '/adminlib.php');
use local_webhooks\local\api;
use local_webhooks\output\services_table;
$deleteid = optional_param('deleteid', 0, PARAM_INT);
$hideshowid = optional_param('hideshowid', 0, PARAM_INT);
$editpage = '/local/webhooks/service.php';
$mainpage = '/local/webhooks/index.php';
$baseurl = new moodle_url($mainpage);
$context = context_system::instance();
admin_externalpage_setup('local_webhooks', '', ['contextid' => $context->contextlevel], $baseurl, []);
// Deleting the existing service.
if ($deleteid !== 0 && confirm_sesskey()) {
api::del_service($deleteid);
redirect($PAGE->url, new lang_string('deleted', 'moodle'));
}
// Setting status to existing service.
if ($hideshowid !== 0 && confirm_sesskey()) {
$service = api::get_service($hideshowid);
$service->status = !filter_var($service->status, FILTER_VALIDATE_BOOLEAN);
api::set_service($service);
redirect($PAGE->url, new lang_string('changessaved', 'moodle'));
}
// Page header.
$titlepage = new lang_string('pluginname', 'local_webhooks');
$PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
echo $OUTPUT->header();
// Adds the add button.
$addserviceurl = new moodle_url($editpage, ['sesskey' => sesskey()]);
echo $OUTPUT->single_button($addserviceurl, new lang_string('add', 'moodle'));
// Separation.
echo html_writer::empty_tag('br');
// Displays the table.
$table = new services_table('local-webhooks-services');
$table->define_baseurl($baseurl);
$table->out(25, true);
// Footer.
echo $OUTPUT->footer();
+4 -5
View File
@@ -15,12 +15,11 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component "local_webhooks", language "en".
* Strings for component 'local_webhooks', language 'en'.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks
*/
$string["managerservice"] = "Service management manager";
$string["pluginname"] = "WebHooks";
$string['pluginname'] = 'WebHooks';
-105
View File
@@ -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();
+82
View File
@@ -0,0 +1,82 @@
<?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/>.
/**
* Page of the service editor.
*
* @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/local/webhooks/classes/ui_forms_plugin.php');
require_once($CFG->dirroot . '/local/webhooks/lib.php');
require_once($CFG->libdir . '/adminlib.php');
$serviceid = optional_param('serviceid', 0, PARAM_INT);
$urlparameters = array('serviceid' => $serviceid);
$baseurl = new moodle_url('/local/webhooks/service.php', $urlparameters);
$mainpage = new moodle_url('/local/webhooks/index.php');
admin_externalpage_setup('local_webhooks', '', null, $baseurl, array());
$context = context_system::instance();
$mform = new local_webhooks_service_edit_form($PAGE->url);
$formdata = (array) $mform->get_data();
/* Cancel */
if ($mform->is_cancelled()) {
redirect($mainpage);
}
/* Updating the data */
if (!empty($formdata) && confirm_sesskey()) {
if (isset($formdata['events'])) {
$formdata['events'] = array_keys($formdata['events']);
}
if (!empty($serviceid)) {
$formdata['id'] = $serviceid;
local_webhooks_api::update_service($formdata);
} else {
local_webhooks_api::create_service($formdata);
}
redirect($mainpage, new lang_string('changessaved', 'moodle'));
}
/* Loading service data */
if (!empty($serviceid)) {
$service = local_webhooks_api::get_service($serviceid);
$service->events = array_fill_keys($service->events, 1);
$mform->set_data($service);
}
/* The page title */
$titlepage = new lang_string('externalservice', 'webservice');
$PAGE->navbar->add($titlepage);
$PAGE->set_heading($titlepage);
$PAGE->set_title($titlepage);
echo $OUTPUT->header();
/* Displays the form */
$mform->display();
/* Footer */
echo $OUTPUT->footer();
+12 -20
View File
@@ -17,29 +17,21 @@
/**
* Settings of the plugin.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @copyright 2018 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package local_webhooks
*/
defined("MOODLE_INTERNAL") || die();
defined('MOODLE_INTERNAL') || die();
/* @var \admin_root $ADMIN */
$settings = null;
if ($hassiteconfig) {
$settings = new admin_settingpage("local_webhooks",
new lang_string("pluginname", "local_webhooks"));
$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)));
$ADMIN->add(
'server', new admin_externalpage(
'local_webhooks',
new lang_string('pluginname', 'local_webhooks'),
new moodle_url('/local/webhooks/index.php')
)
);
}
+364
View File
@@ -0,0 +1,364 @@
<?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/>.
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/classes/local/api.php');
use local_webhooks\local\api;
use local_webhooks\local\record;
/**
* Testing the API plugin class.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class local_webhooks_api_testcase extends advanced_testcase {
/**
* Generate random an event's list.
*
* @return array
*
* @throws \ReflectionException
*/
private static function get_random_events(): array {
$result = array_rand(api::get_events(), random_int(2, 10));
return is_array($result) ? $result : [];
}
/**
* Generate a random record.
*
* @return \local_webhooks\local\record
*
* @throws \ReflectionException
*/
private static function get_random_record(): record {
$record = new record();
$record->events = self::get_random_events();
$record->header = 'application/json';
$record->name = uniqid('', false);
$record->point = 'http://example.org/' . urlencode($record->name);
$record->status = true;
$record->token = generate_uuid();
return $record;
}
/**
* Testing creation of the service.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_adding() {
global $DB;
$this->resetAfterTest();
$record = self::get_random_record();
$record->id = api::add_service($record);
$events = $DB->get_records(LW_TABLE_EVENTS);
$services = $DB->get_records(LW_TABLE_SERVICES);
self::assertCount(1, $services);
$service = array_shift($services);
self::assertEquals($record->header, $service->header);
self::assertEquals($record->id, $service->id);
self::assertEquals($record->name, $service->name);
self::assertEquals($record->point, $service->point);
self::assertEquals($record->status, (bool) $service->status);
self::assertEquals($record->token, $service->token);
self::assertCount(count($record->events), $events);
foreach ($events as $event) {
self::assertContains($event->name, $record->events);
self::assertEquals($record->id, $event->serviceid);
}
}
/**
* Test deletion of the service.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_deleting() {
global $DB;
$this->resetAfterTest();
// Testing correct delete record of the database.
$record = self::get_random_record();
$record->id = api::add_service($record);
self::assertTrue(api::del_service($record->id));
self::assertCount(0, $DB->get_records(LW_TABLE_EVENTS));
self::assertCount(0, $DB->get_records(LW_TABLE_SERVICES));
$ids = [];
$total = random_int(5, 20);
// Testing correct delete record of the record's list.
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$ids[] = api::add_service($record);
}
self::assertEquals(count($ids), api::get_total_count());
self::assertTrue(api::del_service($ids[array_rand($ids, 1)]));
self::assertEquals(count($ids) - 1, api::get_total_count());
}
/**
* Testing get an event's list.
*
* @group local_webhooks
*
* @throws \ReflectionException
*/
public function test_get_events() {
$this->resetAfterTest();
$events = api::get_events();
self::assertNotCount(0, $events);
foreach ($events as $event) {
self::assertInternalType('array', $event);
self::assertEquals([
'eventname', 'component', 'target', 'action', 'crud', 'edulevel', 'objecttable',
], array_keys($event));
}
}
/**
* Testing get to a service.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_get_service() {
$this->resetAfterTest();
$record = self::get_random_record();
$record->id = api::add_service($record);
$service = api::get_service($record->id);
self::assertEquals($record->header, $service->header);
self::assertEquals($record->id, $service->id);
self::assertEquals($record->name, $service->name);
self::assertEquals($record->point, $service->point);
self::assertEquals($record->status, (bool) $service->status);
self::assertEquals($record->token, $service->token);
self::assertInternalType('array', $service->events);
self::assertCount(count($record->events), $service->events);
foreach ($service->events as $event) {
self::assertContains($event, $record->events);
}
}
/**
* Testing get to the list services.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_get_services() {
$this->resetAfterTest();
$records = [];
$total = random_int(5, 20);
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$record->id = api::add_service($record);
$records[$record->id] = $record;
}
$services = api::get_services();
self::assertCount(count($records), $services);
foreach ($services as $service) {
$record = $records[$service->id];
self::assertEquals($record->header, $service->header);
self::assertEquals($record->id, $service->id);
self::assertEquals($record->name, $service->name);
self::assertEquals($record->point, $service->point);
self::assertEquals($record->status, $service->status);
self::assertEquals($record->token, $service->token);
self::assertInternalType('array', $service->events);
self::assertCount(count($record->events), $service->events);
foreach ($service->events as $event) {
self::assertContains($event, $record->events);
}
}
}
/**
* Testing get to the list services by event name.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_get_services_by_event() {
$this->resetAfterTest();
$eventname = generate_uuid();
$limit = random_int(1, 5);
$total = random_int(5, 20);
$ids = [];
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$record->events[] = $i < $limit ? $eventname : '';
$ids[] = api::add_service($record);
}
self::assertEquals(count($ids), api::get_total_count());
$services = api::get_services_by_event($eventname);
self::assertCount($limit, $services);
foreach ($services as $service) {
self::assertContains($service->id, $ids);
}
}
/**
* Testing get to the list services with conditions.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_get_services_with_conditions() {
$this->resetAfterTest();
$records = [];
$total = random_int(5, 20);
$limit = intdiv($total, 2);
// Creating some records.
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$record->id = api::add_service($record);
$records[] = $record;
}
// Testing condition fields.
$record = $records[array_rand($records, 1)];
self::assertCount(1, api::get_services([
'point' => $record->point,
]));
// Testing limit fields.
self::assertCount($limit, api::get_services([], null, 1, $limit));
// Testing sort fields.
$service1 = api::get_services(null, 'id asc')[0];
$service2 = api::get_services(null, 'id desc')[0];
self::assertNotEquals($service1->id, $service2->id);
}
/**
* Testing get a total count of existing records.
*
* @throws \coding_exception
* @throws \dml_exception
* @throws \ReflectionException
*/
public function test_total() {
$this->resetAfterTest();
$total = random_int(5, 20);
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
api::add_service($record);
}
self::assertEquals($total, api::get_total_count());
}
/**
* Testing of the service update.
*
* @group local_webhooks
*
* @throws \dml_exception
* @throws \moodle_exception
* @throws \ReflectionException
*/
public function test_updating() {
global $DB;
$this->resetAfterTest();
$record1 = self::get_random_record();
$record2 = self::get_random_record();
$record2->id = api::add_service($record1);
self::assertTrue(api::set_service($record2));
$events = $DB->get_records(LW_TABLE_EVENTS);
$services = $DB->get_records(LW_TABLE_SERVICES);
self::assertCount(1, $services);
$service = array_shift($services);
self::assertEquals($record2->header, $service->header);
self::assertEquals($record2->id, $service->id);
self::assertEquals($record2->name, $service->name);
self::assertEquals($record2->point, $service->point);
self::assertEquals($record2->status, (bool) $service->status);
self::assertEquals($record2->token, $service->token);
self::assertCount(count($record2->events), $events);
foreach ($events as $event) {
self::assertContains($event->name, $record2->events);
self::assertEquals($record2->id, $event->serviceid);
}
}
}
+386
View File
@@ -0,0 +1,386 @@
<?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/>.
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/externallib.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use local_webhooks\local\api;
use local_webhooks\local\record;
/**
* Testing external functions.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class local_webhooks_external_testcase extends externallib_advanced_testcase {
/**
* Generate random an event's list.
*
* @return array
*
* @throws \ReflectionException
*/
private static function get_random_events(): array {
$result = array_rand(api::get_events(), random_int(2, 10));
return is_array($result) ? $result : [];
}
/**
* Generate a random record.
*
* @return \local_webhooks\local\record
*
* @throws \ReflectionException
*/
private static function get_random_record(): record {
$record = new record();
$record->events = self::get_random_events();
$record->header = 'application/json';
$record->name = uniqid('', false);
$record->point = 'http://example.org/' . urlencode($record->name);
$record->status = true;
$record->token = generate_uuid();
return $record;
}
/**
* Testing external add service.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
public function test_adding() {
$this->resetAfterTest();
self::setAdminUser();
$record = self::get_random_record();
$return = local_webhooks_external::add_service((array) $record);
$return = external_api::clean_returnvalue(local_webhooks_external::add_service_returns(), $return);
self::assertInternalType('integer', $return);
self::assertEquals(1, api::get_total_count());
$service = api::get_service($return);
self::assertEquals($record->header, $service->header);
self::assertEquals($record->name, $service->name);
self::assertEquals($record->point, $service->point);
self::assertEquals($record->status, $service->status);
self::assertEquals($record->token, $service->token);
self::assertEquals($return, $service->id);
self::assertInternalType('array', $service->events);
self::assertCount(count($record->events), $service->events);
foreach ($service->events as $event) {
self::assertContains($event, $record->events);
}
}
/**
* Testing the external delete service.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
public function test_deleting() {
$this->resetAfterTest();
self::setAdminUser();
// Testing correct delete record of the database.
$record = self::get_random_record();
$record->id = api::add_service($record);
$return = local_webhooks_external::del_service($record->id);
$return = external_api::clean_returnvalue(local_webhooks_external::del_service_returns(), $return);
self::assertEquals(0, api::get_total_count());
self::assertInternalType('bool', $return);
$ids = [];
$total = random_int(5, 20);
// Testing correct delete record of the record's list.
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$ids[] = api::add_service($record);
}
self::assertEquals(count($ids), api::get_total_count());
$return = local_webhooks_external::del_service($ids[array_rand($ids, 1)]);
$return = external_api::clean_returnvalue(local_webhooks_external::del_service_returns(), $return);
self::assertEquals(count($ids) - 1, api::get_total_count());
self::assertInternalType('bool', $return);
}
/**
* Testing external function get the event's list.
*
* @throws \ReflectionException
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
public function test_get_events() {
$this->resetAfterTest();
self::setAdminUser();
$return = local_webhooks_external::get_events();
$return = external_api::clean_returnvalue(local_webhooks_external::get_events_returns(), $return);
self::assertInternalType('array', $return);
self::assertCount(count(api::get_events()), $return);
foreach ($return as $item) {
self::assertInternalType('array', $item);
self::assertEquals([
'action', 'component', 'crud', 'edulevel', 'eventname', 'objecttable', 'target',
], array_keys($item));
}
}
/**
* Testing external get record's data.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
public function test_get_service() {
$this->resetAfterTest();
self::setAdminUser();
// Creating a new record.
$record = self::get_random_record();
$record->id = api::add_service($record);
$return = local_webhooks_external::get_service($record->id);
$return = external_api::clean_returnvalue(local_webhooks_external::get_service_returns(), $return);
self::assertInternalType('array', $return);
// Testing the main fields.
self::assertEquals($record->header, $return['header']);
self::assertEquals($record->id, $return['id']);
self::assertEquals($record->name, $return['name']);
self::assertEquals($record->point, $return['point']);
self::assertEquals($record->status, (int) $return['status']);
self::assertEquals($record->token, $return['token']);
// Testing an event's list.
self::assertInternalType('array', $return['events']);
self::assertNotCount(0, $return['events']);
foreach ($return['events'] as $event) {
self::assertContains($event, $record->events);
}
}
/**
* Testing external get the record's list.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
public function test_get_services() {
$this->resetAfterTest();
self::setAdminUser();
$records = [];
$total = random_int(5, 10);
// Creating some records.
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$record->id = api::add_service($record);
$records[$record->id] = $record;
}
self::assertEquals(count($records), api::get_total_count());
$return = local_webhooks_external::get_services();
$return = external_api::clean_returnvalue(local_webhooks_external::get_services_returns(), $return);
// Testing received item's list.
self::assertInternalType('array', $return);
self::assertCount(count($records), $return);
foreach ($return as $item) {
self::assertInternalType('array', $item);
$record = $records[$item['id']];
self::assertEquals($record->header, $item['header']);
self::assertEquals($record->id, $item['id']);
self::assertEquals($record->name, $item['name']);
self::assertEquals($record->point, $item['point']);
self::assertEquals($record->status, (int) $item['status']);
self::assertEquals($record->token, $item['token']);
self::assertInternalType('array', $item['events']);
self::assertNotCount(0, $item['events']);
foreach ($item['events'] as $event) {
self::assertContains($event, $record->events);
}
}
}
/**
* Testing external get to the list services with conditions.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \invalid_response_exception
* @throws \restricted_context_exception
*/
public function test_get_services_with_conditions() {
$this->resetAfterTest();
self::setAdminUser();
$records = [];
$total = random_int(5, 10);
$limit = intdiv($total, 2);
// Creating some records.
for ($i = 0; $i < $total; $i++) {
$record = self::get_random_record();
$record->id = api::add_service($record);
$records[$record->id] = $record;
}
self::assertEquals(count($records), api::get_total_count());
// Testing condition fields.
$record = $records[array_rand($records, 1)];
$return = local_webhooks_external::get_services(['point' => $record->point]);
$return = external_api::clean_returnvalue(local_webhooks_external::get_services_returns(), $return);
self::assertCount(1, $return);
self::assertEquals($return[0]['id'], $record->id);
// Testing limit fields.
$return = local_webhooks_external::get_services(null, null, 1, $limit);
$return = external_api::clean_returnvalue(local_webhooks_external::get_services_returns(), $return);
self::assertCount($limit, $return);
// Testing sort fields.
$return = local_webhooks_external::get_services(null, 'id asc');
$return = external_api::clean_returnvalue(local_webhooks_external::get_services_returns(), $return);
$service1 = array_shift($return);
$return = local_webhooks_external::get_services(null, 'id desc');
$return = external_api::clean_returnvalue(local_webhooks_external::get_services_returns(), $return);
$service2 = array_shift($return);
self::assertNotEquals($service1['id'], $service2['id']);
}
/**
* Testing full update parameters of the service.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public function test_updating_full() {
$this->resetAfterTest();
self::setAdminUser();
$record = self::get_random_record();
$record2 = self::get_random_record();
$record2->id = api::add_service($record);
$return = local_webhooks_external::set_service((array) $record2);
$return = external_api::validate_parameters(local_webhooks_external::set_service_returns(), $return);
self::assertInternalType('bool', $return);
$service = api::get_service($record2->id);
self::assertEquals($record2->id, $service->id);
self::assertEquals($record2->header, $service->header);
self::assertEquals($record2->name, $service->name);
self::assertEquals($record2->point, $service->point);
self::assertEquals($record2->status, $service->status);
self::assertEquals($record2->token, $service->token);
self::assertInternalType('array', $service->events);
self::assertCount(count($record2->events), $service->events);
foreach ($service->events as $event) {
self::assertContains($event, $record2->events);
}
}
/**
* Testing selective update parameters of the service.
*
* @throws \ReflectionException
* @throws \coding_exception
* @throws \dml_exception
* @throws \invalid_parameter_exception
* @throws \restricted_context_exception
*/
public function test_updating_short() {
$this->resetAfterTest();
self::setAdminUser();
$record = self::get_random_record();
$record2 = self::get_random_record();
$record->id = api::add_service($record);
$return = local_webhooks_external::set_service(['id' => $record->id, 'name' => $record2->name, 'point' => $record2->point]);
$return = external_api::validate_parameters(local_webhooks_external::set_service_returns(), $return);
self::assertInternalType('bool', $return);
$service = api::get_service($record->id);
self::assertEquals($record->header, $service->header);
self::assertEquals($record->id, $service->id);
self::assertEquals($record->status, $service->status);
self::assertEquals($record->token, $service->token);
self::assertEquals($record2->name, $service->name);
self::assertEquals($record2->point, $service->point);
self::assertInternalType('array', $service->events);
self::assertCount(count($record->events), $service->events);
foreach ($service->events as $event) {
self::assertContains($event, $record->events);
}
}
}
+205
View File
@@ -0,0 +1,205 @@
<?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/>.
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/local/webhooks/classes/local/api.php');
use core\event\course_created;
use core\task\manager;
use local_webhooks\local\api;
use local_webhooks\local\record;
use local_webhooks\task\notify;
/**
* Class local_webhooks_task_testcase.
*
* @copyright 2019 'Valentin Popov' <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class local_webhooks_task_testcase extends advanced_testcase {
const EVENTNAME = '\\' . course_created::class;
/**
* Generate a random record.
*
* @return \local_webhooks\local\record
*/
private static function get_random_record(): record {
$record = new record();
$record->events = [self::EVENTNAME];
$record->header = 'application/json';
$record->name = uniqid('', false);
$record->point = 'http://example.org/' . urlencode($record->name);
$record->status = true;
$record->token = generate_uuid();
return $record;
}
/**
* Testing add a task to the queue.
*/
public function test_add_task() {
global $DB;
$DB->delete_records('task_adhoc');
$this->resetAfterTest();
manager::queue_adhoc_task(new notify());
$tasks = manager::get_adhoc_tasks(notify::class);
self::assertCount(1, $tasks);
self::assertInstanceOf(notify::class, array_shift($tasks));
}
/**
* Testing disabled processing service.
*
* @throws \coding_exception
* @throws \dml_exception
*/
public function test_execute_disabled() {
global $DB;
$DB->delete_records('task_adhoc');
curl::mock_response('{}');
$this->resetAfterTest();
$record = self::get_random_record();
$record->status = false;
$record->id = api::add_service($record);
$task = new notify();
$task->set_custom_data(['eventname' => self::EVENTNAME]);
$task->execute();
self::assertNull($task->debug);
}
/**
* Testing enabled processing service.
*
* @throws \coding_exception
* @throws \dml_exception
*/
public function test_execute_enabled() {
global $DB;
$DB->delete_records('task_adhoc');
curl::mock_response('{}');
$this->resetAfterTest();
$record = self::get_random_record();
$record->id = api::add_service($record);
$task = new notify();
$task->set_custom_data(['eventname' => self::EVENTNAME]);
$task->execute();
self::assertCount(1, $task->debug);
self::assertInternalType('array', $task->debug);
$element = array_shift($task->debug);
self::assertInternalType('array', $element['data']);
self::assertInternalType('object', $element['service']);
self::assertEquals($record->events[0], $element['data']['eventname']);
self::assertEquals($record->id, $element['service']->id);
self::assertEquals($record->token, $element['data']['token']);
}
/**
* Testing count creating tasks.
*
* @throws \coding_exception
* @throws \dml_exception
*/
public function test_observer_multiple() {
global $DB;
$DB->delete_records('task_adhoc');
curl::mock_response('{}');
$this->resetAfterTest();
$generator = self::getDataGenerator();
$record = self::get_random_record();
$record->id = api::add_service($record);
$total = random_int(5, 20);
for ($i = 0; $i < $total; $i++) {
$generator->create_course();
}
$debug = [];
foreach (manager::get_adhoc_tasks(notify::class) as $event) {
self::assertInstanceOf(notify::class, $event);
/** @var \local_webhooks\task\notify $event */
$event->execute();
if (isset($event->debug) && is_array($event->debug)) {
$debug[] = array_merge(...$event->debug);
}
}
self::assertCount($total, $debug);
}
/**
* Testing structure a creating task.
*
* @throws \coding_exception
* @throws \dml_exception
*/
public function test_observer_single() {
global $DB;
$DB->delete_records('task_adhoc');
curl::mock_response('{}');
$this->resetAfterTest();
$generator = self::getDataGenerator();
$record = self::get_random_record();
$record->id = api::add_service($record);
$course = $generator->create_course();
$debug = [];
foreach (manager::get_adhoc_tasks(notify::class) as $event) {
self::assertInstanceOf(notify::class, $event);
/** @var \local_webhooks\task\notify $event */
$event->execute();
if (isset($event->debug) && is_array($event->debug)) {
$debug[] = array_merge(...$event->debug);
}
}
self::assertCount(1, $debug);
$element = array_shift($debug);
self::assertInternalType('array', $element['data']);
self::assertEquals($course->id, $element['data']['courseid']);
}
}
+6 -13
View File
@@ -14,17 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Information about the version of the plugin.
*
* @package local_webhooks
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
defined("MOODLE_INTERNAL") || die();
$plugin->release = "0.2.0 (Build: 2017102600)";
$plugin->version = 2017102600;
$plugin->requires = 2016112900;
$plugin->component = "local_webhooks";
$plugin->maturity = MATURITY_BETA;
$plugin->component = 'local_webhooks';
$plugin->maturity = MATURITY_ALPHA;
$plugin->release = '5.0.0-rc.1 (Build: 2019040100)';
$plugin->requires = 2016052300;
$plugin->version = 2019040100;