Index: trunk/core/units/general/my_application.php =================================================================== diff -u -r1662 -r2199 --- trunk/core/units/general/my_application.php (.../my_application.php) (revision 1662) +++ trunk/core/units/general/my_application.php (.../my_application.php) (revision 2199) @@ -41,6 +41,45 @@ $this->SetVar('u_id', $user_id); $this->StoreVar('user_id', $user_id); } + + function RunScheduledEvents() + { + $events = Array('ls:OnCheckExpiredPaidListings', 'u:OnCheckExpiredMembership'); + $run_interval = 3600 * 24; // in seconds + + if(rand(0, 100) < 90) + { + return; + } + + $sql = 'SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "LastMaintainRun"'; + $last_maintain = $this->DB->GetOne($sql); + if($last_maintain && $last_maintain > mktime() - $run_interval) + { + return; + } + elseif($last_maintain) + { + $sql = 'UPDATE '.TABLE_PREFIX.'Cache SET Data = "'.mktime().'" + WHERE VarName = "LastMaintainRun"'; + } + else + { + $sql = 'INSERT INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) + VALUES ("LastMaintainRun", "'.mktime().'", "'.mktime().'")'; + } + $this->DB->Query($sql); + + foreach($events as $scheduled_event) + { + list($prefix, $event_name) = explode(':', $scheduled_event); + $event =& new kEvent(); + $event->Init($prefix); + $event->Name = $event_name; + $this->HandleEvent($event); + unset($event); + } + } } ?> \ No newline at end of file