original_string: public function copy_existing_file($oldfile) {
          if (array_key_exists($oldfile->get_contenthash(), $this->newfilehashes)) {
              return $this->newfilehashes[$oldfile->get_contenthash()];
          }
          $fs = get_file_storage();
          $file_record = $this->new_file_record_base($oldfile->get_filename());
          if ($dir = $this->get('format')->get_file_directory()) {
              $file_record->filepath = '/'. $dir . '/';
          }
          try {
              $newfile = $fs->create_file_from_storedfile($file_record, $oldfile->get_id());
              $this->newfilehashes[$newfile->get_contenthash()] = $newfile;
              return $newfile;
          } catch (file_exception $e) {
              return false;
          }
      }
code: public function copy_existing_file($oldfile) {
          if (array_key_exists($oldfile->get_contenthash(), $this->newfilehashes)) {
              return $this->newfilehashes[$oldfile->get_contenthash()];
          }
          $fs = get_file_storage();
          $file_record = $this->new_file_record_base($oldfile->get_filename());
          if ($dir = $this->get('format')->get_file_directory()) {
              $file_record->filepath = '/'. $dir . '/';
          }
          try {
              $newfile = $fs->create_file_from_storedfile($file_record, $oldfile->get_id());
              $this->newfilehashes[$newfile->get_contenthash()] = $newfile;
              return $newfile;
          } catch (file_exception $e) {
              return false;
          }
      }
code_tokens: public function copy_existing_file ( $ oldfile ) { if ( array_key_exists ( $ oldfile -> get_contenthash ( ) , $ this -> newfilehashes ) ) { return $ this -> newfilehashes [ $ oldfile -> get_contenthash ( ) ] ; } $ fs = get_file_storage ( ) ; $ file_record = $ this -> new_file_record_base ( $ oldfile -> get_filename ( ) ) ; if ( $ dir = $ this -> get ( 'format' ) -> get_file_directory ( ) ) { $ file_record -> filepath = '/' . $ dir . '/' ; } try { $ newfile = $ fs -> create_file_from_storedfile ( $ file_record , $ oldfile -> get_id ( ) ) ; $ this -> newfilehashes [ $ newfile -> get_contenthash ( ) ] = $ newfile ; return $ newfile ; } catch ( file_exception $ e ) { return false ; } }
docstring: Copies a file from somewhere else in moodle
  to the portfolio temporary working directory
  associated with this export
  
  @param stored_file $oldfile existing stored file object
  @return stored_file|bool new file object
docstring_tokens: Copies a file from somewhere else in moodle to the portfolio temporary working directory associated with this export