- 🇫🇷France gilbertdelyon
This thread is exactly what I need.
But of course it does not work in DRUPAL 10. (deprecated functions)
Would somebody be so kind to help me finding how to code this in D10?Thanks in advance
- 🇫🇷France gilbertdelyon
I have added this this piece of code in a controller in D10.
May be there is simpler way, but It works!private function updatevideoFilesize(){ // ftech video files in file_managed table $db = \Drupal::service('database'); $query = $db->select('file_managed', 't')->fields('t', ['fid','uri', 'filesize']); $query->condition('filemime', "video%", 'LIKE'); $videofiles = $query->execute()->fetchAll(); // variable to be filled with processing reports during the loop $output = ''; // Loop through the files foreach ($videofiles as $file) { //$output.= 'fid = '.$file->fid.' | uri = '.$file->uri.' | sizeBEFORE = '.$file->filesize.'<br/>'; //debug //Load the file entity by URI $loadedfile = \Drupal::entityTypeManager() ->getStorage('file') ->loadByProperties(['uri' => $file->uri]); // Check if the file entity was loaded successfully. //$output.= $loadedfile ? 'successfull load YES <br/>': 'successfull load NO<br/>';//debug // Get real file size $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')->getViaUri($file->uri); $file_path = $stream_wrapper_manager->realpath(); $realFileSize = filesize($file_path); if($realFileSize != $file->filesize){ //$output.= $file_path.' | realSIZE = '. $realFileSize.'<hr/>'; //debug // Store real size of file $query = $db->update('file_managed')->fields(['filesize'=>$realFileSize] ); $query->condition ('fid',$file->fid,'='); $query->execute(); $output .= 'fid = '.$file->fid.' | uri = '.$file->uri.'<br/>'; $output .= 'former size = '.$file->filesize.' | new size = '.$realFileSize.'<hr/>'; }//end if } //end foreach $output = ($output =='')? 'No filesize to be updated' : 'Following filesizes have been uptdated.<hr/>'.$output; return $output; }//fin function