aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-12-03 18:14:58 +0300
committerValentin Popov <info@valentineus.link>2017-12-03 18:14:58 +0300
commit86b7b53264dbc69d2ed73dacedc4792afd8be90a (patch)
tree0c77f6b17f10ff8d8e329b894e7b95704d34b4fa
parentadbe7b68f6e9187e9a507361e650377681f4a36b (diff)
downloadtool_managertokens-86b7b53264dbc69d2ed73dacedc4792afd8be90a.tar.xz
tool_managertokens-86b7b53264dbc69d2ed73dacedc4792afd8be90a.zip
Refactoring the function to update the record
-rw-r--r--lib.php36
1 files changed, 9 insertions, 27 deletions
diff --git a/lib.php b/lib.php
index 8168dbe..fad6e22 100644
--- a/lib.php
+++ b/lib.php
@@ -72,10 +72,10 @@ function tool_managertokens_create_record($options) {
$token->limited = !empty($options->limited) ? intval($options->limited) : 0;
$token->targetid = !empty($options->targetid) ? intval($options->targetid) : 0;
$token->targettype = !empty($options->targettype) ? strval($options->targettype) : "null";
- $token->timecreated = time();
$token->timelimited = !empty($options->timelimited) ? intval($options->timelimited) : 0;
- $token->timemodified = time();
$token->token = !empty($options->token) ? strval($options->token) : generate_password(12);
+ $token->timecreated = time();
+ $token->timemodified = time();
if (!empty($options->extendedaction) && !empty($options->extendedoptions)) {
$token->extendedaction = strval($options->extendedaction);
@@ -234,37 +234,19 @@ function tool_managertokens_update_record($options) {
}
if ($token = $DB->get_record("tool_managertokens_tokens", array("id" => $options->id), "*", IGNORE_MISSING)) {
+ $token->enabled = !empty($options->enabled) ? boolval($options->enabled) : false;
+ $token->limited = !empty($options->limited) ? intval($options->limited) : $token->limited;
+ $token->targetid = !empty($options->targetid) ? intval($options->targetid) : $token->targetid;
+ $token->targettype = !empty($options->targettype) ? strval($options->targettype) : $token->targettype;
+ $token->timelimited = !empty($options->timelimited) ? intval($options->timelimited) : $token->timelimited;
+ $token->token = !empty($options->token) ? strval($options->token) : $token->token;
$token->timemodified = time();
- if (isset($options->enabled)) {
- $token->enabled = boolval($options->enabled);
- }
-
- if (isset($options->extendedaction) && isset($options->extendedoptions)) {
+ if (!empty($options->extendedaction) && !empty($options->extendedoptions)) {
$token->extendedaction = strval($options->extendedaction);
$token->extendedoptions = strval($options->extendedoptions);
}
- if (isset($options->limited)) {
- $token->limited = intval($options->limited);
- }
-
- if (isset($options->targetid)) {
- $token->targetid = intval($options->targetid);
- }
-
- if (isset($options->targettype)) {
- $token->targettype = strval($options->targettype);
- }
-
- if (isset($options->token)) {
- $token->token = strval($options->token);
- }
-
- if (isset($options->timelimited)) {
- $token->timelimited = intval($options->timelimited);
- }
-
$result = $DB->update_record("tool_managertokens_tokens", $token, false);
}