Exemple #1
0
 public function root($domain_id = null, $debug = false)
 {
     // check root page of ALL DOMAIN EVERY 1hr and update_child right away
     if ($debug) {
         echo 'FETCH:ROOT';
     } else {
         log_message('info', 'FETCH:ROOT');
     }
     $option = array('parent_page_id' => 0);
     if ($domain_id != null) {
         $this->db->where('domain_id', $domain_id);
     }
     $query = $this->db->get_where('page', $option);
     if ($debug) {
         echo 'FETCH:ROOT: Found pages : ' . $query->num_rows();
     } else {
         log_message('info', 'FETCH:ROOT: Found pages : ' . $query->num_rows());
     }
     $new_fetch_pages = array();
     foreach ($query->result() as $row) {
         // every domain find latest page_id of root_url
         $page = new Page_model();
         $page->init($row->id);
         while ($page->outdate != 0) {
             $page->init($page->new_id);
         }
         if ($page->id == null) {
             continue;
         }
         // skip if page is blank
         // check latest_fetch > 60 min
         $latest_fetch = strtotime($page->latest_fetch);
         $difference = time() - $latest_fetch;
         $hours = intval(floor($difference / 3600));
         if ($debug) {
             echo PHP_EOL . 'page:' . $page->id . ' latest_fetch:' . $page->latest_fetch . ' diff:' . $hours;
         }
         // if found, fetch page and put in array
         if ($hours > 0) {
             $fetch = $page->fetch();
             if ($fetch != null) {
                 $new_id = $page->update_new_page($fetch);
                 $new_fetch_pages[] = $new_id;
                 if ($debug) {
                     echo ' FETCH';
                 }
             } else {
                 $page->less_active();
             }
         }
         unset($page);
     }
     unset($new_fetch_pages);
 }