original_string: public function archive_to_storage(array $files, $contextid,
              $component, $filearea, $itemid, $filepath, $filename,
              $userid = NULL, $ignoreinvalidfiles=true, file_progress $progress = null) {
          global $CFG;
  
          $fs = get_file_storage();
  
          check_dir_exists($CFG->tempdir.'/zip');
          $tmpfile = tempnam($CFG->tempdir.'/zip', 'zipstor');
  
          if ($result = $this->archive_to_pathname($files, $tmpfile, $ignoreinvalidfiles, $progress)) {
              if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
                  if (!$file->delete()) {
                      @unlink($tmpfile);
                      return false;
                  }
              }
              $file_record = new stdClass();
              $file_record->contextid = $contextid;
              $file_record->component = $component;
              $file_record->filearea  = $filearea;
              $file_record->itemid    = $itemid;
              $file_record->filepath  = $filepath;
              $file_record->filename  = $filename;
              $file_record->userid    = $userid;
              $file_record->mimetype  = 'application/zip';
  
              $result = $fs->create_file_from_pathname($file_record, $tmpfile);
          }
          @unlink($tmpfile);
          return $result;
      }
code: public function archive_to_storage(array $files, $contextid,
              $component, $filearea, $itemid, $filepath, $filename,
              $userid = NULL, $ignoreinvalidfiles=true, file_progress $progress = null) {
          global $CFG;
  
          $fs = get_file_storage();
  
          check_dir_exists($CFG->tempdir.'/zip');
          $tmpfile = tempnam($CFG->tempdir.'/zip', 'zipstor');
  
          if ($result = $this->archive_to_pathname($files, $tmpfile, $ignoreinvalidfiles, $progress)) {
              if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
                  if (!$file->delete()) {
                      @unlink($tmpfile);
                      return false;
                  }
              }
              $file_record = new stdClass();
              $file_record->contextid = $contextid;
              $file_record->component = $component;
              $file_record->filearea  = $filearea;
              $file_record->itemid    = $itemid;
              $file_record->filepath  = $filepath;
              $file_record->filename  = $filename;
              $file_record->userid    = $userid;
              $file_record->mimetype  = 'application/zip';
  
              $result = $fs->create_file_from_pathname($file_record, $tmpfile);
          }
          @unlink($tmpfile);
          return $result;
      }
code_tokens: public function archive_to_storage ( array $ files , $ contextid , $ component , $ filearea , $ itemid , $ filepath , $ filename , $ userid = NULL , $ ignoreinvalidfiles = true , file_progress $ progress = null ) { global $ CFG ; $ fs = get_file_storage ( ) ; check_dir_exists ( $ CFG -> tempdir . '/zip' ) ; $ tmpfile = tempnam ( $ CFG -> tempdir . '/zip' , 'zipstor' ) ; if ( $ result = $ this -> archive_to_pathname ( $ files , $ tmpfile , $ ignoreinvalidfiles , $ progress ) ) { if ( $ file = $ fs -> get_file ( $ contextid , $ component , $ filearea , $ itemid , $ filepath , $ filename ) ) { if ( ! $ file -> delete ( ) ) { @ unlink ( $ tmpfile ) ; return false ; } } $ file_record = new stdClass ( ) ; $ file_record -> contextid = $ contextid ; $ file_record -> component = $ component ; $ file_record -> filearea = $ filearea ; $ file_record -> itemid = $ itemid ; $ file_record -> filepath = $ filepath ; $ file_record -> filename = $ filename ; $ file_record -> userid = $ userid ; $ file_record -> mimetype = 'application/zip' ; $ result = $ fs -> create_file_from_pathname ( $ file_record , $ tmpfile ) ; } @ unlink ( $ tmpfile ) ; return $ result ; }
docstring: Zip files and store the result in file storage.
  
  @param array $files array with full zip paths (including directory information)
  as keys (archivepath=>ospathname or archivepath/subdir=>stored_file or archivepath=>array('content_as_string'))
  @param int $contextid context ID
  @param string $component component
  @param string $filearea file area
  @param int $itemid item ID
  @param string $filepath file path
  @param string $filename file name
  @param int $userid user ID
  @param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
  @param file_progress $progress Progress indicator callback or null if not required
  @return stored_file|bool false if error stored_file instance if ok
docstring_tokens: Zip files and store the result in file storage .