Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4d105c018 | ||
|
|
3ea8f29329 | ||
|
|
c1077bc9c1 | ||
|
|
bc02d0dce2 | ||
|
|
93d788f046 | ||
|
|
29c12fa971 | ||
|
|
1e8cbe7f09 | ||
|
|
ad07800be9 | ||
|
|
f28b408b1e | ||
|
|
91fd140bd4 | ||
|
|
463aeaf043 | ||
|
|
97140dccf7 | ||
|
|
bf2cef3ea0 | ||
|
|
7b56375c05 | ||
|
|
b61e5a08be | ||
|
|
4a470056a7 | ||
|
|
688448b350 | ||
|
|
35358ea7cc | ||
|
|
97296b795a | ||
|
|
0fcec2738d |
+36
-4
@@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines the form of editing the service.
|
||||
* Defines forms.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
@@ -28,9 +28,9 @@ defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
require_once($CFG->libdir . "/formslib.php");
|
||||
|
||||
use report_eventlist_list_generator;
|
||||
use lang_string;
|
||||
use moodleform;
|
||||
use report_eventlist_list_generator;
|
||||
|
||||
/**
|
||||
* Description editing form definition.
|
||||
@@ -64,7 +64,7 @@ class service_edit_form extends moodleform {
|
||||
*/
|
||||
protected function definition() {
|
||||
$mform =& $this->_form;
|
||||
$size = array("size" => 60);
|
||||
$size = array("size" => 60);
|
||||
|
||||
/* Form heading */
|
||||
$mform->addElement("header", "editserviceheader", new lang_string("service", "webservice"));
|
||||
@@ -104,7 +104,7 @@ class service_edit_form extends moodleform {
|
||||
|
||||
/* List of events */
|
||||
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
||||
$events = array();
|
||||
$events = array();
|
||||
|
||||
/* Formation of the list of elements */
|
||||
foreach ($eventlist as $event) {
|
||||
@@ -119,4 +119,36 @@ class service_edit_form extends moodleform {
|
||||
/* Control Panel */
|
||||
$this->add_action_buttons(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the form of restoration.
|
||||
*
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class service_backup_form extends moodleform {
|
||||
/**
|
||||
* @param string $baseurl
|
||||
*/
|
||||
public function __construct($baseurl) {
|
||||
parent::__construct($baseurl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the standard structure of the form.
|
||||
*/
|
||||
protected function definition() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
/* Form heading */
|
||||
$mform->addElement("header", "editserviceheader", new lang_string("restore", "moodle"));
|
||||
|
||||
/* Download the file */
|
||||
$mform->addElement("filepicker", "backupfile", new lang_string("file", "moodle"));
|
||||
$mform->addRule("backupfile", null, "required");
|
||||
|
||||
/* Control Panel */
|
||||
$this->add_action_buttons(true, new lang_string("restore", "moodle"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Registration of the system of events.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace local_webhooks\event;
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
/**
|
||||
* Defines how to work with events.
|
||||
*
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_performed extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data["crud"] = "c";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
$this->data["objecttable"] = "local_webhooks_service";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string("create", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string("backup", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/local/webhooks/managerservice.php");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Registration of the system of events.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace local_webhooks\event;
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
/**
|
||||
* Defines how to work with events.
|
||||
*
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backup_restored extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data["crud"] = "u";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
$this->data["objecttable"] = "local_webhooks_service";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string("update", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string("backupfinished", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/local/webhooks/managerservice.php");
|
||||
}
|
||||
}
|
||||
@@ -32,14 +32,14 @@ defined("MOODLE_INTERNAL") || die();
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class response_get extends \core\event\base {
|
||||
class response_answer extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data["crud"] = "u";
|
||||
$this->data["crud"] = "r";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
$this->data["objecttable"] = "local_webhooks_service";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Registration of the system of events.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace local_webhooks\event;
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
/**
|
||||
* Defines how to work with events.
|
||||
*
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class service_added extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data["crud"] = "c";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
$this->data["objecttable"] = "local_webhooks_service";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string("create", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string("eventwebserviceservicecreated", "webservice");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Registration of the system of events.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace local_webhooks\event;
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
/**
|
||||
* Defines how to work with events.
|
||||
*
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class service_deleted extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data["crud"] = "d";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
$this->data["objecttable"] = "local_webhooks_service";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string("deleted", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string("eventwebserviceservicedeleted", "webservice");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Registration of the system of events.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace local_webhooks\event;
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
/**
|
||||
* Defines how to work with events.
|
||||
*
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class service_updated extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data["crud"] = "u";
|
||||
$this->data["edulevel"] = self::LEVEL_OTHER;
|
||||
$this->data["objecttable"] = "local_webhooks_service";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*/
|
||||
public static function get_name() {
|
||||
return new \lang_string("update", "moodle");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*/
|
||||
public function get_description() {
|
||||
return new \lang_string("eventwebserviceserviceupdated", "webservice");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/local/webhooks/editservice.php", array("serviceid" => $this->objectid));
|
||||
}
|
||||
}
|
||||
+13
-11
@@ -41,12 +41,8 @@ class handler {
|
||||
* @param object $event
|
||||
*/
|
||||
public static function events($event) {
|
||||
$enable = get_config("local_webhooks", "enable");
|
||||
|
||||
if (boolval($enable)) {
|
||||
$data = $event->get_data();
|
||||
self::transmitter($data);
|
||||
}
|
||||
$data = $event->get_data();
|
||||
self::transmitter($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +71,8 @@ class handler {
|
||||
* @param object $callback
|
||||
*/
|
||||
private static function handler_callback($data, $callback) {
|
||||
global $CFG;
|
||||
|
||||
if (boolval($callback->enable)) {
|
||||
$events = array();
|
||||
if (!empty($callback->events)) {
|
||||
@@ -82,6 +80,9 @@ class handler {
|
||||
}
|
||||
|
||||
if (!empty($events[$data["eventname"]])) {
|
||||
$urlparse = parse_url($CFG->wwwroot);
|
||||
$data["host"] = $urlparse['host'];
|
||||
|
||||
if (!empty($callback->token)) {
|
||||
$data["token"] = $callback->token;
|
||||
}
|
||||
@@ -122,14 +123,15 @@ class handler {
|
||||
$status = $response["HTTP/1.1"];
|
||||
}
|
||||
|
||||
$event = \local_webhooks\event\response_get::create(
|
||||
$event = \local_webhooks\event\response_answer::create(
|
||||
array(
|
||||
"context" => \context_system::instance(0),
|
||||
"context" => \context_system::instance(0),
|
||||
"objectid" => $callback->id,
|
||||
"other" => array(
|
||||
"status" => $status
|
||||
"other" => array(
|
||||
"status" => $status
|
||||
)
|
||||
)
|
||||
));
|
||||
);
|
||||
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
+4
-4
@@ -26,10 +26,10 @@ defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
$observers = array(
|
||||
array(
|
||||
"eventname" => "*",
|
||||
"callback" => "\local_webhooks\\handler::events",
|
||||
"callback" => "\local_webhooks\\handler::events",
|
||||
"eventname" => "*",
|
||||
"includefile" => null,
|
||||
"priority" => 200,
|
||||
"internal" => true
|
||||
"internal" => true,
|
||||
"priority" => 200
|
||||
)
|
||||
);
|
||||
+21
-11
@@ -26,16 +26,15 @@ require_once(__DIR__ . "/../../config.php");
|
||||
require_once(__DIR__ . "/classes/editform.php");
|
||||
require_once($CFG->libdir . "/adminlib.php");
|
||||
|
||||
admin_externalpage_setup("managelocalplugins");
|
||||
admin_externalpage_setup("local_webhooks");
|
||||
|
||||
/* Optional parameters */
|
||||
$serviceid = optional_param("serviceid", 0, PARAM_INT);
|
||||
|
||||
require_login();
|
||||
|
||||
/* Link generation */
|
||||
$urlparameters = array("serviceid" => $serviceid);
|
||||
$urlparameters = array("serviceid" => $serviceid);
|
||||
$managerservice = new moodle_url("/local/webhooks/managerservice.php", $urlparameters);
|
||||
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
|
||||
$baseurl = new moodle_url("/local/webhooks/editservice.php", $urlparameters);
|
||||
$PAGE->set_url($baseurl, $urlparameters);
|
||||
|
||||
/* Configure the context of the page */
|
||||
@@ -43,7 +42,7 @@ $context = context_system::instance();
|
||||
$PAGE->set_context($context);
|
||||
|
||||
/* Preparing a template for data */
|
||||
$titlepage = new lang_string("externalservice", "webservice");
|
||||
$titlepage = new lang_string("externalservice", "webservice");
|
||||
$servicerecord = new stdClass;
|
||||
|
||||
/* Create an editing form */
|
||||
@@ -62,16 +61,29 @@ if ($editing = boolval($serviceid)) {
|
||||
|
||||
/* Processing of received data */
|
||||
if ($data = $mform->get_data()) {
|
||||
if (!empty($data->events)) {
|
||||
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
|
||||
if (empty($data->events)) {
|
||||
$data->events = array();
|
||||
}
|
||||
|
||||
/* Pack the list of events */
|
||||
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
|
||||
|
||||
if ($editing) {
|
||||
$data->id = $serviceid;
|
||||
$DB->update_record("local_webhooks_service", $data);
|
||||
|
||||
/* Run the event */
|
||||
$event = \local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $data->id));
|
||||
$event->trigger();
|
||||
|
||||
redirect($managerservice, new lang_string("eventwebserviceserviceupdated", "webservice"));
|
||||
} else {
|
||||
$DB->insert_record("local_webhooks_service", $data);
|
||||
$servicenewid = $DB->insert_record("local_webhooks_service", $data);
|
||||
|
||||
/* Run the event */
|
||||
$event = \local_webhooks\event\service_added::create(array("context" => $context, "objectid" => $servicenewid));
|
||||
$event->trigger();
|
||||
|
||||
redirect($managerservice, new lang_string("eventwebserviceservicecreated", "webservice"));
|
||||
}
|
||||
}
|
||||
@@ -82,8 +94,6 @@ $PAGE->set_heading($titlepage);
|
||||
$PAGE->set_title($titlepage);
|
||||
|
||||
/* The page title */
|
||||
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"), new moodle_url("/admin/settings.php", array("section" => "local_webhooks")));
|
||||
$PAGE->navbar->add(new lang_string("externalservices", "webservice"), $managerservice);
|
||||
$PAGE->navbar->add($titlepage);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
|
||||
+45
-14
@@ -26,16 +26,19 @@ require_once(__DIR__ . "/../../config.php");
|
||||
require_once($CFG->libdir . "/tablelib.php");
|
||||
require_once($CFG->libdir . "/adminlib.php");
|
||||
|
||||
admin_externalpage_setup("managelocalplugins");
|
||||
admin_externalpage_setup("local_webhooks");
|
||||
|
||||
$hideshowid = optional_param("hideshowid", 0, PARAM_INT);
|
||||
$deleteid = optional_param("deleteid", 0, PARAM_INT);
|
||||
/* Optional parameters */
|
||||
$backupservices = optional_param("getbackup", 0, PARAM_BOOL);
|
||||
$deleteid = optional_param("deleteid", 0, PARAM_INT);
|
||||
$hideshowid = optional_param("hideshowid", 0, PARAM_INT);
|
||||
|
||||
require_login();
|
||||
/* Used references */
|
||||
$editservice = "/local/webhooks/editservice.php";
|
||||
$managerservice = "/local/webhooks/managerservice.php";
|
||||
$restorebackup = "/local/webhooks/restorebackup.php";
|
||||
|
||||
/* Link generation */
|
||||
$managerservice = "/local/webhooks/managerservice.php";
|
||||
$editservice = "/local/webhooks/editservice.php";
|
||||
$baseurl = new moodle_url($managerservice);
|
||||
$PAGE->set_url($baseurl);
|
||||
|
||||
@@ -46,12 +49,29 @@ $PAGE->set_context($context);
|
||||
/* Delete the service */
|
||||
if (boolval($deleteid) && confirm_sesskey()) {
|
||||
$DB->delete_records("local_webhooks_service", array("id" => $deleteid));
|
||||
|
||||
/* Run the event */
|
||||
$event = \local_webhooks\event\service_deleted::create(array("context" => $context, "objectid" => $deleteid));
|
||||
$event->trigger();
|
||||
|
||||
redirect($PAGE->url, new lang_string("eventwebserviceservicedeleted", "webservice"));
|
||||
}
|
||||
|
||||
/* Retrieving a list of services */
|
||||
$callbacks = $DB->get_records_select("local_webhooks_service", null, null, $DB->sql_order_by_text("id"));
|
||||
|
||||
/* Upload settings as a file */
|
||||
if (boolval($backupservices)) {
|
||||
$filecontent = base64_encode(gzcompress(serialize($callbacks), 9));
|
||||
$filename = "webhooks_" . date("U") . ".backup";
|
||||
|
||||
/* Run the event */
|
||||
$event = \local_webhooks\event\backup_performed::create(array("context" => $context, "objectid" => 0));
|
||||
$event->trigger();
|
||||
|
||||
send_file($filecontent, $filename, 0, 0, true, true);
|
||||
}
|
||||
|
||||
/* Switching the status of the service */
|
||||
if (boolval($hideshowid) && confirm_sesskey()) {
|
||||
$callback = $callbacks[$hideshowid];
|
||||
@@ -59,19 +79,22 @@ if (boolval($hideshowid) && confirm_sesskey()) {
|
||||
if (!empty($callback)) {
|
||||
$callback->enable = !boolval($callback->enable);
|
||||
$DB->update_record("local_webhooks_service", $callback);
|
||||
|
||||
/* Run the event */
|
||||
$event = \local_webhooks\event\service_updated::create(array("context" => $context, "objectid" => $hideshowid));
|
||||
$event->trigger();
|
||||
|
||||
redirect($PAGE->url, new lang_string("eventwebserviceserviceupdated", "webservice"));
|
||||
}
|
||||
}
|
||||
|
||||
/* Page template */
|
||||
$titlepage = new lang_string("externalservices", "webservice");
|
||||
$titlepage = new lang_string("pluginname", "local_webhooks");
|
||||
$PAGE->set_pagelayout("admin");
|
||||
$PAGE->set_title($titlepage);
|
||||
$PAGE->set_heading($titlepage);
|
||||
|
||||
/* The page title */
|
||||
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"), new moodle_url("/admin/settings.php", array("section" => "local_webhooks")));
|
||||
$PAGE->navbar->add($titlepage, $baseurl);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/* Table declaration */
|
||||
@@ -86,13 +109,13 @@ $table->setup();
|
||||
foreach ($callbacks as $callback) {
|
||||
/* Filling of information columns */
|
||||
$titlecallback = html_writer::div($callback->title, "title");
|
||||
$urlcallback = html_writer::div($callback->url, "url");
|
||||
$urlcallback = html_writer::div($callback->url, "url");
|
||||
|
||||
/* Defining service status */
|
||||
$hideshowicon = "t/show";
|
||||
$hideshowicon = "t/show";
|
||||
$hideshowstring = new lang_string("enable", "moodle");
|
||||
if (boolval($callback->enable)) {
|
||||
$hideshowicon = "t/hide";
|
||||
$hideshowicon = "t/hide";
|
||||
$hideshowstring = new lang_string("disable", "moodle");
|
||||
}
|
||||
|
||||
@@ -116,7 +139,15 @@ foreach ($callbacks as $callback) {
|
||||
$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");
|
||||
$addserviceurl = new moodle_url($editservice);
|
||||
echo $OUTPUT->single_button($addserviceurl, new lang_string("addaservice", "webservice"), "get");
|
||||
|
||||
/* Button to get a backup */
|
||||
$backupurl = new moodle_url($managerservice, array("getbackup" => true));
|
||||
echo $OUTPUT->single_button($backupurl, new lang_string("backup", "moodle"), "get");
|
||||
|
||||
/* Button for restoring settings */
|
||||
$restorebackupurl = new moodle_url($restorebackup, array("sesskey" => sesskey()));
|
||||
echo $OUTPUT->single_button($restorebackupurl, new lang_string("restore", "moodle"), "get");
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Restore settings page.
|
||||
*
|
||||
* @package local_webhooks
|
||||
* @copyright 2017 "Valentin Popov" <info@valentineus.link>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . "/../../config.php");
|
||||
require_once(__DIR__ . "/classes/editform.php");
|
||||
require_once($CFG->libdir . "/adminlib.php");
|
||||
|
||||
admin_externalpage_setup("local_webhooks");
|
||||
|
||||
/* Link generation */
|
||||
$managerservice = new moodle_url("/local/webhooks/managerservice.php");
|
||||
$baseurl = new moodle_url("/local/webhooks/restorebackup.php");
|
||||
$PAGE->set_url($baseurl);
|
||||
|
||||
/* Configure the context of the page */
|
||||
$context = context_system::instance();
|
||||
$PAGE->set_context($context);
|
||||
|
||||
/* Create an editing form */
|
||||
$mform = new \local_webhooks\service_backup_form($PAGE->url);
|
||||
|
||||
/* Cancel processing */
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($managerservice);
|
||||
}
|
||||
|
||||
/* Processing the received file */
|
||||
$data = $mform->get_data();
|
||||
if (boolval($data) && confirm_sesskey()) {
|
||||
$content = $mform->get_file_content("backupfile");
|
||||
$callbacks = unserialize(gzuncompress(base64_decode($content)));
|
||||
|
||||
$DB->delete_records("local_webhooks_service");
|
||||
foreach ($callbacks as $callback) {
|
||||
$DB->insert_record("local_webhooks_service", $callback);
|
||||
}
|
||||
|
||||
/* Run the event */
|
||||
$event = \local_webhooks\event\backup_restored::create(array("context" => $context, "objectid" => 0));
|
||||
$event->trigger();
|
||||
|
||||
redirect($managerservice, new lang_string("restorefinished", "moodle"));
|
||||
}
|
||||
|
||||
/* Page template */
|
||||
$titlepage = new lang_string("backup", "moodle");
|
||||
$PAGE->set_pagelayout("admin");
|
||||
$PAGE->set_heading($titlepage);
|
||||
$PAGE->set_title($titlepage);
|
||||
|
||||
/* The page title */
|
||||
$PAGE->navbar->add($titlepage);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/* Displays the form */
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
+4
-11
@@ -24,16 +24,9 @@
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
$settings = null;
|
||||
if ($hassiteconfig) {
|
||||
$settings = new admin_settingpage("local_webhooks", new lang_string("pluginname", "local_webhooks"));
|
||||
$ADMIN->add("localplugins", $settings);
|
||||
|
||||
/* The switch of the interceptor of events */
|
||||
$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("externalservices", "webservice");
|
||||
$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/managerservice.php")
|
||||
));
|
||||
}
|
||||
+2
-2
@@ -24,8 +24,8 @@
|
||||
|
||||
defined("MOODLE_INTERNAL") || die();
|
||||
|
||||
$plugin->release = "1.1.1 (Build: 2017102910)";
|
||||
$plugin->version = 2017102910;
|
||||
$plugin->release = "2.1.0 (Build: 2017111810)";
|
||||
$plugin->version = 2017111810;
|
||||
$plugin->requires = 2016112900;
|
||||
$plugin->component = "local_webhooks";
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
Reference in New Issue
Block a user