View source
<?php
function imagefield_install() {
}
function imagefield_update_1() {
$ret = array();
include_once drupal_get_path('module', 'content') . '/content.module';
include_once drupal_get_path('module', 'content') . '/content_admin.inc';
$fields = content_fields();
foreach ($fields as $field) {
switch ($field['type']) {
case 'file':
$columns = array(
'list' => array(
'type' => 'int',
'not null' => TRUE,
'default' => '0',
),
);
content_alter_db_field(array(), array(), $field, $columns);
break;
}
}
db_query('DELETE FROM {cache}');
return $ret;
}
function imagefield_update_2() {
$ret = array();
include_once drupal_get_path('module', 'content') . '/content.module';
include_once drupal_get_path('module', 'content') . '/content_admin.inc';
$fields = content_fields();
foreach ($fields as $field) {
switch ($field['type']) {
case 'image':
$oldcolumns = array(
'fid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => '0',
),
);
$newcolumns = array(
'fid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => '0',
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => "''",
'sortable' => TRUE,
),
'alt' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => "''",
'sortable' => TRUE,
),
);
content_alter_db_field($field, $oldcolumns, $field, $newcolumns);
break;
}
drupal_set_message('altered: <br /><pre>' . print_r($field, true) . '</pre>');
}
db_query('DELETE FROM {cache}');
return $ret;
}
function imagefield_update_3() {
return array();
}
function imagefield_update_4() {
$ret = array();
include_once drupal_get_path('module', 'content') . '/content.module';
include_once drupal_get_path('module', 'content') . '/content_admin.inc';
$result = db_query("SELECT field_name, type_name, display_settings FROM {node_field_instance} WHERE widget_type = 'image'");
while ($row = db_fetch_array($result)) {
$needs_update = FALSE;
$display_settings = unserialize($row['display_settings']);
foreach (_content_admin_display_contexts() as $context) {
if ($display_settings[$context]['format'] == 'imagefield_default' || empty($display_settings[$context]['format'])) {
$display_settings[$context]['format'] = 'default';
$needs_update = TRUE;
}
}
if ($needs_update) {
db_query("UPDATE {node_field_instance} SET display_settings = '%s' WHERE type_name = '%s' AND field_name = '%s'", serialize($display_settings), $row['type_name'], $row['field_name']);
}
}
content_clear_type_cache();
return $ret;
}
function imagefield_update_5() {
$ret = array();
$fields = content_fields();
foreach ($fields as $field) {
if ($field['type'] == 'image') {
$db_info = content_database_info($field);
if (isset($db_info['columns']['fid'])) {
$table = $db_info['table'];
$column = $db_info['columns']['fid']['column'];
$ret[] = update_sql("UPDATE {" . $table . "} SET {$column} = 0 WHERE {$column} NOT IN (SELECT fid FROM {files})");
}
}
}
return $ret;
}