Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2014-09-27 09:50:02 +0400
committerdiosmosis <benaka@piwik.pro>2014-09-27 14:27:44 +0400
commit13f7e2ca13264b615aa0233faa9ca589c83fedb7 (patch)
treea9ae5c66c5189202fe6953821b747c05ad6974f0 /core/Piwik.php
parent6a959a5566f25e828f07ac5d588023931a32ba97 (diff)
Refactor Login controller and auth to be more modular and easier to extend/override. Added extra method to Auth interface and documented Auth interface completely. Created new PasswordResetter class to contain password reset logic.
Diffstat (limited to 'core/Piwik.php')
-rw-r--r--core/Piwik.php30
1 files changed, 29 insertions, 1 deletions
diff --git a/core/Piwik.php b/core/Piwik.php
index e52f329404..c00d5e42e9 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -861,4 +861,32 @@ class Piwik
}
return $options;
}
-}
+
+ /**
+ * Executes a callback with superuser privileges, making sure those privileges are rescinded
+ * before this method exits. Privileges will be rescinded even if an exception is thrown.
+ *
+ * @param callback $function The callback to execute. Should accept no arguments.
+ * @return mixed The result of `$function`.
+ * @throws Exception rethrows any exceptions thrown by `$function`.
+ * @api
+ */
+ public static function doAsSuperUser($function)
+ {
+ $isSuperUser = self::hasUserSuperUserAccess();
+
+ self::setUserHasSuperUserAccess();
+
+ try {
+ $result = $function();
+ } catch (Exception $ex) {
+ self::setUserHasSuperUserAccess($isSuperUser);
+
+ throw $ex;
+ }
+
+ self::setUserHasSuperUserAccess($isSuperUser);
+
+ return $result;
+ }
+} \ No newline at end of file