You are here

function PclZip::duplicate in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/lib/pclzip/pclzip.lib.php \PclZip::duplicate()

File

includes/moodle/lib/pclzip/pclzip.lib.php, line 1169

Class

PclZip

Code

function duplicate($p_archive) {

  //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
  $v_result = 1;

  // ----- Reset the error handler
  $this
    ->privErrorReset();

  // ----- Look if the $p_archive is a PclZip object
  if (is_object($p_archive) && get_class($p_archive) == 'pclzip') {

    //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");

    // ----- Duplicate the archive
    $v_result = $this
      ->privDuplicate($p_archive->zipname);
  }
  else {
    if (is_string($p_archive)) {

      //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");

      // ----- Check that $p_archive is a valid zip file
      // TBC : Should also check the archive format
      if (!is_file($p_archive)) {

        // ----- Error log
        PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '" . $p_archive . "'");
        $v_result = PCLZIP_ERR_MISSING_FILE;
      }
      else {

        // ----- Duplicate the archive
        $v_result = $this
          ->privDuplicate($p_archive);
      }
    }
    else {

      // ----- Error log
      PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
      $v_result = PCLZIP_ERR_INVALID_PARAMETER;
    }
  }

  // ----- Return

  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  return $v_result;
}