original_string: public static function move_to_filepool($thefile, $record) {
          global $DB, $CFG, $USER, $OUTPUT;
  
          // scan for viruses if possible, throws exception if problem found
          // TODO: MDL-28637 this repository_no_delete is a bloody hack!
          \core\antivirus\manager::scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
  
          $fs = get_file_storage();
          // If file name being used.
          if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) {
              $draftitemid = $record->itemid;
              $new_filename = repository::get_unused_filename($draftitemid, $record->filepath, $record->filename);
              $old_filename = $record->filename;
              // Create a tmp file.
              $record->filename = $new_filename;
              $newfile = $fs->create_file_from_pathname($record, $thefile);
              $event = array();
              $event['event'] = 'fileexists';
              $event['newfile'] = new stdClass;
              $event['newfile']->filepath = $record->filepath;
              $event['newfile']->filename = $new_filename;
              $event['newfile']->url = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $new_filename)->out();
  
              $event['existingfile'] = new stdClass;
              $event['existingfile']->filepath = $record->filepath;
              $event['existingfile']->filename = $old_filename;
              $event['existingfile']->url      = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $old_filename)->out();
              return $event;
          }
          if ($file = $fs->create_file_from_pathname($record, $thefile)) {
              if (empty($CFG->repository_no_delete)) {
                  $delete = unlink($thefile);
                  unset($CFG->repository_no_delete);
              }
              return array(
                  'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(),
                  'id'=>$file->get_itemid(),
                  'file'=>$file->get_filename(),
                  'icon' => $OUTPUT->image_url(file_extension_icon($thefile, 32))->out(),
              );
          } else {
              return null;
          }
      }
code: public static function move_to_filepool($thefile, $record) {
          global $DB, $CFG, $USER, $OUTPUT;
  
          // scan for viruses if possible, throws exception if problem found
          // TODO: MDL-28637 this repository_no_delete is a bloody hack!
          \core\antivirus\manager::scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
  
          $fs = get_file_storage();
          // If file name being used.
          if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) {
              $draftitemid = $record->itemid;
              $new_filename = repository::get_unused_filename($draftitemid, $record->filepath, $record->filename);
              $old_filename = $record->filename;
              // Create a tmp file.
              $record->filename = $new_filename;
              $newfile = $fs->create_file_from_pathname($record, $thefile);
              $event = array();
              $event['event'] = 'fileexists';
              $event['newfile'] = new stdClass;
              $event['newfile']->filepath = $record->filepath;
              $event['newfile']->filename = $new_filename;
              $event['newfile']->url = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $new_filename)->out();
  
              $event['existingfile'] = new stdClass;
              $event['existingfile']->filepath = $record->filepath;
              $event['existingfile']->filename = $old_filename;
              $event['existingfile']->url      = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $old_filename)->out();
              return $event;
          }
          if ($file = $fs->create_file_from_pathname($record, $thefile)) {
              if (empty($CFG->repository_no_delete)) {
                  $delete = unlink($thefile);
                  unset($CFG->repository_no_delete);
              }
              return array(
                  'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(),
                  'id'=>$file->get_itemid(),
                  'file'=>$file->get_filename(),
                  'icon' => $OUTPUT->image_url(file_extension_icon($thefile, 32))->out(),
              );
          } else {
              return null;
          }
      }
code_tokens: public static function move_to_filepool ( $ thefile , $ record ) { global $ DB , $ CFG , $ USER , $ OUTPUT ; // scan for viruses if possible, throws exception if problem found // TODO: MDL-28637 this repository_no_delete is a bloody hack! \ core \ antivirus \ manager :: scan_file ( $ thefile , $ record -> filename , empty ( $ CFG -> repository_no_delete ) ) ; $ fs = get_file_storage ( ) ; // If file name being used. if ( repository :: draftfile_exists ( $ record -> itemid , $ record -> filepath , $ record -> filename ) ) { $ draftitemid = $ record -> itemid ; $ new_filename = repository :: get_unused_filename ( $ draftitemid , $ record -> filepath , $ record -> filename ) ; $ old_filename = $ record -> filename ; // Create a tmp file. $ record -> filename = $ new_filename ; $ newfile = $ fs -> create_file_from_pathname ( $ record , $ thefile ) ; $ event = array ( ) ; $ event [ 'event' ] = 'fileexists' ; $ event [ 'newfile' ] = new stdClass ; $ event [ 'newfile' ] -> filepath = $ record -> filepath ; $ event [ 'newfile' ] -> filename = $ new_filename ; $ event [ 'newfile' ] -> url = moodle_url :: make_draftfile_url ( $ draftitemid , $ record -> filepath , $ new_filename ) -> out ( ) ; $ event [ 'existingfile' ] = new stdClass ; $ event [ 'existingfile' ] -> filepath = $ record -> filepath ; $ event [ 'existingfile' ] -> filename = $ old_filename ; $ event [ 'existingfile' ] -> url = moodle_url :: make_draftfile_url ( $ draftitemid , $ record -> filepath , $ old_filename ) -> out ( ) ; return $ event ; } if ( $ file = $ fs -> create_file_from_pathname ( $ record , $ thefile ) ) { if ( empty ( $ CFG -> repository_no_delete ) ) { $ delete = unlink ( $ thefile ) ; unset ( $ CFG -> repository_no_delete ) ; } return array ( 'url' => moodle_url :: make_draftfile_url ( $ file -> get_itemid ( ) , $ file -> get_filepath ( ) , $ file -> get_filename ( ) ) -> out ( ) , 'id' => $ file -> get_itemid ( ) , 'file' => $ file -> get_filename ( ) , 'icon' => $ OUTPUT -> image_url ( file_extension_icon ( $ thefile , 32 ) ) -> out ( ) , ) ; } else { return null ; } }
docstring: Move file from download folder to file pool using FILE API
  
  @todo MDL-28637
  @static
  @param string $thefile file path in download folder
  @param stdClass $record
  @return array containing the following keys:
  icon
  file
  id
  url
docstring_tokens: Move file from download folder to file pool using FILE API