From 65d7cb38230929653101cc61ef6e08c29c53325c Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 28 Oct 2014 12:26:14 +0000 Subject: [PATCH] Use "update_operator" func for operator modification everywhere --- .../Controller/PasswordRecoveryController.php | 31 ++++--------- src/mibew/libs/operator.php | 44 +++++++------------ 2 files changed, 25 insertions(+), 50 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php b/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php index 1fbdc40c..913d0259 100644 --- a/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php +++ b/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php @@ -19,7 +19,6 @@ namespace Mibew\Controller; -use Mibew\Database; use Mibew\Http\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -72,17 +71,10 @@ class PasswordRecoveryController extends AbstractController ? openssl_random_pseudo_bytes(32) : (time() + microtime()) . mt_rand(0, 99999999))); - $db = Database::getInstance(); - $db->query( - ("UPDATE {operator} " - . "SET dtmrestore = :now, vcrestoretoken = :token " - . "WHERE operatorid = :operatorid"), - array( - ':now' => time(), - ':token' => $token, - ':operatorid' => $to_restore['operatorid'], - ) - ); + // Update the operator + $to_restore['dtmrestore'] = time(); + $to_restore['vcrestoretoken'] = $token; + update_operator($to_restore); $href = $this->getRouter()->generate( 'password_recovery_reset', @@ -178,16 +170,11 @@ class PasswordRecoveryController extends AbstractController if (count($page['errors']) == 0) { $page['isdone'] = true; - $db = Database::getInstance(); - $db->query( - ("UPDATE {operator} " - . "SET vcpassword = ?, vcrestoretoken = '' " - . "WHERE operatorid = ?"), - array( - calculate_password_hash($operator['vclogin'], $password), - $op_id, - ) - ); + // Update the operator + $operator['vcrestoretoken'] = ''; + $operator['vcpassword'] = calculate_password_hash($operator['vclogin'], $password); + update_operator($operator); + $page['loginname'] = $operator['vclogin']; return $this->render('password_recovery_reset', $page); diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index d6271698..72d93f69 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -93,11 +93,9 @@ function permission_descriptions() */ function update_operator_permissions($operator_id, $perm) { - $db = Database::getInstance(); - $db->query( - "UPDATE {operator} SET iperm = ? WHERE operatorid = ?", - array($perm, $operator_id) - ); + $operator = operator_by_id($operator_id); + $operator['iperm'] = $perm; + update_operator($operator); } function operator_by_login($login) @@ -331,11 +329,9 @@ function update_operator($operator) function update_operator_avatar($operator_id, $avatar) { - $db = Database::getInstance(); - $db->query( - "UPDATE {operator} SET vcavatar = ? WHERE operatorid = ?", - array($avatar, $operator_id) - ); + $operator = operator_by_id($operator_id); + $operator['vcavatar'] = $avatar; + update_operator($operator); } /** @@ -431,16 +427,10 @@ function delete_operator($operator_id) */ function notify_operator_alive($operator_id, $istatus) { - $db = Database::getInstance(); - $db->query( - ("UPDATE {operator} SET istatus = :istatus, dtmlastvisited = :now " - . "WHERE operatorid = :operatorid"), - array( - ':istatus' => $istatus, - ':now' => time(), - ':operatorid' => $operator_id, - ) - ); + $operator = operator_by_id($operator_id); + $operator['istatus'] = $istatus; + $operator['dtmlastvisited'] = time(); + update_operator($operator); } /** @@ -784,10 +774,9 @@ function update_operator_groups($operator_id, $new_value) */ function disable_operator($operator_id) { - Database::getInstance()->query( - 'UPDATE {operator} SET idisabled = ? WHERE operatorid = ?', - array('1', $operator_id) - ); + $operator = operator_by_id($operator_id); + $operator['idisabled'] = 1; + update_operator($operator); } /** @@ -797,10 +786,9 @@ function disable_operator($operator_id) */ function enable_operator($operator_id) { - Database::getInstance()->query( - 'UPDATE {operator} SET idisabled = ? WHERE operatorid = ?', - array('0', $operator_id) - ); + $operator = operator_by_id($operator_id); + $operator['idisabled'] = 0; + update_operator($operator); } /**