function _filefield_paths_create_redirect in File (Field) Paths 7
Same name and namespace in other branches
- 8 filefield_paths.module \_filefield_paths_create_redirect()
Creates a redirect for a moved File field.
Parameters
$source:
$path:
Throws
Exception
1 call to _filefield_paths_create_redirect()
- filefield_paths_filefield_paths_process_file in modules/
filefield_paths.inc - Implements hook_filefield_paths_process_file().
File
- ./
filefield_paths.module, line 382 - Contains core functions for the File (Field) Paths module.
Code
function _filefield_paths_create_redirect($source, $path) {
global $base_path;
watchdog('filefield_paths', 'Creating redirect from @source to @path', array(
'@source' => $source,
'@path' => $path,
), WATCHDOG_DEBUG);
$redirect = new stdClass();
redirect_object_prepare($redirect);
$parsed_source = parse_url(file_create_url($source), PHP_URL_PATH);
$parsed_path = parse_url(file_create_url($path), PHP_URL_PATH);
$redirect->source = drupal_substr(urldecode($parsed_source), drupal_strlen($base_path));
$redirect->redirect = drupal_substr(urldecode($parsed_path), drupal_strlen($base_path));
// Check if the redirect exists before saving.
$hash = redirect_hash($redirect);
if (!redirect_load_by_hash($hash)) {
redirect_save($redirect);
}
}