After trying 6.x-3.0-alpha1 I'd like to migrate a Drupal website with a quite large number of users and their pictures (nodes of Image type) in Acidfree albums to Node Gallery. However, some issues which definitely will occur during such a migration make me reluctant from starting the process and I would love to hear the module maintainer's and user's opinion.

I think fo the following sequence of steps:

1. Migrate nodes of Image type to nodes with imagefields following #201983: How To: Migrate from Image.module to ImageField Documentation Project;
2. Activate Node Gallery module;
3. Delete Gallery Image node type leaving Gallery node type in tact;
4. Add new relationship on 'admin/settings/node_gallery' for Image node type (with imagefield as per step 1) to attribute it as Image type.

But I am not sure if this way will work out successfully because of two issues:

1. How to migrate per user galleries in Acidfree to Node Gallery?
2. Will Node Gallery pick up previously added images or it deals only with new pictures?

Thank you for your attention.

Comments

scroogie’s picture

It will require custom code to create gallery nodes and to attach the image nodes to these. You'll have to traverse the gallery taxonomy vocabulary and create a node for every term, as well as "register" the nodes to these gallery nodes afterwards.

If you want, and are willing to invest some time yourself, we can try to build some code together in this issue. At some point, I'll migrate one of my existing sites to NG3 from image.module, and will need similar code as well.

One additional problem would be that gallery hierarchies are only planned for NG 3.1.

justintime’s picture

I've never used Acidfree, but I have something that may be of help.

I've a views_bulk_operations junkie, and since I'm the maintainer, I made sure that NG3 worked with it. In NG3, we expose an action that can assign images to galleries. So, if you can come up with a way to isolate images using VBO's filters, then you can do this all via the gui.

However, this sounds like it would be a pretty quick and easy drush script. Once the gallery and image types are part of a relationship, nodeapi takes care of the rest. POC code:

$acidfree_gallery_nids = get_acidfree_gallery_nids();
foreach ($acidfree_gallery_nids as $afnid) {
  $gallery = new stdClass;
  $gallery->gid = $afnid;
  // create the row in node_gallery_galleries
  drupal_write_record('node_gallery_galleries', $gallery);
  node_save($gallery);
  $image_nids = get_acidfree_image_nids($afnid);
  foreach ($image_nids as $image_nid) {
    $image = node_load($image_nid);
    $image->gid = $afnid;
    node_save($image);
  }
}

That's all you need to do to build the linkage between gallery and image, but obviously the bulk of the work is in the unwritten get_acidfree_gallery_nids() and get_acidfree_image_nids() functions. If you have a truly large number of images and galleries, I would definitely run this via 'drush scr' so you don't run into execution time issues.

BTW: you're Andy, right?

yngens’s picture

scroogie, for the sake of making this work for more general purpose let's simplify my sequence and ignore Acdifree albums. Let's try to build a migration path from Images to Imgefields to make them Node Gallery images. If I understand right, then answer to my second question (if Node Gallery will pick up previously added images) is negative, because, as you've put, it should "register" the nodes to gallery nodes, isn't it?

I'll do my best, however I'm not a coder, so would love to get some help here.

justintime, never used drush, but for the sake of solving this issue could learn using it. However, I'm afraid I can't build those get_acidfree_gallery_nids() and get_acidfree_image_nids() functions. Not Andy.

justintime’s picture

Here's those functions, and a script to boot: http://pastebin.com/0L8RcZmC

scroogie can help you with the image.module to imagefield migration, since he needs to do it anyway. Here's the basics of what you'd do:

1) Install Node Gallery, leave the defaults.
2) Run the script above.
3) Run scroogie's script to convert images to imagefield
4) Uninstall the Acidfree module
5) Enjoy

I didn't test that script above, so please don't even attempt with it until you are working on a development copy of your live site.

To run it, download and install drush according to the docs. Change to your drupal install root, and place the script linked above in a file named acidfree_migrate.php. Then run 'drush scr acidfree_migrate'.

scroogie’s picture

The script needs some more work to retrieve the title of the gallery, author, etc. I think you should start with acidfree_get_vocab_id() and then taxonomy_get_term() your way through the galleries. I used acidfree only in Drupal 5, quite some time ago.

yngens’s picture

Thank you guys,

Using #201983: How To: Migrate from Image.module to ImageField Documentation Project I have successfully migrated all the Images on my site to ImageFields. All the album names are converted to taxonomy term names. So now the task is little bit different for me.

I need to 1) turn taxonomy names into Node Gallery albums and 2) make Node Galleries to register all the nodes with imagefields. So not to confuse, if any of the above scripts still applicable, which of them would help me to solve which task?

