diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-01 13:44:38 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-01 13:44:38 +0000 |
commit | c123a6e5546b0cd0b8ed7f6b580ec6a03fecae81 (patch) | |
tree | 9be14b9a3a0b61ebc569f2b0d72b8a0838a2acf9 /engine/lib/elgglib.php | |
parent | f4adea3198f441663835ea4e45f622483adb444e (diff) | |
download | elgg-c123a6e5546b0cd0b8ed7f6b580ec6a03fecae81.tar.gz elgg-c123a6e5546b0cd0b8ed7f6b580ec6a03fecae81.tar.bz2 |
Introducing run_function_once($functionname, $timelastupdatedcheck).
git-svn-id: https://code.elgg.org/elgg/trunk@592 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/elgglib.php')
-rw-r--r-- | engine/lib/elgglib.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 10a2ebb25..999bffce5 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -859,4 +859,29 @@ }
+ /**
+ * Runs a function once - not per page load, but per installation.
+ * If you like, you can also set the threshold for the function execution - i.e.,
+ * if the function was executed before or on $timelastupdatedcheck, this
+ * function will run it again.
+ *
+ * @param string $functionname The name of the function you want to run.
+ * @param int $timelastupdatedcheck Optionally, the UNIX epoch timestamp of the execution threshold
+ * @return true|false Depending on success.
+ */
+ function run_function_once($functionname, $timelastupdatedcheck = 0) {
+ if ($lastupdated = datalist_get($name)) {
+ $lastupdated = (int) $lastupdated;
+ } else {
+ $lastupdated = 0;
+ }
+ if (is_callable($functionname) && $lastupdated <= $timelastupdatedcheck) {
+ $functionname();
+ datalist_set($functionname,time());
+ return true;
+ } else {
+ return false;
+ }
+ }
+
?>
\ No newline at end of file |