Exemplo n.º 1
0
 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();
     if (!$is_date_e && !$is_limt_e) {
         return;
     }
     // pruning disabled
     $occ = new WSAL_Models_Occurrence();
     $cnt_items = $occ->Count();
     // Check if there is something to delete
     if ($is_limt_e && $cnt_items < $max_count) {
         return;
     }
     $max_stamp = $now - (strtotime($max_sdate) - $now);
     $max_items = (int) max($cnt_items - $max_count + 1, 0);
     $query = new WSAL_Models_OccurrenceQuery();
     $query->addOrderBy("created_on", false);
     // TO DO Fixing data
     if ($is_date_e) {
         $query->addCondition('created_on <= %s', intval($max_stamp));
     }
     if ($is_limt_e) {
         $query->setLimit($max_items);
     }
     if ($max_items - 1 == 0) {
         return;
     }
     // nothing to delete
     $result = $query->getAdapter()->GetSqlDelete($query);
     $deletedCount = $query->getAdapter()->Delete($query);
     if ($deletedCount == 0) {
         return;
     }
     // nothing to delete
     // keep track of what we're doing
     $this->plugin->alerts->Trigger(03, array('Message' => 'Running system cleanup.', 'Query SQL' => $result['sql'], 'Query Args' => $result['args']), true);
     // notify system
     do_action('wsal_prune', $deletedCount, vsprintf($result['sql'], $result['args']));
 }
Exemplo n.º 2
0
 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 {
         $occ = new WSAL_Models_Occurrence();
         $new = $occ->Count();
         usleep(500000);
         // 500msec
     } while ($old == $new && --$max > 0);
     echo $old == $new ? 'false' : $new;
     die;
 }