View source
<?php
function image_schema() {
$schema['image'] = array(
'description' => 'Stores image files information.',
'fields' => array(
'nid' => array(
'description' => 'Primary Key: The {node}.nid of the image node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'fid' => array(
'description' => 'Index: The {files}.fid of the image file.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'image_size' => array(
'description' => 'Primary Key: The {files}.filename of the image file. For image module this indicates the file size.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'nid',
'image_size',
),
'indexes' => array(
'fid' => array(
'fid',
),
),
);
return $schema;
}
function image_install() {
drupal_install_schema('image');
variable_set('node_options_image', array(
'status',
));
}
function image_uninstall() {
drupal_uninstall_schema('image');
variable_del('image_max_upload_size');
variable_del('image_updated');
variable_del('image_default_path');
variable_del('image_sizes');
variable_del('image_block_0_number_images');
variable_del('image_block_1_number_images');
}
function image_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
if ($toolkit = image_get_toolkit()) {
$requirements['image_toolkit'] = array(
'value' => t('The %toolkit_name toolkit is installed.', array(
'%toolkit_name' => $toolkit,
)),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['image_toolkit'] = array(
'value' => t('Not installed.'),
'severity' => REQUIREMENT_ERROR,
'description' => t('No image toolkit is currently enabled. Without one the image module will not be able to resize your images. You can select one from the <a href="@link">image toolkit settings page</a>.', array(
'@link' => url('admin/settings/image-toolkit'),
)),
);
}
$requirements['image_toolkit']['title'] = t('Image toolkit');
$image_path = file_create_path(file_directory_path() . '/' . variable_get('image_default_path', 'images'));
$temp_path = $image_path . '/temp';
if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY)) {
$requirements['image_dirs'] = array(
'value' => t('Missing directory.'),
'severity' => REQUIREMENT_ERROR,
'description' => t("The image module's image directory %image_dir is missing.", array(
'%image_dir' => $image_path,
)),
);
}
else {
if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY)) {
$requirements['image_dirs'] = array(
'value' => t('Missing temp directory.'),
'severity' => REQUIREMENT_ERROR,
'description' => t("The image module's temp directory %temp_dir is missing.", array(
'%temp_dir' => $temp_path,
)),
);
}
else {
$requirements['image_dirs'] = array(
'value' => t('Exists (%path).', array(
'%path' => $image_path,
)),
'severity' => REQUIREMENT_OK,
);
}
}
$requirements['image_dirs']['title'] = t('Image module directories');
}
return $requirements;
}
function image_update_2() {
$sizes = variable_get('image_sizes', FALSE);
if ($sizes) {
$new_sizes = array(
IMAGE_ORIGINAL => array(
'width' => '',
'height' => '',
'label' => t('Original'),
),
);
foreach ($sizes as $size) {
$key = drupal_strtolower($size['label']);
$size['label'] = drupal_ucfirst($size['label']);
$new_sizes[$key] = $size;
}
variable_set('image_sizes', $new_sizes);
}
return array();
}
function image_update_3() {
$sizes = variable_get('image_sizes', FALSE);
if ($sizes) {
$new_sizes = array();
foreach ($sizes as $key => $size) {
$size['link'] = 1;
$new_sizes[$key] = $size;
}
variable_set('image_sizes', $new_sizes);
}
return array();
}
function image_update_4() {
$ret = array();
$files_path = rtrim(file_directory_path(), '\\/');
$result = db_query("SELECT f.nid, f.fid, f.filename, f.filepath FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type = 'image' AND f.filename = '_original' AND NOT f.filepath LIKE '%s/%%'", $files_path);
while ($file = db_fetch_object($result)) {
$file->filepath = file_create_path($file->filepath);
if (file_exists($file->filepath)) {
if (db_result(db_query("SELECT COUNT(*) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type = 'image' AND filepath = '%s' AND fid <> %d", $file->filepath, $file->fid))) {
$ret[] = update_sql("DELETE FROM {files} WHERE fid = " . (int) $file->fid);
$ret[] = update_sql("DELETE FROM {file_revisions} WHERE fid = " . (int) $file->fid);
}
else {
$ret[] = update_sql("UPDATE {files} SET filepath = '" . db_escape_string($file->filepath) . "' WHERE fid = " . (int) $file->fid);
}
}
else {
$ret[] = update_sql("DELETE FROM {files} WHERE fid = " . (int) $file->fid);
$ret[] = update_sql("DELETE FROM {file_revisions} WHERE fid = " . (int) $file->fid);
}
}
$result = db_query("SELECT f1.fid, f1.nid, f1.filepath FROM {files} f1 INNER JOIN {node} n ON f1.nid = n.nid WHERE n.type = 'image' AND EXISTS ( SELECT * FROM {files} f2 WHERE f2.filepath = f1.filepath AND f1.fid <> f2.fid AND f1.fid < f2.fid )");
while ($file = db_fetch_object($result)) {
$ret[] = update_sql("DELETE FROM {files} WHERE fid = " . (int) $file->fid);
}
$ret[] = update_sql("DELETE FROM {file_revisions} WHERE NOT EXISTS (SELECT * FROM {files} WHERE {files}.fid = {file_revisions}.fid)");
return $ret;
}
function image_update_5() {
$ret = array();
if ($old_sizes = variable_get('image_sizes', FALSE)) {
if (!isset($old_sizes[IMAGE_ORIGINAL])) {
drupal_set_message(t("The original image size was missing so no changes were made. See this <a href='@link'>image module issue</a> for more information. Include the following:<br /><pre>@old_sizes\n</pre>", array(
'@link' => 'http://drupal.org/node/158334',
'@old_sizes' => print_r($old_sizes, 1),
)), 'error');
return array();
}
if (!isset($old_sizes[IMAGE_PREVIEW])) {
$old_sizes[IMAGE_PREVIEW] = array(
'width' => 640,
'height' => 640,
'label' => t('Preview'),
'link' => IMAGE_LINK_SHOWN,
);
}
if (!isset($old_sizes[IMAGE_THUMBNAIL])) {
$old_sizes[IMAGE_THUMBNAIL] = array(
'width' => 100,
'height' => 100,
'label' => t('Thumbnail'),
'link' => IMAGE_LINK_SHOWN,
);
}
$new_sizes = array();
foreach ($old_sizes as $old_key => $size) {
$new_key = drupal_strtolower(drupal_substr($old_key, 0, 32));
if ($new_key != $old_key) {
$ret[] = update_sql("UPDATE {files} f INNER JOIN {node} n ON f.nid = n.nid SET f.filename = '" . db_escape_string($new_key) . "' WHERE n.type = 'image' AND filename = '" . db_escape_string($old_key) . "'");
}
$new_sizes[$new_key] = $size;
}
variable_set('image_sizes', $new_sizes);
}
return $ret;
}
function image_update_5200() {
$ret = array();
if (db_table_exists('image')) {
db_rename_table($ret, 'image', 'image_old');
drupal_set_message('Your existing {image} table has been renamed {image_old}.');
}
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE {image} (\n `nid` INTEGER UNSIGNED NOT NULL,\n `fid` INTEGER UNSIGNED NOT NULL,\n `image_size` VARCHAR(32) NOT NULL,\n PRIMARY KEY (`nid`, `image_size`),\n INDEX image_fid(`fid`)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {image} (\n nid int_unsigned NOT NULL,\n fid int_unsigned NOT NULL,\n image_size VARCHAR(32) NOT NULL,\n PRIMARY KEY (nid, image_size)\n );");
$ret[] = update_sql("CREATE INDEX {image_fid} on {image}(fid);");
break;
}
drupal_load('module', 'image');
$args = array_map('db_escape_string', array_keys(image_get_sizes()));
$cond = " IN ('" . implode("', '", $args) . "')";
if (db_table_exists('file_revisions')) {
$ret[] = update_sql("INSERT IGNORE INTO {image} SELECT DISTINCT f.nid, f.fid, f.filename FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type = 'image' AND f.filename" . $cond);
$ret[] = update_sql("DELETE FROM {file_revisions} WHERE EXISTS (SELECT * FROM {image} WHERE {image}.fid = {file_revisions}.fid)");
}
else {
$ret[] = update_sql("INSERT IGNORE INTO {image} SELECT DISTINCT u.nid, f.fid, f.filename FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid INNER JOIN {node} n ON u.nid = n.nid WHERE n.type = 'image' AND f.filename" . $cond);
$ret[] = update_sql("DELETE FROM {upload} WHERE EXISTS (SELECT * FROM {image} WHERE {image}.fid = {upload}.fid)");
}
return $ret;
}
function image_update_5201() {
drupal_load('module', 'image');
$sizes = image_get_sizes();
foreach ($sizes as $key => $size) {
$sizes[$key]['operation'] = 'scale';
}
variable_set('image_sizes', $sizes);
return array();
}
function image_update_6100() {
$ret = array();
db_change_field($ret, 'image', 'nid', 'nid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_change_field($ret, 'image', 'fid', 'fid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
@db_drop_primary_key($ret, 'image');
db_add_primary_key($ret, 'image', array(
'nid',
'image_size',
));
@db_drop_index($ret, 'image', 'image_fid');
db_add_index($ret, 'image', 'fid', array(
'fid',
));
$ret[] = array(
'success' => TRUE,
'query' => t('You can safely ignore the error message "Failed: ALTER TABLE {image} DROP PRIMARY KEY" or "DROP INDEX image_fid".'),
);
return $ret;
}
function image_update_6101() {
$ret = array();
$path = variable_get('image_default_path', NULL);
if (!empty($path)) {
variable_set('image_default_path', rtrim($path, '/'));
}
return $ret;
}
function image_update_6102() {
$ret = array();
variable_set('node_options_image', variable_get('node_options_image', array(
'status',
)));
return $ret;
}
function image_update_6103() {
$ret = array();
$result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
while ($role = db_fetch_object($result)) {
$renamed_permission = strtr($role->perm, array(
'edit images' => 'edit any images, delete any images',
'edit own images' => 'edit own images, delete own images',
));
if ($renamed_permission != $role->perm) {
$args = array(
$renamed_permission,
$role->rid,
);
$query = "UPDATE {permission} SET perm = '%s' WHERE rid = %d";
_db_query_callback($args, TRUE);
$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
$ret[] = update_sql($query);
}
}
return $ret;
}
function image_update_6104() {
$ret = array();
db_drop_primary_key($ret, 'image');
db_change_field($ret, 'image', 'image_size', 'image_size', array(
'description' => 'Primary Key: The {files}.filename of the image file. For image module this indicates the file size.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
), array(
'primary key' => array(
'nid',
'image_size',
),
));
return $ret;
}