Exemple #1
0
 /**
  * Delete this test or related object.
  * If no parameters are set, this method deletes current test and all files associated with this test.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $path_to_test_files = 'private/uploads/unit_tests/test_' . $this->id;
         if (file_exists($path_to_test_files)) {
             unlink_recursive($path_to_test_files, TRUE);
         }
     }
     parent::delete($object, $related_field);
 }
function list_import_prepare()
{
    $CI =& get_instance();
    $periods = new Period();
    $periods->truncate();
    echo 'LIST periods table truncated ...' . "\n";
    $courses = new Course();
    $courses->truncate();
    echo 'LIST courses table truncated ...' . "\n";
    $groups = new Group();
    $groups->truncate();
    echo 'LIST groups table truncated ...' . "\n";
    $rooms = new Room();
    $rooms->truncate();
    echo 'LIST rooms table truncated ...' . "\n";
    $participants = new Participant();
    $participants->truncate();
    echo 'LIST participants table truncated ...' . "\n";
    $CI->db->simple_query('TRUNCATE TABLE `course_task_set_type_rel`');
    echo 'LIST course_task_set_type_rel table truncated ...' . "\n";
    $categories = new Category();
    $categories->truncate();
    echo 'LIST categories table truncated ...' . "\n";
    $tasks = new Task();
    $tasks->truncate();
    $CI->lang->delete_overlays('tasks');
    unlink_recursive('private/uploads/task_files/', FALSE);
    unlink_recursive('private/uploads/unit_tests/', FALSE);
    echo 'LIST tasks table truncated ...' . "\n";
    $CI->db->simple_query('TRUNCATE TABLE `task_category_rel`');
    echo 'LIST task_category_rel table truncated ...' . "\n";
    $task_set_types = new Task_set_type();
    $task_set_types->truncate();
    echo 'LIST task_set_types table truncated ...' . "\n";
    $task_sets = new Task_set();
    $task_sets->truncate();
    $CI->lang->delete_overlays('task_sets');
    echo 'LIST task_sets table truncated ...' . "\n";
    $comments = new Comment();
    $comments->truncate();
    echo 'LIST comments table truncated ...' . "\n";
    $solutions = new Solution();
    $solutions->truncate();
    unlink_recursive('private/uploads/solutions/', FALSE);
    echo 'LIST solutions table truncated ...' . "\n";
    $CI->db->simple_query('TRUNCATE TABLE `task_task_set_rel`');
    echo 'LIST task_task_set_rel table truncated ...' . "\n";
}
/**
 * Recursively delete a directory.
 *
 * @param string  $dir             directory name.
 * @param boolean $delete_root_too delete specified top-level directory as well.
 */
