function _migrate_files_to_imagefields in Node Gallery 6.3
1 call to _migrate_files_to_imagefields()
- node_gallery_update_6300 in ./
node_gallery.install - MAJOR UPGRADE - please don't blindly update from 2.x to 3.x! Your data will migrate, but some of your settings and most of your theming will need to be redone.
File
- ./
node_gallery.install, line 191 - Install, update and uninstall functions for the node_gallery module.
Code
function _migrate_files_to_imagefields() {
$total = db_result(db_query('SELECT COUNT(nid) FROM {node_galleries}'));
// first, select nid, fid from node_galleries
$result = db_query('SELECT nid, fid FROM {node_galleries}');
// upgrade the node
$count = 0;
while ($r = db_fetch_array($result)) {
$count++;
if ($count % 50 == 0) {
// Make sure we don't run out of memory by clearing the cache.
$image = node_load(NULL, NULL, TRUE);
}
$image = node_load($r['nid']);
$file = db_fetch_array(db_query('SELECT fid, uid, filename, filepath, filemime, filesize, status, timestamp FROM {files} WHERE fid = %d', $r['fid']));
$image->field_node_gallery_image[0] = $file;
$image->field_node_gallery_image[0]['data'] = array(
'alt' => $image->title,
'title' => $image->title,
);
$image->field_node_gallery_image[0]['origname'] = $file['filename'];
$image->field_node_gallery_image[0]['list'] = 1;
node_save($image);
db_query('DELETE FROM {node_galleries} WHERE nid = %d', $image->nid);
}
drupal_set_message(t('Upgraded !number total images to imagefield.', array(
'!number' => $total,
)));
}