示例#1
0
 /**
  * When missing chapters are found, this cleans up and adds new chapters
  *
  * @param int $comic_id
  * @param array $new_chapters_array 
  */
 public function _clean_comic($comic_id, $new_chapters_array)
 {
     // found, let's get all chapters for this comic
     $chapters = new Chapter();
     $chapters->where('comic_id', $comic_id)->get();
     $chapters = $chapters->all_to_array();
     foreach ($new_chapters_array as $key => $item) {
         foreach ($chapters as $k => $i) {
             if ($item["id"] == $i["id"]) {
                 if ($item["stub"] != $i["stub"] || $item["uniqid"] != $i["uniqid"]) {
                     $chapter = new Chapter($item["id"]);
                     $chapter->remove();
                     unset($chapters[$k]);
                     break;
                 }
                 unset($chapters[$k]);
                 unset($new_chapters_array[$key]);
                 break;
             }
         }
     }
     foreach ($new_chapters_array as $key => $item) {
         $chapter = new Chapter();
         $chapter->from_array($item);
         $chapter->save_as_new();
     }
     foreach ($chapters as $key => $item) {
         $chapter = new Chapter($item["id"]);
         $chapter->remove();
     }
 }