diff options
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 45 | ||||
-rw-r--r-- | engine/lib/upgrades/2010060101.php | 16 | ||||
-rw-r--r-- | engine/start.php | 10 |
3 files changed, 50 insertions, 21 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index f890b3518..e86b7a4c8 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -431,12 +431,19 @@ function elgg_view_register_simplecache($viewname) { /** * Regenerates the simple cache. * + * @param string $viewtype Optional viewtype to regenerate * @see elgg_view_register_simplecache * */ -function elgg_view_regenerate_simplecache() { +function elgg_view_regenerate_simplecache($viewtype = NULL) { global $CONFIG; + if (!isset($CONFIG->views->simplecache) || !is_array($CONFIG->views->simplecache)) { + return; + } + + $lastcached = time(); + // @todo elgg_view() checks if the page set is done (isset($CONFIG->pagesetupdone)) and // triggers an event if it's not. Calling elgg_view() here breaks submenus // (at least) because the page setup hook is called before any @@ -445,25 +452,35 @@ function elgg_view_regenerate_simplecache() { // the trigger correctly when the first view is actually being output. $CONFIG->pagesetupdone = TRUE; - if (isset($CONFIG->views->simplecache)) { - if (!file_exists($CONFIG->dataroot . 'views_simplecache')) { - @mkdir($CONFIG->dataroot . 'views_simplecache'); - } + if (!file_exists($CONFIG->dataroot . 'views_simplecache')) { + mkdir($CONFIG->dataroot . 'views_simplecache'); + } - if (!empty($CONFIG->views->simplecache) && is_array($CONFIG->views->simplecache)) { - foreach($CONFIG->views->simplecache as $view) { - $viewcontents = elgg_view($view); - $viewname = md5(elgg_get_viewtype() . $view); - if ($handle = fopen($CONFIG->dataroot . 'views_simplecache/' . $viewname, 'w')) { - fwrite($handle, $viewcontents); - fclose($handle); - } + if (isset($viewtype)) { + $viewtypes = array($viewtype); + } else { + $viewtypes = $CONFIG->view_types; + } + + $original_viewtype = elgg_get_viewtype(); + + foreach ($viewtypes as $viewtype) { + elgg_set_viewtype($viewtype); + foreach ($CONFIG->views->simplecache as $view) { + $viewcontents = elgg_view($view); + $viewname = md5(elgg_get_viewtype() . $view); + if ($handle = fopen($CONFIG->dataroot . 'views_simplecache/' . $viewname, 'w')) { + fwrite($handle, $viewcontents); + fclose($handle); } } - datalist_set('simplecache_lastupdate', 0); + datalist_set("simplecache_lastupdate_$viewtype", $lastcached); + datalist_set("simplecache_lastcached_$viewtype", $lastcached); } + elgg_set_viewtype($original_viewtype); + unset($CONFIG->pagesetupdone); } diff --git a/engine/lib/upgrades/2010060101.php b/engine/lib/upgrades/2010060101.php new file mode 100644 index 000000000..7772c42eb --- /dev/null +++ b/engine/lib/upgrades/2010060101.php @@ -0,0 +1,16 @@ +<?php + +/** + * Clears old simplecache variables out of database + */ + +$query = "DELETE FROM {$CONFIG->dbprefix}datalists WHERE name LIKE 'simplecache%'"; + +delete_data($query); + +if ($CONFIG->simplecache_enabled) { + datalist_set('simplecache_enabled', 1); + elgg_view_regenerate_simplecache(); +} else { + datalist_set('simplecache_enabled', 0); +} diff --git a/engine/start.php b/engine/start.php index 8329c1e75..f5d3ce5e4 100644 --- a/engine/start.php +++ b/engine/start.php @@ -134,13 +134,9 @@ if (empty($oldview)) { } if (($installed) && ($db_installed)) { - $lastupdate = datalist_get('simplecache_lastupdate'); - $lastcached = datalist_get('simplecache_'.$oldview); + $lastupdate = datalist_get("simplecache_lastupdate_$oldview"); + $lastcached = datalist_get("simplecache_lastcached_$oldview"); if ($lastupdate == 0 || $lastcached < $lastupdate) { - elgg_view_regenerate_simplecache(); - $lastcached = time(); - datalist_set('simplecache_lastupdate',$lastcached); - datalist_set('simplecache_'.$oldview,$lastcached); + elgg_view_regenerate_simplecache($oldview); } - $CONFIG->lastcache = $lastcached; } |