original_string: public static function copy_file_moodle2backup($backupid, $filerecorid) {
          global $DB;
  
          if (!backup_controller_dbops::backup_includes_files($backupid)) {
              // Only include the files if required by the controller.
              return;
          }
  
          // Normalise param
          if (!is_object($filerecorid)) {
              $filerecorid = $DB->get_record('files', array('id' => $filerecorid));
          }
  
          // Directory, nothing to do
          if ($filerecorid->filename === '.') {
              return;
          }
  
          $fs = get_file_storage();
          $file = $fs->get_file_instance($filerecorid);
          // If the file is external file, skip copying.
          if ($file->is_external_file()) {
              return;
          }
  
          // Calculate source and target paths (use same subdirs strategy for both)
          $targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' .
                            self::get_backup_content_file_location($filerecorid->contenthash);
  
          // Create target dir if necessary
          if (!file_exists(dirname($targetfilepath))) {
              if (!check_dir_exists(dirname($targetfilepath), true, true)) {
                  throw new backup_helper_exception('cannot_create_directory', dirname($targetfilepath));
              }
          }
  
          // And copy the file (if doesn't exist already)
          if (!file_exists($targetfilepath)) {
              $file->copy_content_to($targetfilepath);
          }
      }
code: public static function copy_file_moodle2backup($backupid, $filerecorid) {
          global $DB;
  
          if (!backup_controller_dbops::backup_includes_files($backupid)) {
              // Only include the files if required by the controller.
              return;
          }
  
          // Normalise param
          if (!is_object($filerecorid)) {
              $filerecorid = $DB->get_record('files', array('id' => $filerecorid));
          }
  
          // Directory, nothing to do
          if ($filerecorid->filename === '.') {
              return;
          }
  
          $fs = get_file_storage();
          $file = $fs->get_file_instance($filerecorid);
          // If the file is external file, skip copying.
          if ($file->is_external_file()) {
              return;
          }
  
          // Calculate source and target paths (use same subdirs strategy for both)
          $targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' .
                            self::get_backup_content_file_location($filerecorid->contenthash);
  
          // Create target dir if necessary
          if (!file_exists(dirname($targetfilepath))) {
              if (!check_dir_exists(dirname($targetfilepath), true, true)) {
                  throw new backup_helper_exception('cannot_create_directory', dirname($targetfilepath));
              }
          }
  
          // And copy the file (if doesn't exist already)
          if (!file_exists($targetfilepath)) {
              $file->copy_content_to($targetfilepath);
          }
      }
code_tokens: public static function copy_file_moodle2backup ( $ backupid , $ filerecorid ) { global $ DB ; if ( ! backup_controller_dbops :: backup_includes_files ( $ backupid ) ) { // Only include the files if required by the controller. return ; } // Normalise param if ( ! is_object ( $ filerecorid ) ) { $ filerecorid = $ DB -> get_record ( 'files' , array ( 'id' => $ filerecorid ) ) ; } // Directory, nothing to do if ( $ filerecorid -> filename === '.' ) { return ; } $ fs = get_file_storage ( ) ; $ file = $ fs -> get_file_instance ( $ filerecorid ) ; // If the file is external file, skip copying. if ( $ file -> is_external_file ( ) ) { return ; } // Calculate source and target paths (use same subdirs strategy for both) $ targetfilepath = self :: get_backup_storage_base_dir ( $ backupid ) . '/' . self :: get_backup_content_file_location ( $ filerecorid -> contenthash ) ; // Create target dir if necessary if ( ! file_exists ( dirname ( $ targetfilepath ) ) ) { if ( ! check_dir_exists ( dirname ( $ targetfilepath ) , true , true ) ) { throw new backup_helper_exception ( 'cannot_create_directory' , dirname ( $ targetfilepath ) ) ; } } // And copy the file (if doesn't exist already) if ( ! file_exists ( $ targetfilepath ) ) { $ file -> copy_content_to ( $ targetfilepath ) ; } }
docstring: Copy one file from moodle storage to backup storage
docstring_tokens: Copy one file from moodle storage to backup storage