diff options
| author | Nathan Kinkade <nath@nkinka.de> | 2013-03-19 16:41:42 +0000 | 
|---|---|---|
| committer | Nathan Kinkade <nath@nkinka.de> | 2013-03-19 16:41:42 +0000 | 
| commit | 3908e37d965fa76ea774e76ddf42365a872a5f27 (patch) | |
| tree | 457e1a1e465f83855eee96ba287cd91f1623395c /modules/gallery/helpers/gallery_event.php | |
| parent | 711651f727e093cc7357a6bbff6bd992fd6dfd80 (diff) | |
| parent | 1eab94f6062b5f54ea5d9db01d968e7195f3de9d (diff) | |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/gallery/helpers/gallery_event.php')
| -rw-r--r-- | modules/gallery/helpers/gallery_event.php | 39 | 
1 files changed, 39 insertions, 0 deletions
| diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index aeb1c7eb..a319b9c6 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -36,6 +36,41 @@ class gallery_event_Core {      locales::set_request_locale();    } +  static function gallery_shutdown() { +    // Every 500th request, do a pass over var/logs and var/tmp and delete old files. +    // Limit ourselves to deleting a single file so that we don't spend too much CPU +    // time on it.  As long as servers call this at least twice a day they'll eventually +    // wind up with a clean var/logs directory because we only create 1 file a day there. +    // var/tmp might be stickier because theoretically we could wind up spamming that +    // dir with a lot of files.  But let's start with this and refine as we go. +    if (!(rand() % 500)) { +      // Note that this code is roughly duplicated in gallery_task::file_cleanup +      $threshold = time() - 1209600; // older than 2 weeks +      foreach(array("logs", "tmp") as $dir) { +        $dir = VARPATH . $dir; +        if ($dh = opendir($dir)) { +          while (($file = readdir($dh)) !== false) { +            if ($file[0] == ".") { +              continue; +            } + +            // Ignore directories for now, but we should really address them in the long term. +            if (is_dir("$dir/$file")) { +              continue; +            } + +            if (filemtime("$dir/$file") <= $threshold) { +              unlink("$dir/$file"); +              break; +            } +          } +        } +      } +    } +    // Delete all files marked using system::delete_later. +    system::delete_marked_files(); +  } +    static function user_deleted($user) {      $admin = identity::admin_user();      if (!empty($admin)) {          // could be empty if there is not identity provider @@ -399,6 +434,10 @@ class gallery_event_Core {                          ->label(t("Graphics"))                          ->url(url::site("admin/graphics")))                 ->append(Menu::factory("link") +                        ->id("movies_settings") +                        ->label(t("Movies")) +                        ->url(url::site("admin/movies"))) +               ->append(Menu::factory("link")                          ->id("languages")                          ->label(t("Languages"))                          ->url(url::site("admin/languages"))) | 
