From c123a6e5546b0cd0b8ed7f6b580ec6a03fecae81 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 1 May 2008 13:44:38 +0000 Subject: Introducing run_function_once($functionname, $timelastupdatedcheck). git-svn-id: https://code.elgg.org/elgg/trunk@592 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 -- cgit v1.2.3