justintime’s picture

Well, that's good progress. Next step, create the gallery nodes.

Try using http://drupal.org/project/taxonomy_node to create a node_gallery_gallery node for each of your terms.

Post back whether that succeeds or not. If it works, then it should be a pretty simple script to get the images into the galleries.

yngens’s picture

justintime, it has worked, however all the taxonomy terms have been associated with user #1. trying to attribute them back to their owners. unfortunately taxonomy_node module just creates nodes without attributing associated taxonomy terms at the same time. if it did then now would be peace of cake to go through images and bind each of them to associated gallery. what would be the next step?

yngens’s picture

On admin/settings/node_gallery/relationship/content_types/1 wanted to change only the content type to Image type, but it did not let me to, giving the error: "The node_gallery_gallery type is already part of a relationship." So I deleted and re-created the relationship, but now on attempt to edit an image node and assign it to a gallery, it gives "Unable to find a navigator image sort view. Please revisit your node gallery relationship settings." and fails to assign to any gallery. Revisiting settings page does not help.

justintime’s picture

Okay, wrt "The node_gallery_gallery type is already part of a relationship.", that was a validation bug that I've fixed in dev.

As for your problem in saving, I'm not for sure where the problem is at. Can you give me:
1) The content types in your relationship
2) The content type of the image you're editing
3) What user you're editing the image with
4) The title of the gallery you're selecting in the "Assign to Gallery:" select box
5) The content type of the gallery selected in 4)

justintime’s picture

Oh, and of course, clear your caches first if you haven't already.

yngens’s picture

6.x-3.x-dev of 2010-Dec-02 still gives 'The node_gallery_gallery type is already part of a relationship' error.

1) Gallery Type: Gallery of 'node_gallery_gallery' type (Original),
Image Type: Gallery Image of 'node_gallery_image' type (Recreated. Original one was deleted and node type of 'imapgepage' with 'field_imagefield' field, which holds all my images, has ben reneamed node_gallery_image)
2) node_gallery_image
3) User #1
4) It's username of user #1, because gallery names have been retrieved from per user gallery taxonomies. However, as I understand titel of the gallery can be anythign here, right?
5) Gallery

Clearing cache did not help.

I'm afraid something with views broken when I had deleted 'node_gallery_image' and renamed one of the previously existed content types to 'node_gallery_image'. I tried, but could not find any differences in views or Gallery Node settings. The only difference is that imagefield of my 'node_gallery_image' is called 'field_imagefield'.

Does Relationship ID play any role here? Current rid is 3, two previous ones have been deleted because of 'The node_gallery_gallery type is already part of a relationship' error message.

justintime’s picture

@yngens - I commited the fix for 'The node_gallery_gallery type is already part of a relationship' this morning, you'll need a dev build after that.

I found and fixed the bug in dev that was causing yngens to not be able to manually assign pre-existing image nodes to galleries. @yngens, I left the fixed file in place on your server, so you don't need to wait for a dev build.

yngens’s picture

Justintime, thank you very much! This allows me to place tons of pre-existing images into Node Galleries. tamerzg have been helping me to Migrate images from AcidFree and Gallery2 to Node Gallery. As soon as the whole process is done we will be contributing all the migration scripts to the community and then this issue could be considered solved.

yngens’s picture

justintime, in #7 you mentioned that if it works, then it should be a pretty simple script to get the images into the galleries. Adding manually couple of images I can see changes in database, but to make sure that kind of scripts makes changed on all the needed places, can you please confirm changes to which database tables should be made by the script to add pre-existing images to pre-existing galleries? Is biding correct nids and gids in node_gallery_images table sufficient?

justintime’s picture

http://pastebin.com/rLN3tYj5

You owe me a lot of beer, or a lot of documentation :)

Put that script someplace, like /tmp/ng_migrate.php. cd into your drupal root directory, and run the script: 'php /tmp/ng_migrate.php'. In it's current form, it will not change anything, just print out how many images it finds for each gallery.

If that looks right, remove the comment from the drupal_write_record() and the node_save() lines. PLEASE FOR THE LOVE OF GOD BACKUP YOUR DB FIRST. I haven't tested it - it should work, but I claim no reponsibility for anything in it.

justintime’s picture

If that script works, please post the code back to this issue for safekeeping.

yngens’s picture

Yee, it works. Actually, I'm still running the script. Had to increase php memory for it. I hope running several times does not double the images or hurt otherwise.

