You are here

function qformat_blackboard_6::clean_temp_dir in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/question/format/blackboard_6/format.php \qformat_blackboard_6::clean_temp_dir()
1 call to qformat_blackboard_6::clean_temp_dir()
qformat_blackboard_6::importpostprocess in includes/moodle/question/format/blackboard_6/format.php
Override if any post-processing is required

File

includes/moodle/question/format/blackboard_6/format.php, line 40

Class

qformat_blackboard_6

Code

function clean_temp_dir($dir = '') {

  // for now we will just say everything happened okay note
  // that a mess may be piling up in $CFG->dataroot/temp/bbquiz_import
  // TODO return true at top of the function renders all the following code useless
  return true;
  if ($dir == '') {
    $dir = $this->temp_dir;
  }
  $slash = "/";

  // Create arrays to store files and directories
  $dir_files = array();
  $dir_subdirs = array();

  // Make sure we can delete it
  chmod($dir, 0777);
  if (($handle = opendir($dir)) == FALSE) {

    // The directory could not be opened
    return false;
  }

  // Loop through all directory entries, and construct two temporary arrays containing files and sub directories
  while (false !== ($entry = readdir($handle))) {
    if (is_dir($dir . $slash . $entry) && $entry != ".." && $entry != ".") {
      $dir_subdirs[] = $dir . $slash . $entry;
    }
    else {
      if ($entry != ".." && $entry != ".") {
        $dir_files[] = $dir . $slash . $entry;
      }
    }
  }

  // Delete all files in the curent directory return false and halt if a file cannot be removed
  for ($i = 0; $i < count($dir_files); $i++) {
    chmod($dir_files[$i], 0777);
    if (unlink($dir_files[$i]) == FALSE) {
      return false;
    }
  }

  // Empty sub directories and then remove the directory
  for ($i = 0; $i < count($dir_subdirs); $i++) {
    chmod($dir_subdirs[$i], 0777);
    if ($this
      ->clean_temp_dir($dir_subdirs[$i]) == FALSE) {
      return false;
    }
    else {
      if (rmdir($dir_subdirs[$i]) == FALSE) {
        return false;
      }
    }
  }

  // Close directory
  closedir($handle);
  if (rmdir($this->temp_dir) == FALSE) {
    return false;
  }

  // Success, every thing is gone return true
  return true;
}