function unlink_recursive($dir, $delete_root_too)
{
    if (!($dh = @opendir($dir))) {
        return;
    }
    while (FALSE !== ($obj = readdir($dh))) {
        if ($obj == '.' || $obj == '..') {
            continue;
        }
        if (!@unlink($dir . '/' . $obj)) {
            unlink_recursive($dir . '/' . $obj, TRUE);
        }
    }
    closedir($dh);
    if ($delete_root_too) {
        @rmdir($dir);
    }
    return;
}
Exemple #4
0
function unlink_recursive($dir, $deleteRootToo = true)
{
    if (!file_exists($dir) || !($dh = @opendir($dir))) {
        return;
    }
    while (false !== ($obj = readdir($dh))) {
        if ($obj == '.' || $obj == '..') {
            continue;
        }
        if (!@unlink($dir . DIRECTORY_SEPARATOR . $obj)) {
            unlink_recursive($dir . DIRECTORY_SEPARATOR . $obj, true);
        }
    }
    closedir($dh);
    if ($deleteRootToo) {
        @rmdir($dir);
    }
    return;
}
Exemple #5
0
 /**
  * Extracts one file from given student ZIP file and index and returns its content.
  * @param string $real_filename solution file name.
  * @param integer $index index in ZIP file.
  * @return boolean|array returns array with file content, name and extension or FALSE on error.
  */
 public function extract_student_file_by_index($real_filename, $index)
 {
     $file_info = $this->get_specific_file_info($real_filename);
     if ($file_info !== FALSE) {
         $path = 'private/uploads/solutions/task_set_' . intval($this->id) . '/';
         $CI =& get_instance();
         $CI->load->library('session');
         $supported_extensions = $this->trim_explode(',', $CI->config->item('readable_file_extensions'));
         $all_userdata = $CI->session->all_userdata();
         $extract_path = 'private/extracted_solutions/task_set_' . intval($this->id) . '/' . $all_userdata['session_id'] . '/';
         @mkdir('private/extracted_solutions/task_set_' . intval($this->id) . '/', DIR_READ_MODE);
         @mkdir($extract_path, DIR_READ_MODE);
         $zip_file = new ZipArchive();
         $open = $zip_file->open($path . $real_filename);
         $content = '';
         $filename = '';
         $extension = '';
         $file_read = TRUE;
         if ($open === TRUE && intval($index) >= 0 && intval($index) < $zip_file->numFiles) {
             $extracted_file = $zip_file->getNameIndex(intval($index));
             $extension = '';
             $ext_pos = strrpos($extracted_file, '.');
             if ($ext_pos !== FALSE) {
                 $extension = substr($extracted_file, $ext_pos + 1);
             }
             if (in_array(strtolower($extension), $supported_extensions)) {
                 $zip_file->extractTo($extract_path, $extracted_file);
                 $content = @file_get_contents($extract_path . $extracted_file);
                 $filename = basename($extract_path . $extracted_file);
             } else {
                 $file_read = FALSE;
             }
             $zip_file->close();
         } else {
             $file_read = FALSE;
         }
         @unlink_recursive(rtrim($extract_path, '/'), TRUE);
         return $file_read ? array('content' => $content, 'filename' => $filename, 'extension' => $extension) : FALSE;
     }
     return FALSE;
 }
 protected function delete_upload_folder($id)
 {
     $path = Questionnaire::PATH_TO_UPLOAD_FOLDER . $id;
     @unlink_recursive($path, true);
 }
 public function delete_person($person_id = NULL)
 {
     if (is_null($person_id)) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     $person = new Person();
     $person->get_by_id((int) $person_id);
     if (!$person->exists()) {
         add_error_flash_message('Osoba sa nenašla.');
         redirect(site_url('persons'));
     }
     if ($person->id == auth_get_id()) {
         add_error_flash_message('Nemôžete vymazať vlastný účet.');
         redirect(site_url('persons'));
     }
     $success_message = 'Osoba <strong>' . $person->name . ' ' . $person->surname . '</strong> s loginom <strong>' . $person->login . '</strong>, a s ID <strong>' . $person->id . '</strong> bola úspešne vymazaná.';
     $error_message = 'Osobu <strong>' . $person->name . ' ' . $person->surname . '</strong> s loginom <strong>' . $person->login . '</strong>, a s ID <strong>' . $person->id . '</strong> sa nepodarilo vymazať.';
     if ($person->delete()) {
         unlink_recursive('user/photos/data/' . (int) $person_id . '/', TRUE);
         add_success_flash_message($success_message);
     } else {
         add_error_flash_message($error_message);
     }
     redirect(site_url('persons'));
 }
 function delete_directory($dir)
 {
     unlink_recursive($dir);
 }
Exemple #9
0
 public function clone_task($task_id)
 {
     $result = new stdClass();
     $result->result = FALSE;
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $old_task = new Task();
     $old_task->get_by_id((int) $task_id);
     if ($old_task->exists()) {
         $new_task = $old_task->get_copy();
         if ($new_task->save()) {
             $this->lang->clone_overlays('tasks', $old_task->id, $new_task->id);
             $from = 'private/uploads/task_files/task_' . $old_task->id;
             $continue = TRUE;
             if (file_exists($from)) {
                 $to = 'private/uploads/task_files/task_' . $new_task->id;
                 if (!clone_directory($from, $to)) {
                     unlink_recursive($to, TRUE);
                     $this->db->trans_rollback();
                     $result->message = $this->lang->line('admin_tasks_error_message_files_not_cloned');
                     $continue = FALSE;
                 }
             }
             if ($continue) {
                 $old_categories = new Category();
                 $old_categories->where_related($old_task);
                 $old_categories->get();
                 if ($old_categories->result_count()) {
                     foreach ($old_categories->all as $old_category) {
                         $old_category->save($new_task);
                     }
                 }
                 $old_tests = new Test();
                 $old_tests->where_related($old_task);
                 $old_tests->get();
                 if ($old_tests->result_count()) {
                     foreach ($old_tests->all as $old_test) {
                         $new_test = $old_test->get_copy();
                         if ($new_test->save($new_task)) {
                             $this->lang->clone_overlays('tests', $old_test->id, $new_test->id);
                             $from = 'private/uploads/unit_tests/test_' . $old_test->id;
                             $to = 'private/uploads/unit_tests/test_' . $new_test->id;
                             clone_directory($from, $to);
                         }
                     }
                 }
                 $this->db->trans_commit();
                 $result->result = TRUE;
                 $result->message = $this->lang->line('admin_tasks_success_message_task_cloned');
             }
         } else {
             $this->db->trans_rollback();
             $result->message = $this->lang->line('admin_tasks_error_message_clone_dont_saved');
         }
     } else {
         $this->db->trans_rollback();
         $result->message = $this->lang->line('admin_tasks_error_message_task_not_found');
     }
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($result));
 }
 /**
  * Recursive delete current test work directory with everything inside.
  */
 protected function delete_test_directory()
 {
     if (file_exists($this->current_test_directory)) {
         unlink_recursive($this->current_test_directory, TRUE);
     }
 }
