Example #1
0
 public function check_external($repair = FALSE, $recursive = FALSE)
 {
     $this->load->helper('directory');
     // check if all that is inside is writeable
     if (!$this->check_writable('content/comics/')) {
         return FALSE;
     }
     // check that every folder has a correpsonding comic
     $map = directory_map('content/comics/', 1);
     foreach ($map as $key => $item) {
         // gotta split the directory to get stub and uniqid
         $item_arr = explode('_', $item);
         $uniqid = end($item_arr);
         $stub = str_replace('_' . $uniqid, '', $item);
         $comic = new Comic();
         $comic->where('stub', $stub)->where('uniqid', $uniqid)->get();
         if ($comic->result_count() == 0) {
             $errors[] = 'comic_entry_not_found';
             set_notice('warning', _('No database entry found for:') . ' ' . $stub);
             log_message('debug', 'check: database entry missing for ' . $stub);
             if ($repair) {
                 if (is_dir('content/comics/' . $item)) {
                     // you have to remove all the files in the folder first
                     delete_files('content/comics/' . $item, TRUE);
                     rmdir('content/comics/' . $item);
                 } else {
                     unlink('content/comics/' . $item);
                 }
             }
         }
     }
     // check the database entries
     $comics = new Comic();
     $comics->get();
     foreach ($comics->all as $key => $comic) {
         $comic->check($repair);
     }
     // if recursive, this will go through a through (and long) check of all chapters
     if ($recursive) {
         $chapters = new Chapter();
         $chapters->get_iterated();
         foreach ($chapters as $chapter) {
             $chapter->check($repair);
         }
         // viceversa, check that all the database entries have a matching file
         $pages = new Page();
         $pages->get_iterated();
         foreach ($pages as $page) {
             $page->check($repair);
         }
     }
 }