summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-12-21 11:06:20 +0300
committerValentin Popov <info@valentineus.link>2017-12-21 11:06:20 +0300
commit499f36d118380ce6994fa31944deb64867d022eb (patch)
tree30573e9974bef43c939cd9deca860cd2dbeb624e
parent49516bea824623973233916dd119d1c0afe4e25f (diff)
downloadlocal_webhooks-499f36d118380ce6994fa31944deb64867d022eb.tar.xz
local_webhooks-499f36d118380ce6994fa31944deb64867d022eb.zip
Integration of the event system into functions
-rw-r--r--classes/event/service_deletedall.php4
-rw-r--r--lib.php19
2 files changed, 14 insertions, 9 deletions
diff --git a/classes/event/service_deletedall.php b/classes/event/service_deletedall.php
index 8958cd9..a7eba67 100644
--- a/classes/event/service_deletedall.php
+++ b/classes/event/service_deletedall.php
@@ -46,14 +46,14 @@ class service_deletedall extends \core\event\base {
* Return localised event name.
*/
public static function get_name() {
- return new \lang_string("deleteall", "moodle");
+ return new \lang_string("deleted", "moodle");
}
/**
* Returns description of what happened.
*/
public function get_description() {
- return new \lang_string("eventwebserviceservicedeleted", "webservice");
+ return new \lang_string("deletecompletely", "moodle");
}
/**
diff --git a/lib.php b/lib.php
index 64f2065..f22c61b 100644
--- a/lib.php
+++ b/lib.php
@@ -35,15 +35,13 @@ require_once(__DIR__ . "/locallib.php");
function local_webhooks_change_status($serviceid) {
global $DB;
- $result = false;
- $conditions = array("id" => $serviceid);
-
- if ($DB->record_exists("local_webhooks_service", $conditions)) {
- $enabled = $DB->get_field("local_webhooks_service", "enable", $conditions, IGNORE_MISSING);
- $result = $DB->set_field("local_webhooks_service", "enable", !boolval($enabled), $conditions);
+ $result = false;
+ if ($record = local_webhooks_get_record($serviceid)) {
+ $record->enable = !boolval($record->enable);
+ $result = local_webhooks_update_record($record);
}
- return boolval($result);
+ return $result;
}
/**
@@ -99,6 +97,7 @@ function local_webhooks_create_record($record) {
}
$result = $DB->insert_record("local_webhooks_service", $record, true, false);
+ local_webhooks_events::service_added($result);
return boolval($result);
}
@@ -116,6 +115,7 @@ function local_webhooks_update_record($record) {
}
$result = $DB->update_record("local_webhooks_service", $record, false);
+ local_webhooks_events::service_updated($record->id);
return boolval($result);
}
@@ -128,6 +128,7 @@ function local_webhooks_update_record($record) {
function local_webhooks_delete_record($serviceid) {
global $DB;
$result = $DB->delete_records("local_webhooks_service", array("id" => $serviceid));
+ local_webhooks_events::service_deleted($serviceid);
return boolval($result);
}
@@ -139,6 +140,7 @@ function local_webhooks_delete_record($serviceid) {
function local_webhooks_delete_all_records() {
global $DB;
$result = $DB->delete_records("local_webhooks_service", null);
+ local_webhooks_events::service_deletedall();
return boolval($result);
}
@@ -150,6 +152,7 @@ function local_webhooks_delete_all_records() {
function local_webhooks_create_backup() {
$listrecords = local_webhooks_get_list_records();
$result = local_webhooks_serialization_data($listrecords);
+ local_webhooks_events::backup_performed();
return $result;
}
@@ -168,6 +171,8 @@ function local_webhooks_restore_backup($data, $deleterecords = false) {
foreach ($listrecords as $servicerecord) {
local_webhooks_create_record($servicerecord);
}
+
+ local_webhooks_events::backup_restored();
}
/**