- Issue created by @andrea.cavattoni
- 🇮🇹Italy andrea.cavattoni
I was planning to make a script and create redirects with https://www.drupal.org/project/redirect → to all files in the db in the public folder as I was lookin in the module code and I dont see any redirect functionality.
Please let me know - 🇮🇹Italy andrea.cavattoni
Just made the script, sounds good or should we take a different approach:
//LOAD S3 FILES AND NOT FOLDERS $query = db_select('s3fs_file','sf'); $query->fields('sf'); $query->condition('sf.dir',0); $files = $query->execute()->fetchAll(); foreach($files as $f){ //LOAD LANGUAGE //TODO CHECK DIFFERENT FILE LANGUAGES global $language; //BUILD THE PATH FOR REDIRECT $path = array( 'source' => str_replace('public:/', 'sites/default/files', $f->uri), 'destination' => file_create_url($f->uri), 'language' => $language->language ); //CREATE THE REDIRECT $redirect = new stdClass(); redirect_object_prepare($redirect); $redirect->source = $path['source']; $redirect->redirect = $path['destination']; $redirect->language = $path['language']; //CHECK IF REDIRECT EXISTS $hash = redirect_hash($redirect); $existing = redirect_load_by_hash($hash); if (!$existing) { redirect_save($redirect); } }