public function get_new_items($watch_owner)
 {
     global $dbh;
     $selector_object = $this->get_selected_selector();
     if ($selector_object) {
         $selector_values = $selector_object->get_value();
         $selector_values = $this->filter_datas($selector_values, $watch_owner);
         $items_datas = $this->get_items_datas($selector_values);
         $datasource_items = $this->fetch_datasource_items();
         for ($i = 0; $i < count($items_datas); $i++) {
             $item = new docwatch_item();
             if ($this->default_interesting) {
                 $item->set_interesting(1);
             }
             $item->set_type($items_datas[$i]['type']);
             if ($this->clean_html) {
                 $item->set_title(strip_tags($items_datas[$i]['title']));
                 $item->set_summary(strip_tags($items_datas[$i]['summary']));
                 $item->set_content(strip_tags($items_datas[$i]['content']));
             } else {
                 $item->set_title($items_datas[$i]['title']);
                 $item->set_summary($items_datas[$i]['summary']);
                 $item->set_content($items_datas[$i]['content']);
             }
             $item->set_publication_date($items_datas[$i]['publication_date']);
             $item->set_url($items_datas[$i]['url']);
             $item->set_logo_url($items_datas[$i]['logo_url']);
             $item->set_num_notice($items_datas[$i]['num_notice']);
             $item->set_source_id($this->id);
             $item->set_num_watch($this->num_watch);
             $item->set_num_article($items_datas[$i]['num_article']);
             $item->set_num_section($items_datas[$i]['num_section']);
             $item->gen_hash();
             if (!in_array($item->get_hash(), $datasource_items)) {
                 $query_hash = "select id_item from docwatch_items where item_hash = '" . $item->get_hash() . "'";
                 $resultat = pmb_mysql_query($query_hash, $dbh);
                 if (!pmb_mysql_num_rows($resultat)) {
                     $item->save();
                 }
             } else {
                 $key = array_search($item->get_hash(), $datasource_items);
                 unset($datasource_items[$key]);
             }
         }
         //Il y'a des items a supprimer de la table (ils ne sont plus dans le flux)
         if (count($datasource_items)) {
             foreach ($datasource_items as $key => $value) {
                 $item = new docwatch_item($key);
                 //On peut supprimer directement
                 if ($item->get_status > 1) {
                     $item->delete();
                 } else {
                     //Check le ttl
                     $query = "select docwatch_items.id_item from docwatch_items join docwatch_watches on docwatch_watches.id_watch=" . $this->num_watch . " where id_item = '" . $item->get_id() . "' and date_add(docwatch_items.item_added_date, interval docwatch_watches.watch_ttl hour) < now()";
                     $result = pmb_mysql_query($query, $dbh);
                     if ($result) {
                         $item->delete();
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * Méthode de suppression
  */
 public function delete()
 {
     global $dbh;
     global $msg;
     if ($this->id && $this->check_rights()) {
         //on commence par éliminer les sources de données et sélecteurs associés...
         $query = "select id_datasource from docwatch_datasources where datasource_num_watch = " . $this->id;
         $result = pmb_mysql_query($query, $dbh);
         if (pmb_mysql_num_rows($result)) {
             while ($row = pmb_mysql_fetch_object($result)) {
                 $query = "select id_selector from docwatch_selectors where selector_num_datasource = " . $row->id_datasource;
                 $sel_result = pmb_mysql_query($query, $dbh);
                 if (pmb_mysql_num_rows($sel_result)) {
                     while ($sel_row = pmb_mysql_fetch_object($sel_result)) {
                         $query = "delete from docwatch_selectors where selector_num_datasource = " . $row->id_datasource;
                         pmb_mysql_query($query, $dbh);
                     }
                 }
                 $query = "delete from docwatch_datasources where datasource_num_watch = " . $this->id;
                 pmb_mysql_query($query, $dbh);
             }
         }
         //il faut ensuite éliminer les items..
         $query = "select id_item from docwatch_items where item_num_watch = " . $this->id;
         $result = pmb_mysql_query($query, $dbh);
         if ($result) {
             while ($row = pmb_mysql_fetch_object($result)) {
                 $docwatch_item = new docwatch_item($row->id_item);
                 $docwatch_item->delete();
             }
         }
         $query = "delete from docwatch_watches where id_watch = " . $this->id;
         $result = pmb_mysql_query($query, $dbh);
         if ($result) {
             return true;
         } else {
             $this->error = $msg['dsi_docwatch_watch_error_database'];
             return false;
         }
     } else {
         $this->error = $msg['dsi_docwatch_watch_error_dont_exist'];
     }
 }
 /**
  * Suppression des items périmés de sources supprimées
  */
 protected function del_outdated_of_datasource_removed()
 {
     global $dbh;
     $query = "select id_item from docwatch_items \n\t\t\t\tleft join docwatch_datasources on item_num_datasource=id_datasource\n\t\t\t\twhere date_add(item_added_date, INTERVAL " . $this->ttl . " hour) < now() \n\t\t\t\tand id_datasource is null and item_status = 2 and item_num_watch = '" . $this->id . "'";
     $result = pmb_mysql_query($query, $dbh);
     if (pmb_mysql_num_rows($result)) {
         while ($row = pmb_mysql_fetch_object($result)) {
             $item = new docwatch_item($row->id_item);
             $item->delete();
         }
     }
     return true;
 }