The Image Attach Migrate module resolved the issue of migration image attach nodes from Drupal 6 to Drupal 7. In Drupal 6, to add pictures to posts was using a combination of the image module with the image attach module. Now in Drupal 7 Imagecache and ImageField is incorporated into Drupal 7 core and renamed 'Image'.

Usage:
- Backup your Drupal database.
- Go to admin/config/media/image-node-attach.
- Select the content type(s) to which all your images will be migrated.
- Run this migration script by clicking on submit button.

After running this module, you will found there is entity reference field (field_image_node_attach) available in every content type selected from configuration page and all relevant image are migrated there.

Image Attach Field

There would be a custom formatter (Entity Reference Image Formatter) available on 'Manage Display' page for this field in every selected content type.

Formatter

Module Link:
https://www.drupal.org/sandbox/er.pushpinderrana/2297739

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/er.pushpinderrana/2297739.git

Reviews:
https://www.drupal.org/node/2308823#comment-8994565
https://www.drupal.org/node/2298271#comment-8951589
https://www.drupal.org/node/2274105#comment-8951615
https://www.drupal.org/node/2288977#comment-8951653
https://www.drupal.org/node/2300519#comment-8965469
https://www.drupal.org/node/2298271#comment-8965457
https://www.drupal.org/node/2284835#comment-8976115

Comments

joachim’s picture

Status: Needs review » Needs work

I'm very pleased to see that someone's tackling this! Do please make it known on the very very long issue about the old contrib Image module's D7 upgrade path!

One thing that came up a lot is that there's more than one way to migrate attached images -- you could keep your image nodes as nodes, and use entityreference to point to them, and then have a custom formatter; or you could lose the image node and have a simple image field (and then have to figure out a strategy for dealing with an image node that's attached to more than one content node).

function _batch_image_attach_migrate_update_http_requests() {
  $_SESSION['http_request_count']++;
}

That's not the right way to do this at all. Use the batch sandbox to store details from one batch iteration to the next, it's what it's there to do.

Though I don't know why you need this anyway:

    drupal_set_message(t('@count results processed in @requests HTTP requests.', array('@count' => count($results), '@requests' => _batch_image_attach_migrate_get_http_requests())));

It's not customary to bother with saying how many requests were needed.

