aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-20 18:36:25 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-20 18:36:25 +0000
commita773bddd6e7d5efb58de2bf2abb717125bb53330 (patch)
treede69e2db9b00c38ba9a43e37e02dad1be2ae030d
parentb91909b1a70c4cf6fc9bdb28d0192a52a1e98c09 (diff)
downloadelgg-a773bddd6e7d5efb58de2bf2abb717125bb53330.tar.gz
elgg-a773bddd6e7d5efb58de2bf2abb717125bb53330.tar.bz2
Refs #2793, #2956. Ported run_function_once() and datalist_get/set() changes for values > 32 chars to trunk.
git-svn-id: http://code.elgg.org/elgg/trunk@8363 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/configuration.php42
1 files changed, 35 insertions, 7 deletions
diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php
index bf120a519..7e660c34b 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -210,13 +210,20 @@ $DATALIST_CACHE = array();
*
* @tip Use datalists to store information common to a full installation.
*
- * @param string $name The name of the datalist element
- *
- * @return string|false The datalist value or false if it doesn't exist.
+ * @param string $name The name of the datalist
+ * @return string|null|false String if value exists, null if doesn't, false on error
*/
function datalist_get($name) {
global $CONFIG, $DATALIST_CACHE;
+ $name = trim($name);
+
+ // cannot store anything longer than 32 characters in db, so catch here
+ if (elgg_strlen($name) > 32) {
+ elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
+ return false;
+ }
+
$name = sanitise_string($name);
if (isset($DATALIST_CACHE[$name])) {
return $DATALIST_CACHE[$name];
@@ -255,7 +262,7 @@ function datalist_get($name) {
}
}
- return false;
+ return null;
}
/**
@@ -264,11 +271,17 @@ function datalist_get($name) {
* @param string $name The name of the datalist
* @param string $value The new value
*
- * @return true
+ * @return bool
*/
function datalist_set($name, $value) {
global $CONFIG, $DATALIST_CACHE;
+ // cannot store anything longer than 32 characters in db, so catch before we set
+ if (elgg_strlen($name) > 32) {
+ elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
+ return false;
+ }
+
$name = sanitise_string($name);
$value = sanitise_string($value);
@@ -306,6 +319,9 @@ function datalist_set($name, $value) {
* This will cause the run once function to be run on all installations. To perform
* additional upgrades, create new functions for each release.
*
+ * @warning The function name cannot be longer than 32 characters long due to
+ * the current schema for the datalist table.
+ *
* @internal A datalist entry $functioname is created with the value of time().
*
* @param string $functionname The name of the function you want to run.
@@ -315,10 +331,14 @@ function datalist_set($name, $value) {
* @return bool
*/
function run_function_once($functionname, $timelastupdatedcheck = 0) {
- if ($lastupdated = datalist_get($functionname)) {
+ $lastupdated = datalist_get($functionname);
+ if ($lastupdated) {
$lastupdated = (int) $lastupdated;
- } else {
+ } elseif ($lastupdated !== false) {
$lastupdated = 0;
+ } else {
+ // unable to check datalist
+ return false;
}
if (is_callable($functionname) && $lastupdated <= $timelastupdatedcheck) {
$functionname();
@@ -383,6 +403,14 @@ function unset_config($name, $site_guid = 0) {
function set_config($name, $value, $site_guid = 0) {
global $CONFIG;
+ $name = trim($name);
+
+ // cannot store anything longer than 32 characters in db, so catch before we set
+ if (elgg_strlen($name) > 32) {
+ elgg_log("The name length for configuration variables cannot be greater than 32", "ERROR");
+ return false;
+ }
+
// Unset existing
unset_config($name, $site_guid);