About beer, yes i do :) where in us you are? If in bay area then be my guest for drinking real, not virtual bear :) I also hope that in result of this issue the Drupal community will have safe path of migrating to Node Gallery from other gallery modules. I will contribute all the scripts, that Tamer wrote for me too.

P.S. I know separate issue should be created, but maybe it is too simple: Would be nice to place links to galleries on user's profile. Is this easily configurable?

Update: Still have been running the script over and over again, because it spits out the list of galleries with different numbers of images in them. The upper part of the list, seems have been stabilized, but every time scripts add some new galleries in the end part. I think with every refresh of the page the scripts starts to go through all the images, even those which have already been processed. Would be nice if it process only the rest of the images. The script, at least in my case, never reaches its last line: echo "Migrated $galleries galleries and $total_images images to Node Gallery\n";

Can this procedure use Drupal's batch function instead?

justintime’s picture

Updated the link above to http://pastebin.com/rLN3tYj5

This should be more efficient on memory, and also skip any images that are already part of the gallery.

RE: user profile: http://drupal.org/project/node_gallery_user_profile

Shouldn't need batch API if you're running at the command line with the cache clearing that the new version does.

yngens’s picture

justintime, thanks for the second script. It definitely works better, because after several refreshing it finally reached end of the script and gave a report message. However, browsing through galleries and image nodes shows there are still empty galleries and unassigned images. Could you please confirm the followings:

1) Empty galleries are left because some images were associated with several taxonomy terms.
2) Leftout images were not associated with any taxonomies.
3) If the scripts made to the final report message, then all the images associated with taxonomy terms have been imported to galleries and no chance that any single image could be omitted.

Or there might be some exclusions?

yngens’s picture

Just have looked at admin/reports/dblog and found out the script have been giving an error message:

in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argument in /home/mysite/public_html/picmig2.php on line 34.
yngens’s picture

I have been attributing all the orphan images with Views Bulk Operations and, because have read on the other thread that it is not possible for now to add an image to two or more galleries, will delete all the empty galleries.

justintime’s picture

That's right - one gallery per image, no subgalleries. So, regarding #20, 1, 2, and 3 are all correct afaik. The error in #21 is non-fatal, it just means that we're looking inside an empty gallery.

yngens’s picture