At any rate, use the sandbox and all the code surrounding this will boil down to 2 lines: one to initialize and one to increment.

    foreach ($image_attach_result as $image_attach_data) {
      // Each operation is an array consisting of
      // - The function to call.
      // - An array of arguments to that function.
      $operations[] = array(
        'batch_image_attach_migrate',
        array(

That's not the best way to use BatchAPI. You should only add the operation once, and let the operation iterate over a set number of results, using the sandbox to mark how far it got each time.

Though a bigger issue is that as you've called your module 'migrate', I assumed you'd be building on top of Migrate module...

gaurav.pahuja’s picture

Please run PAreview.sh once. I found multiple issues in your module.

USe URL: http://pareview.sh/

pushpinderchauhan’s picture

@gaurav.pahuja and @joachim, thanks!

@joachim, Great thanks to you to review this module so soon. Sorry for delayed replying as I was tried your suggested approach in my current project and I found your approach looks more generic. So I make following changes:

One thing that came up a lot is that there's more than one way to migrate attached images -- you could keep your image nodes as nodes, and use entityreference to point to them, and then have a custom formatter; or you could lose the image node and have a simple image field (and then have to figure out a strategy for dealing with an image node that's attached to more than one content node).

I keep image nodes as nodes and use entityreference with custom formatter. Even I am not facing any issue with existing approach but this one looks good and more generic so going with this.

Use the batch sandbox to store details

Yes now I am using BatchApi sandbox with specific feature that required here.

You should only add the operation once,

This time I added the operation once and iterate the same on specific nodes.

Though a bigger issue is that as you've called your module 'migrate', I assumed you'd be building on top of Migrate module...

I have changed the module name from image_attach_migrate to image_node_attach.

@gaurav.pahuja, as the code is completely changed now, so after fixing all issues posted by http://pareview.sh/ will move to Need Review.

Thankyou again!

pushpinderchauhan’s picture

Title: [D7]Image Attach Migrate » [D7]Image Node Attach
Issue summary: View changes
Status: Needs work » Needs review

@gaurav.pahuja and @joachim, please review the updated code.

@gaurav.pahuja, I have fixed all issues of http://pareview.sh/, please review.

@joachim, Please do share your thoughts on this, it would help me to make this module more reliable and robust.

Thanks!

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

pushpinderchauhan’s picture

Issue summary: View changes
Issue tags: +PAreview: review bonus
StatusFileSize
new7.93 KB
new9.75 KB
gaurav.pahuja’s picture

Manually reviewed your code. It seems to be changed completely from last revision. Now it makes more sense to have images as node. I am going to test it fully on a migration environment and let you know the comments.

Can we have configurable node limit that you used in batch? Currently it is hard coded to 50.

pushpinderchauhan’s picture

@gaurav.pahuja, thanks for review.

I am going to test it fully on a migration environment and let you know the comments.

I am awaiting for your comments.

Can we have configurable node limit that you used in batch? Currently it is hard coded to 50.

Yes, we can have a configurable node limit but it would make the user little bit confused at this stage. I think 50 is safe number to process within a single batch without a timeout.

But if you think it is required, I can add the same on configuration page.

Thanks again!

gaurav.pahuja’s picture

Automated Review

PAReview doesnt reported any issue in current build.

Manual Review

Tried migrating images content from one of the existing Drupal 6 site to new Drupal 7 vanilla. Worked for me.

Duplication
No. Googling for drupal does not find an existing module that does this. Though found one similar custom PHP script. A full fledge module would be helpful.

Master Branch
No.

Project page
Exists. Module name changed to make it more informative.

README.txt
Yes: Followed steps from Readme file and Help page and able to complete image attach migration.

Code long/complex enough for review
Yes

Secure code
Yes: Follows guidelines for writing secure code. (There isn't much to review, but I didn't find anything wrong with the code submitted.)

Coding style & Drupal API usage
There isn't much to review, but I didn't find anything wrong with the code submitted.

There are IMHO no blockers, so I am giving +1. Let somebody else also review this module then it can be moved to RTBC.

chetan-singhal’s picture

Status: Needs review » Needs work

@er.pushpinderrana

Nice Module

There are few issue
1. line no-100, image_node_attach.module file Please also check

!empty($image_node->node_image) 

otherwise if array empty it give php warning undefined index.

2. intially assign

$link_file

to FALSE in your function image_node_attach_field_formatter_view. so you not need to check isset again and again in your foreach loop. Then only check

if($link_file){ }

3. Line no 212

theme_entity_reference_image_formatter

function. In this function $item variable may has other attributes like 'error'. so also manage rest attributes.

pushpinderchauhan’s picture

Status: Needs work » Needs review

@gaurav.pahuja, thanks for your feedback.

@chetan_singhal, thanks for your review. I deeply analyze each point, adding my comment with each.

1. line no-100, image_node_attach.module file Please also check

!empty($image_node->node_image)

I am also checking 0th index here, so there is no need to separately check for array. Below is my code.


 if (isset($image_node->node_image[LANGUAGE_NONE][0])) {
 ....
}
intially assign
$link_file

to FALSE

Here $link_file is declared in else condition so when it is going to if condition then variable is not declared as shown in below code

// Check if the formatter involves a link.
  if ($display['settings']['image_link'] == 'content') {
    $uri = entity_uri($entity_type, $entity);
  }
  elseif ($display['settings']['image_link'] == 'file') {
    $link_file = TRUE;
  }

That's why I am checking isset with following code.

if (isset($link_file)) {
    $uri = array(
    'path' => file_create_url($item['uri']),
    'options' => array(),
   );
} 
In this function $item variable may has other attributes like 'error'.

I am doing theming here within this function of custom formatter and 'error' attribute is not available here. That's why error attribute is not declared here.

Thanks again @chetan_singhal for review!

chetan-singhal’s picture

Status: Needs review » Reviewed & tested by the community
pushpinderchauhan’s picture

@chetan_singhal, thanks for your review and quick reply.

If you have anything to say about my coding standard or documentation (any particular thing that can be improved), I would appreciate that.

I would also appreciate git admin users to review this ASAP, as lot of people experiencing this issue that would resolved through this module.

Though, I am working as a co-maintainer in other projects but never get time to contribute a complete module. I actively contribute on drupal forums and core issues. I just experienced this issue in past, did lot of researched on this but at the end write my own custom script for this. As most of people avoid to write own custom script so I developed this module but currently don't have permission to promote sandbox projects. So it would be great if any user from git admin look into this module once and share feedback on this.

Thankyou for your time!

mpdonadio’s picture

@er.pushpinderrana, the review process has been backed up, but some new admins have come on and we are working on clearing this out as quickly as we can (without compromising the review process). Unfortunately, this is a new application and older projects have priority. There are currently four RTBC applications before you, so it will be a few days before we can take a look at this.

pushpinderchauhan’s picture

@mpdonadio, Great thanks to you for quick reply. I am completely agree with you on this and I'll also follow the complete review process.

Thanks again!

chetan-singhal’s picture

add a tag

pushpinderchauhan’s picture

Issue summary: View changes
pushpinderchauhan’s picture

Issue summary: View changes
chetan-singhal’s picture

Removing "PAReview: Single project promote" tag as by mistaken added. Everything is looking good to me, it is ready to go.

pushpinderchauhan’s picture

Issue summary: View changes
klausi’s picture

Status: Reviewed & tested by the community » Needs work

Git default branch is not set, see the documentation on setting a default branch.

manual review:

  1. Project page: "There was a module in Drupal 6 that are deprecated in Drupal 7". Which one is it? Please provide a link.
  2. "'access arguments' => array('administer access'),": that permission is not defined by your module in hook_permission()? Also the permission name does not really fit? Shouldn't it be "administer image node migration" or something similar?
  3. image_node_attach_field_formatter_view(): the switch() statement does not make sense here since you only have one case? Use if() instead?
  4. "'#default_value' => variable_get('image_node_attach_content_type_names'),": that variable is never used or set anywhere else, why do you need it? Please add a comment.

The misleading and undefined permission is a blocker right now, otherwise this would seem good to go.

pushpinderchauhan’s picture

Status: Needs work » Needs review

@klausi, thankyou for your review and valuable feedback!

I am done with all your suggested points, please review.

1. Git default branch is not set, see the documentation on setting a default branch. [DONE]
2. Project page: "There was a module in Drupal 6 that are deprecated in Drupal 7". Which one is it? Please provide a link. [DONE]
> Link added on project page.
3. "'access arguments' => array('administer access'),": that permission is not defined by your module in hook_permission()? Also the permission name does not really fit? Shouldn't it be "administer image node migration" or something similar? [DONE]
4. "'#default_value' => variable_get('image_node_attach_content_type_names'),": [DONE]
> Very good caught, there is no need of default value, removed it.

Thanks again!

pushpinderchauhan’s picture

Issue summary: View changes
ratanphp’s picture

Status: Needs review » Reviewed & tested by the community

1) PAReview is clear.

2) I did a manual review of this project as well. I also installed your module, and test functionally, it works fine. I can see all the points are fixed mentioned by @klausi.

It looks RTBC to me but I am not the right person that makes the final decision. Someone from git administrator look into this and will take a final call on this.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

This looks good to me now after a manual review, so ...

Thanks for your contribution, er.pushpinderrana!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

pushpinderchauhan’s picture

@klausi, thanks a lot!

Thanks to all the reviewers.

Status: Fixed » Closed (fixed)

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