public function CleanUp() { $now = current_time('timestamp'); $max_sdate = $this->plugin->settings->GetPruningDate(); $max_count = $this->plugin->settings->GetPruningLimit(); $is_date_e = $this->plugin->settings->IsPruningDateEnabled(); $is_limt_e = $this->plugin->settings->IsPruningLimitEnabled(); $max_stamp = $now - (strtotime($max_sdate) - $now); $cnt_items = WSAL_DB_Occurrence::Count(); $max_items = max($cnt_items - $max_count + 1, 0); if (!$is_date_e && !$is_limt_e) { return; } // pruning disabled $query = new WSAL_DB_OccurrenceQuery('WSAL_DB_Occurrence'); $query->order[] = 'created_on ASC'; if ($is_date_e) { $query->Where('created_on < %d', array($max_stamp)); } if ($is_limt_e) { $query->length = (int) $max_items; } $count = $query->Count(); if (!$count) { return; } // nothing to delete // delete data $query->Delete(); // keep track of what we're doing $this->plugin->alerts->Trigger(03, array('Message' => 'Running system cleanup.', 'Query SQL' => $query->GetSql(), 'Query Args' => $query->GetArgs()), true); // notify system do_action('wsal_prune', $count, vsprintf($query->GetSql(), $query->GetArgs())); }
public function CleanUp() { $now = current_time('timestamp'); $max_count = $this->plugin->settings->GetPruningLimit(); $max_sdate = $this->plugin->settings->GetPruningDate(); $max_stamp = $now - (strtotime($max_sdate) - $now); $cnt_items = WSAL_DB_Occurrence::Count(); if ($cnt_items == $max_count) { return; } $max_items = max($cnt_items - $max_count + 1, 0); $is_date_e = $this->plugin->settings->IsPruningDateEnabled(); $is_limt_e = $this->plugin->settings->IsPruningLimitEnabled(); switch (true) { case $is_date_e && $is_limt_e: $cond = 'created_on < %d ORDER BY created_on ASC LIMIT %d'; $args = array($max_stamp, $max_items); break; case $is_date_e && !$is_limt_e: $cond = 'created_on < %d'; $args = array($max_stamp); break; case !$is_date_e && $is_limt_e: $cond = '1 ORDER BY created_on ASC LIMIT %d'; $args = array($max_items); break; case !$is_date_e && !$is_limt_e: return; } if (!isset($cond)) { return; } $items = WSAL_DB_Occurrence::LoadMulti($cond, $args); if (!count($items)) { return; } foreach ($items as $item) { $item->Delete(); } do_action('wsal_prune', $items, vsprintf($cond, $args)); }
public function AjaxRefresh() { if (!$this->_plugin->settings->CurrentUserCan('view')) { die('Access Denied.'); } if (!isset($_REQUEST['logcount'])) { die('Log count parameter expected.'); } $old = (int) $_REQUEST['logcount']; $max = 40; // 40*500msec = 20sec session_write_close(); // fixes session lock issue do { $new = WSAL_DB_Occurrence::Count(); usleep(500000); // 500msec } while ($old == $new && --$max > 0); echo $old == $new ? 'false' : $new; die; }