function textimage_update_2 in Textimage 6.2
Same name and namespace in other branches
- 5.2 textimage.install \textimage_update_2()
File
- ./
textimage.install, line 115
Code
function textimage_update_2() {
$ret = array();
$schema['textimage_image'] = array(
'fields' => array(
'pid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'file' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'data' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'file',
),
);
db_create_table($ret, 'textimage_image', $schema['textimage_image']);
include_once drupal_get_path('module', 'textimage') . '/textimage_admin.inc';
foreach (textimage_get_presets() as $preset) {
$path = realpath(file_directory_path() . '/textimage/' . $preset->name);
if (is_dir($path)) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($files as $file => $object) {
$file = str_replace($path . '/', '', $file);
$args = explode('/', $file);
$filename = urldecode(array_pop($args));
$additional_text = $args;
preg_match('/\\.([a-z]+)$/i', $filename, $matches);
$format = $matches[1];
if ($format == 'jpg') {
$format = 'jpeg';
}
$text = preg_replace('/\\.([a-z]+)$/i', '', $filename);
db_query("INSERT {textimage_image} (pid, file, data) VALUES (%d, '%s', '%s')", $preset['pid'], file_directory_path() . '/textimage/' . $preset->name . '/' . $file, serialize(array(
'format' => $format,
'text' => $text,
'additional_text' => $additional_text,
)));
}
}
}
return $ret;
}