AWESOME AND EASY :D, patch follows...

But _uuid_services_entity_access() is being a pain in the ass (again), the access callback for a field collection item is:

function field_collection_item_access($op, FieldCollectionItemEntity $item = NULL, $account = NULL) {
    if (user_access('administer field collections', $account)) {
      return TRUE;
    }
    if (!isset($item)) {
      return FALSE;
    }
    $op = $op == 'view' ? 'view' : 'edit';
    // Access is determined by the entity and field containing the reference.
    $field = field_info_field($item->field_name);
    $entity_access = entity_access($op == 'view' ? 'view' : 'update', $item->hostEntityType(), $item->hostEntity(), $account);
    return $entity_access && field_access($op, $field, $item->hostEntityType(), $item->hostEntity(), $account);
  }

It type hints FieldCollectionItemEntity and than everything explodes. When I comment that out and just return true (for testing purpose) the field_collection gets transfered.

Comments

aspilicious’s picture

Status: Active » Needs review
StatusFileSize
new1.4 KB

Here it is

cracu’s picture

Does not work for me :(.
But still... if I remove FieldCollectionItemEntity and force the function to return TRUE, it will transfer the field_collection as you said.
Do you have any news on this issue?

David_Rothstein’s picture

Title: Deploy field_collections » Allow field collections to be deployed via UUID and Services
Project: Deploy - Content Staging » Universally Unique IDentifier
Version: 7.x-2.x-dev » 7.x-1.x-dev
StatusFileSize
new1.9 KB

I'm not sure this patch actually belongs in Deploy... Normally, when deploying content you don't even need the Deploy module enabled on the target site, right (only on the source site)? But with the above patch you would need to.

Seems like it would be better off in either UUID or Field Collection itself. For now, I'm trying it in UUID because (a) that's the module where all the magic happens that allows the above patch to work even with 'field_collection_item' set to an empty array :), and (b) that allows us to fix the bug with _uuid_services_entity_access() described above, all in one patch.

With the attacehd patch applied, I was able to deploy field collections after (1) clearing caches, (2) enabling the field collection 'update' operation on the services endpoint of the target site, and (3) making sure the user I was using for content deployment had access to create field collections on the target site (easiest way is to give that user the 'administer field collections' permission).

The part of the patch that fixes the type hinting issue is this:

@@ -170,7 +170,7 @@ function _uuid_services_entity_access($op, $args) {
     $entity_ids = entity_get_id_by_uuid($entity_type, array($args[1]));
     $entity = NULL;
     if (!empty($args[2])) {
-      $entity = (object)$args[2];
+      $entity = entity_create($entity_type, $args[2]);

As far as I can tell, that's a reasonable thing to do for all entities, not just field collections (and UUID Services already depends on the Entity module anyway).

Without that change, you get this when deploying a field collection:

Recoverable fatal error: Argument 2 passed to field_collection_item_access() must be an instance of FieldCollectionItemEntity, instance of stdClass given

But with it, things seem to work fine.

Assuming that is the correct change, note that there's another line of code in UUID Services that seems like it would make sense to change in a similar way:

function _uuid_services_entity_update($entity_type, $uuid, $entity) {
  try {
    $entity = (object)$entity;

I didn't need it for this patch so I didn't do it, but it may make sense to do that either here or in a separate issue.

David_Rothstein’s picture

Sorry, that patch was relative to the wrong directory. Try this one instead.

johnpitcairn’s picture

Patch does not apply using git apply -v for me. There's no output.

Patch applies using patch, from the uuid_services directory. But if using patch, when attempting to add field collections as a deployable resource at the endpoint, you'll get:

Fatal error: Call to undefined function _field_collection_resource_definition() in /Volumes/Opus Locus/Sites/_drupal7/sites/all/modules/contrib/uuid/uuid_services/uuid_services.module on line 219

Because the "resources" subdirectory is not being created, and the resource file is created at top level.

David_Rothstein’s picture

You're right, I managed to create a patch from the wrong directory twice in a row. Third time's the charm (I hope)...

johnpitcairn’s picture

Re #6, with everything in the correct place, I can deploy nodes containing field collections. That's probably just saved me a couple of days on a site rebuild, massive thanks!

So if the patch in #7 applies, it's good...

Dean Reilly’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm the patch works well and resolved the problem.

dixon_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all for the work on this. I've carefully looked through this small and simple patch and I see no hurdles. It has a low impact on other things, so I've committed the patch from David in #7.

Thanks!

Status: Fixed » Closed (fixed)

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

picardmyhero’s picture

I have a Source Server that is trying to deploy a photo_gallery content type which has a field_collection,
to a Destination Server. I applied the above patch:
uuid-services-field-collection-1504444-7.patch+
to both servers, but when I try to deploy the photo_gallery, I'm still getting:
a. Source Server Log error:
DeployServiceException: Service error: 404 Not found: Could not find resource field_collection_item. in DeployServiceRest->httpRequest() (line 70 of /data/timeinc/content/test.drupal-staging/drupal/sites/all/modules/deploy/includes/DeployServiceRest.inc).

b. Destination Server Log error:
Notice: Undefined index: source in RESTServer->checkNumberOfArguments() (line 681 of /data/timeinc/content/test.drupal-prod-nj2x/drupal/sites/all/modules/services/servers/rest_server/includes/RESTServer.inc).

After I applied the patches I cleared cache with drush.
Also, for this post above:
"enabling the field collection 'update' operation on the services endpoint of the target site"
on the Destination Server, for the endpoint, I do not see a field collection item. Should I?

I would appreciate any help anyone can provide for this issue.

timaholt’s picture

This hasn't been updated in a while, but @picardmyhero this is caused by not enabling the field_collection in the services endpoint on the destination site. If you still have this error after confirming that is set correctly, let us know.

damok’s picture

Issue summary: View changes

I know this is a bit old now but I'm receiving the error 'Could not find resource field_collection_item' when attempting to deploy any nodes with field collections.

@timaholt: You mention enabling the field_collection in the services endpoint on the destination site, how would I achieve this? Is there an obvious setting I'm missing?

damok’s picture

I managed to get it working and it was something obvious, after clearing the cache on the destination site the field_collection_item showed in the services endpoint resources.

jeremygrajales’s picture

I had the same problem but had to resolve it by enabling "Support all UUID entity types" in /admin/config/services/uuid-services
Then, the field_collection_item resource was display in services.