Overview

Packages

  • Horde
  • None

Classes

  • Horde_Ajax_Application
  • Horde_Api
  • Horde_Block_Account
  • Horde_Block_Account_Base
  • Horde_Block_Account_Finger
  • Horde_Block_Account_Ldap
  • Horde_Block_Account_Localhost
  • Horde_Block_Cloud
  • Horde_Block_FbStream
  • Horde_Block_Feed
  • Horde_Block_Fortune
  • Horde_Block_Google
  • Horde_Block_Iframe
  • Horde_Block_Metar
  • Horde_Block_Moon
  • Horde_Block_Sunrise
  • Horde_Block_Time
  • Horde_Block_TwitterTimeline
  • Horde_Block_Vatid
  • Horde_Block_Weather
  • Horde_LoginTasks_SystemTask_GarbageCollection
  • Horde_LoginTasks_SystemTask_Upgrade
  • Horde_LoginTasks_Task_AdminCheck
  • Horde_LoginTasks_Task_LastLogin
  • Horde_LoginTasks_Task_TosAgreement
  • Horde_Prefs_Ui
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Login system task for automated garbage collection tasks.
 4:  *
 5:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file COPYING for license information (LGPL). If you
 8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 9:  *
10:  * @author   Michael Slusarz <slusarz@horde.org>
11:  * @category Horde
12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
13:  * @package  Horde
14:  */
15: class Horde_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_SystemTask
16: {
17:     /**
18:      * The interval at which to run the task.
19:      *
20:      * @var integer
21:      */
22:     public $interval = Horde_LoginTasks::WEEKLY;
23: 
24:     /**
25:      * Perform all functions for this task.
26:      */
27:     public function execute()
28:     {
29:         /* Clean out static cache files. Any user has a 10% chance of
30:          * triggering this weekly - no need to have every user trigger
31:          * this once weekly since these static files are shared among
32:          * all users. */
33:         if (rand(0, 9) === 0) {
34:             foreach (array('cachecss', 'cachejs') as $val) {
35:                 if (!empty($GLOBALS['conf'][$val]) &&
36:                     (strcasecmp($GLOBALS['conf'][$val . 'params']['driver'], 'filesystem') === 0)) {
37:                     $this->_staticFilesGc($val);
38:                 }
39:             }
40:         }
41:     }
42: 
43:     /**
44:      * Do cleanup of static files directory.
45:      */
46:     protected function _staticFilesGc($type)
47:     {
48:         if (!($lifetime = $GLOBALS['conf'][$type . 'params']['lifetime'])) {
49:             continue;
50:         }
51: 
52:         /* Keep a file in the static directory that prevents us from doing
53:          * garbage collection more than once a day. */
54:         $curr_time = time();
55:         $static_dir = $GLOBALS['registry']->get('fileroot', 'horde') . '/static';
56:         $static_stat = $static_dir . '/gc_' . $type;
57:         $next_run = null;
58: 
59:         if (file_exists($static_stat)) {
60:             $next_run = $static_stat;
61:         }
62: 
63:         if (is_null($next_run) || ($curr_time > $next_run)) {
64:             file_put_contents($static_stat, $curr_time + 86400);
65:         }
66: 
67:         if (is_null($next_run) || ($curr_time < $next_run)) {
68:             return;
69:         }
70: 
71:         $c_time = $curr_time - $lifetime;
72:         foreach (glob($static_dir . '/*.' . substr($type, 5)) as $file) {
73:             if ($c_time > filemtime($file)) {
74:                 @unlink($file);
75:             }
76:         }
77: 
78:         Horde::logMessage('Cleaned out static files for ' . $type, 'DEBUG');
79:     }
80: 
81: }
82: 
API documentation generated by ApiGen