Have been running VBO successfully for some time (I have lot's of images, so it will take some time to sort them all out), but suddenly the view stopped working. Log gives the following, though I am not sure if it is related to the Node Gallery module. Posting it here, because I encountered this solving the issue of the thread and because node_gallery_gallery_image_views is mentioned in the error report.

Type	backtrace
Date	Saturday, December 4, 2010 - 13:48
Message	Type: php 
Invalid argument supplied for foreach() in /usr/drupal/sites/all/modules/views/theme/theme.inc on line 583. 
Backtrace:
template_preprocess_views_view_grid(array)[?:?];
.call_user_func_array(array)[theme.inc:697];
..theme(array)[views_plugin_style.inc:228];
...render(array)[theme.inc:46];
....template_preprocess_views_view(array)[?:?];
.....call_user_func_array(array)[theme.inc:697];
......theme(array)[views_plugin_display.inc:2079];
.......render(array:)[view.inc:842];
........render(array:)[views_plugin_display.inc:2159];
.........preview(array:)[view.inc:937];
..........preview(array:a:2:{i:0;s:6:"page_2";i:1;a:1:{i:0;s:5:"18246";}})[views.module:1301];
...........views_embed_view(array:a:3:{i:0;s:32:"node_gallery_gallery_image_views";i:1;s:6:"page_2";i:2;s:5:"18246";})[node_gallery.module:533];
............_node_gallery_gallery_view(array)[node_gallery.module:488];
.............node_gallery_nodeapi(array)[node.module:679];
..............node_invoke_nodeapi(array)[node.module:1089];
...............node_build_content(array)[node.module:1006];
................node_view(array)[node.module:1765];
.................node_page_default(array:)[?:?];
..................call_user_func_array(array:a:2:{i:0;s:17:"node_page_default";i:1;a:0:{}})[menu.inc:348];
...................menu_execute_active_handler(array:)[index.php:19];
....................index.php

justintime’s picture

Looks like this is a known views issue: http://drupal.org/node/989092

pepemty’s picture

subscribing

nasi’s picture

Title: Migrate from Acidfree/Images to Node Gallery/Imagefields » Migrate from Image Module galleries to Node Gallery/Imagefields

Is there an update on this? I am now in exactly the same position of migrating image galleries from Image and Image Gallery to Node Gallery.

I have got as far as migrating all the images to use image field, so now I just need to create the gallery nodes and build the relationships of images to galleries. Things should be a little simpler for me as I have a 1:1 image:gallery relationship and no user galleries to worry about.

Is the script linked in #19 still the best way to go? How did you get on with VBO, was that better? It would be great to see updated/definitive scripts posted back here.

nasi’s picture

Component: Documentation » Code
Category: task » support

Ok, here is the script that I have written to do the migration in a (hopefully) safe manner. I've run it a few times and all seems to work, but YMMV.

Perhaps this should go into a documentation page?

/**
* @file
* Migrate all image galleries from using Taxonomy terms to Node Gallery nodes.
* This script will traverse a given vocabulary, create Gallery nodes if needed
* and link image nodes to the relevant gallery.
* 
* USAGE
* -----
* - Backup your Drupal database.
* - Edit the 'Configuration' section below.
* - Place this script in the root of your Drupal site.
* - Run the script by requesting, e.g. http://<yoursite>/ng_migrate.php
* - Re-run the script if necessary (if it did not complete)
* - You are free to remove/tidy up your old gallery vocabulary
* 
* LIMITATIONS
* -----------
* - This script is designed to work with Node Gallery 6.x-3.0. As such, it only supports
* a 1:1 image:gallery relationship and does not support nested galleries.
* - It doesn't migrate the images themselves (from image to imagefield).  To do that, see
* http://drupal.org/node/432860 and http://drupal.org/node/201983
* - This script should be run once you have migrated your images.
* - While it will move the taxonomy description to the gallery node body, it will not correctly
* populate the teaser field.  That will only be set and displayed once the gallery node has
* subsequently been edited.
* 
* AUTHORS
* -------
* justintime (http://drupal.org/user/99149)
* nasi (http://drupal.org/user/5712)
*/

// ***** CONFIGURATION *******

// The taxonomy id of your Image Gallery vocabulary
$vid = 8;
// THe user with which all new galleries should be created
$uid = 1;

// ***** END CONFIGURATION *******

require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$total_images = 0;
$galleries = 0;
$gallery = new stdClass;
$sql = 'SELECT DISTINCT(n.nid)
  FROM {node} n
  INNER JOIN {term_node} tn ON n.vid = tn.vid
  WHERE tn.tid = %d';

// Get the list of terms for the given tid
$terms = taxonomy_get_tree($vid);

foreach ($terms as $term) {
	// See if a gallery node already exists for this term
	$gal['title'] = $term->name;
	$gallery = node_load($gal, NULL, TRUE);
	if (!$gallery) {
		printf("Gallery: '%s' does not exist.<br/>\n", $term->name);
		// Create a new gallery node
		$gallery->title = $term->name;
		$gallery->body = $term->description;
		$gallery->type = 'node_gallery_gallery';
		$gallery->uid = $uid;
		node_save(&$gallery);
		if ($gallery->nid) {
			$galleries++;
			printf("Gallery: '%s' CREATED<br/>\n", $gallery->title);
		} else {
			printf("Gallery: '%s' creation FAILED<br/>\n", $gallery->title);
		}
	} else {
		printf("Gallery: '%s' already exists.<br/>\n", $gallery->title);
	}
	// Find and attach all images in this gallery
	$gid = $gallery->nid;
	$images = 0;
	$result = db_query($sql, $term->tid);
	while ($row = db_fetch_object($result)) {
		// Check if this image is already in the gallery
		if (in_array($row->nid, node_gallery_get_image_nids($gid, FALSE, FALSE, TRUE))) {
			continue;
		}
		$image = node_load($row->nid);
		$image->gid = $gid;
		node_save($image);
		$images++;
	}
	printf("Gallery: '%s': Migrated %d images.<br/>\n", $gallery->title, $images);
	$total_images += $images;
}
printf("<br/><b>Migrated %d galleries and %d images to Node Gallery</b>\n", $galleries, $total_images);
justintime’s picture

Component: Code » Documentation
Category: support » task

Adding to documentation queue - thanks for the contribution!

izmeez’s picture

subscribing

nasi’s picture

One additional limitation worth pointing out (that I have since discovered); This script will not populate the teaser field of the new gallery nodes. So gallery descriptions will appear in the gallery body but not in teaser displays.

The way I solved this was to edit and save each gallery node by hand, but that would be impractical for a site with a lot of galleries. So anyone planning to use this script on a large scale may want to first work out how to also save the teaser, correctly truncated.

I have edited the script above to reflect this.

justintime’s picture

Component: Code » Howto/FAQ/Example
Category: support » task
Status: Active » Fixed

updateing component

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.