transliteration.install in Transliteration 6.2
Install, update, and uninstall functions for the transliteration module.
File
transliteration.install
View source
<?php
define('TRANSLITERATION_RETROACTIVE', FALSE);
function transliteration_install() {
if (TRANSLITERATION_RETROACTIVE) {
transliteration_install_retroactive();
}
else {
$t = get_t();
drupal_set_message($t('Existing filenames have not been transliterated.'));
}
}
function transliteration_uninstall() {
}
function transliteration_install_retroactive() {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
$t = get_t();
$errors = array();
$query = "SELECT fid, filepath FROM {files} WHERE filepath ";
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$query .= "REGEXP '[^0-9a-z_./-]'";
break;
case 'pgsql':
$query .= "~* '[^0-9a-z_./-]'";
break;
case 'mssql':
$query .= "LIKE '%[^0-9A-Za-z_./-]%'";
break;
default:
drupal_set_message($t('Filenames could not be transliterated: database type not supported.'), 'error');
return;
}
$result = db_query($query);
while ($file = db_fetch_object($result)) {
$transliterated = dirname($file->filepath) . '/' . transliteration_clean_filename(basename($file->filepath));
if ($transliterated == $file->filepath) {
continue;
}
if (realpath($file->filepath) && file_move($file->filepath, $transliterated, FILE_EXISTS_RENAME)) {
$transliterated = $file->filepath;
db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $transliterated, $file->fid);
}
else {
$errors[] = $file->filepath;
}
}
if ($errors) {
$message = $t('Not all existing filenames could be transliterated. The following files could not be accessed:');
$message .= theme_item_list($errors);
drupal_set_message($message, 'error');
}
else {
drupal_set_message($t('Existing filenames have been successfully transliterated.'));
}
}
function transliteration_update_1() {
$ret = array();
if (TRANSLITERATION_RETROACTIVE) {
transliteration_install_retroactive();
}
else {
$t = get_t();
drupal_set_message($t('Existing filenames have not been transliterated.'));
}
return $ret;
}
Functions
Constants
Name |
Description |
TRANSLITERATION_RETROACTIVE |
Whether to perform retroactive transliteration of existing files.
Since this might break hard-coded links to files in content, it is disabled
by default. Set to TRUE to enable. |