Exemple #11
0
 /**
  * Deletes relations (if parameters are set) or this object from database.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     parent::delete($object, $related_field);
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $tests = new Test();
         $tests->where_related($this);
         $tests->get();
         if ($tests->result_count()) {
             foreach ($tests->all as $test) {
                 $test->delete();
             }
         }
         $path = 'private/uploads/task_files/task_' . intval($this_id) . '/';
         if (file_exists($path)) {
             unlink_recursive($path, TRUE);
         }
     }
 }
Exemple #12
0
 public function garbage_collector()
 {
     echo 'Running garbage collector script ...' . "\n";
     $this->load->helper('application');
     $current_time = time();
     $this->load->library('cli_progress_bar');
     $this->cli_progress_bar->init(5);
     // ----------- COMPARATOR WORKING DIRECTORIES --------------------------
     $path_to_comparator_files = 'public/comparator/';
     $time_for_comparator_folders_to_remain_untouched = 21600;
     //echo ' Clearing old Java comparator working directories:' . "\n";
     $this->cli_progress_bar->print_text(' Clearing old Java comparator working directories:');
     $dirs = scandir($path_to_comparator_files);
     $deleted = 0;
     $total_dirs = 0;
     if (is_array($dirs) && count($dirs) > 0) {
         foreach ($dirs as $dir) {
             if (is_dir($path_to_comparator_files . $dir) && $dir != '.' && $dir != '..') {
                 $total_dirs++;
                 $to_print = '  ' . $dir;
                 $dir_mod_time = filemtime($path_to_comparator_files . $dir);
                 if ($current_time - $dir_mod_time >= $time_for_comparator_folders_to_remain_untouched) {
                     $deleted++;
                     unlink_recursive($path_to_comparator_files . $dir, TRUE);
                     $to_print .= ':  OLD - deleting' . "\n";
                 } else {
                     $to_print .= ':  SAFE' . "\n";
                 }
                 $this->cli_progress_bar->print_text($to_print, TRUE);
             } else {
                 $this->cli_progress_bar->tick();
             }
         }
     }
     if ($total_dirs == 0) {
         //echo '  No directories ...' . "\n";
         $this->cli_progress_bar->print_text('  No directories ...');
     }
     //echo ' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.' . "\n";
     $this->cli_progress_bar->print_text(' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.');
     $this->cli_progress_bar->increment();
     // ----------- MOSS WORKING DIRECTORIES --------------------------------
     $path_to_moss_files = 'private/moss/';
     $time_for_moss_folders_to_remain_untouched = 21600;
     //echo ' Clearing old MOSS comparator working directories:' . "\n";
     $this->cli_progress_bar->print_text(' Clearing old MOSS comparator working directories:');
     $dirs = scandir($path_to_moss_files);
     $deleted = 0;
     $total_dirs = 0;
     if (is_array($dirs) && count($dirs) > 0) {
         foreach ($dirs as $dir) {
             if (is_dir($path_to_moss_files . $dir) && $dir != '.' && $dir != '..') {
                 $total_dirs++;
                 $to_print = '  ' . $dir;
                 $dir_mod_time = filemtime($path_to_moss_files . $dir);
                 if ($current_time - $dir_mod_time >= $time_for_moss_folders_to_remain_untouched) {
                     $deleted++;
                     unlink_recursive($path_to_moss_files . $dir, TRUE);
                     $to_print .= ':  OLD - deleting' . "\n";
                 } else {
                     $to_print .= ':  SAFE' . "\n";
                 }
                 $this->cli_progress_bar->print_text($to_print, TRUE);
             } else {
                 $this->cli_progress_bar->tick();
             }
         }
     }
     if ($total_dirs == 0) {
         //echo '  No directories ...' . "\n";
         $this->cli_progress_bar->print_text('  No directories ...');
     }
     //echo ' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.' . "\n";
     $this->cli_progress_bar->print_text(' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.');
     $this->cli_progress_bar->increment();
     // ----------- EXTRACTED SOLUTIONS DIRECTORIES -------------------------
     $path_to_extracted_solutions = 'private/extracted_solutions/';
     $time_for_extracted_solutions_to_remain_untouched = 1800;
     //echo ' Clearing old extracted solutions working directories:' . "\n";
     $this->cli_progress_bar->print_text(' Clearing old extracted solutions working directories:');
     $dirs = scandir($path_to_extracted_solutions);
     $deleted = 0;
     $total_dirs = 0;
     if (is_array($dirs) && count($dirs) > 0) {
         foreach ($dirs as $dir) {
             if (is_dir($path_to_extracted_solutions . $dir) && $dir != '.' && $dir != '..') {
                 $total_dirs++;
                 $to_print = '  ' . $dir;
                 $dir_mod_time = filemtime($path_to_extracted_solutions . $dir);
                 if ($current_time - $dir_mod_time >= $time_for_extracted_solutions_to_remain_untouched) {
                     $deleted++;
                     unlink_recursive($path_to_extracted_solutions . $dir, TRUE);
                     $to_print .= ':  OLD - deleting' . "\n";
                 } else {
                     $to_print .= ':  SAFE' . "\n";
                 }
                 $this->cli_progress_bar->print_text($to_print, TRUE);
             } else {
                 $this->cli_progress_bar->tick();
             }
         }
     }
     if ($total_dirs == 0) {
         //echo '  No directories ...' . "\n";
         $this->cli_progress_bar->print_text('  No directories ...');
     }
     //echo ' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.' . "\n";
     $this->cli_progress_bar->print_text(' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.');
     $this->cli_progress_bar->increment();
     // ----------- TEST TO EXECUTE DIRECTORIES -----------------------------
     $path_to_test_to_execute = 'private/test_to_execute/';
     $time_for_test_to_execute_to_remain_untouched = 3600;
     //echo ' Clearing old test to execute working directories:' . "\n";
     $this->cli_progress_bar->print_text(' Clearing old test to execute working directories:');
     $dirs = scandir($path_to_test_to_execute);
     $deleted = 0;
     $total_dirs = 0;
     if (is_array($dirs) && count($dirs) > 0) {
         foreach ($dirs as $dir) {
             if (is_dir($path_to_test_to_execute . $dir) && $dir != '.' && $dir != '..') {
                 $total_dirs++;
                 $to_print = '  ' . $dir;
                 $dir_mod_time = filemtime($path_to_test_to_execute . $dir);
                 if ($current_time - $dir_mod_time >= $time_for_test_to_execute_to_remain_untouched) {
                     $deleted++;
                     unlink_recursive($path_to_test_to_execute . $dir, TRUE);
                     $to_print .= ':  OLD - deleting' . "\n";
                 } else {
                     $to_print .= ':  SAFE' . "\n";
                 }
                 $this->cli_progress_bar->print_text($to_print, TRUE);
             } else {
                 $this->cli_progress_bar->tick();
             }
         }
     }
     if ($total_dirs == 0) {
         //echo '  No directories ...' . "\n";
         $this->cli_progress_bar->print_text('  No directories ...');
     }
     //echo ' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.' . "\n";
     $this->cli_progress_bar->print_text(' Done, ' . $deleted . ' from ' . $total_dirs . ' directories deleted.');
     $this->cli_progress_bar->increment();
     // ----------- TEST TO EXECUTE DIRECTORIES -----------------------------
     $total_number = 0;
     //echo ' Clearing unfinished uploads of task files:' . "\n";
     $this->cli_progress_bar->print_text(' Clearing unfinished uploads of task files:');
     $deleted = $this->find_and_delete_old_upload_part('private/uploads/task_files/', '', 172800, $current_time, $total_number);
     if ($total_number == 0) {
         //echo '  No files ...' . "\n";
         $this->cli_progress_bar->print_text('  No files ...');
     }
     //echo ' Done, ' . $deleted . ' from ' . $total_number . ' files deleted.' . "\n";
     $this->cli_progress_bar->print_text(' Done, ' . $deleted . ' from ' . $total_number . ' files deleted.');
     $this->cli_progress_bar->increment();
     $this->cli_progress_bar->finish();
     echo 'Done ...' . "\n";
 }
Exemple #13
0
 private function clear_old_directories()
 {
     $path = self::MOSS_WORKING_DIRECTORY;
     $path = ltrim($path, '\\/') . '/';
     $directories = scandir($path);
     $current_time = time();
     if (is_array($directories) && count($directories) > 0) {
         foreach ($directories as $directory) {
             if (is_dir($path . $directory) && $directory != '.' && $directory != '..') {
                 $last_mod_time = filemtime($path . $directory);
                 if ($current_time - $last_mod_time >= self::SECONDS_TO_BE_CONSIDERED_OLD) {
                     unlink_recursive($path . $directory, TRUE);
                 }
             }
         }
     }
 }