I guess they're the same as file fields, but they're handled by a different module and so need differently named hooks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Morahan’s picture

FileSize
1.24 KB

Fixing doc typo and the one I copied it from

John Morahan’s picture

FileSize
1.07 KB

Ahem.

mlncn’s picture

FileSize
1.12 KB

Re-rolled.

Paul Kim Consulting’s picture

Status: Needs review » Needs work

This function appears to be missing in your patches:

function file_deploy_field_alter($entity_type, &$entity, $field, $instance, $langcode, &$items) {
  $uuids = array();
  foreach ($items as $item) {
    $uuids[] = $item['uid'];
  }
  // Get all UIDs in one query.
  $uids = entity_get_id_by_uuid('user', array($uuids));
  foreach ($items as &$item) {
    if (isset($uids[$item['uid']]) && $uids[$item['uid']] == 1) {
      $item['uid'] = '1';
    }
  }
}
John Morahan’s picture

Hmm, it was in the module already, wasn't it? has it been removed?

John Morahan’s picture

Status: Needs work » Needs review
FileSize
903 bytes

Indeed it was.

John Morahan’s picture

FileSize
507 bytes
1.3 KB

There's also the fact that the file data isn't deployed. Here's a couple of patches to make this happen (the first also includes the patch above; the second is for uuid).

John Morahan’s picture

FileSize
1.66 KB

hmm. uploaded the wrong patch for deploy. here's the right one.

garethsprice’s picture

Issue tags: +file, +fid, +deploy, +uuid_entity, +uploads

Awesome, thanks for posting this John! This was the missing piece of the puzzle. I also needed to manually create the target directory on the destination server, for some reason it was not auto-created (although permissions are fine).

Just pasting in the error message I was dealing with to help other people searching for this:

<strong>PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'fid' at row 1</strong>: INSERT INTO {file_usage} (fid, module, type, id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => 487cbdbc-a728-bee4-ed64-af003afc930c [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => 3 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 664 of /home/gareth/public_html/deploy-catch/includes/file.inc).

dixon_’s picture

Thanks John for the work on this!

I have a question about $entity->file_contents. If we do base64_encode() on the file and push it over HTTP, how do you take care of that on the endpoint site? Drupal core doesn't seem to have any way of handling raw base64 encoded content in a file_contents property like that.

It would be fairly simple to solve that using hook_entity_presave() or something on the endpoint site...

John Morahan’s picture

Yes, hence the second patch above: https://drupal.org/files/1324970-uuid.patch

which should admittedly have been posted against uuid

aspilicious’s picture

Ok this works great, I'm tempted to apply

+  if ($entity_type == 'file') {
+    foreach ($entities as &$entity) {
+      if (!isset($entity->file_contents)) {
+        $entity->file_contents = base64_encode(file_get_contents($entity->uri));
+      }
+    }
+  }

to deploy.

The only problem I see here is another assumption in UUID based on deploy code AND we need to get the uuid patch applied...
But this is the only way to have a nice and clean deploy system that does everything people want.

So this needs more discussion. (but I love it)

Great! Thnx!

dixon_’s picture

I'm fine with adding what we need in UUID to support this. I will take a look at this shortly.

dixon_’s picture

Status: Needs review » Needs work
+++ b/deploy.core.inc
@@ -153,7 +160,7 @@ function entityreference_deploy_field_dependencies($entity_type, $entity, $field
-function taxonomy_entity_load(&$entities, $entity_type) {
+function deploy_entity_load(&$entities, $entity_type) {
   if ($entity_type == 'taxonomy_term') {
     foreach ($entities as &$entity) {
       if (!isset($entity->parent)) {
@@ -167,6 +174,13 @@ function taxonomy_entity_load(&$entities, $entity_type) {

@@ -167,6 +174,13 @@ function taxonomy_entity_load(&$entities, $entity_type) {
       }
     }
   }
+  if ($entity_type == 'file') {
+    foreach ($entities as &$entity) {
+      if (!isset($entity->file_contents)) {
+        $entity->file_contents = base64_encode(file_get_contents($entity->uri));
+      }
+    }
+  }
 }

I'm quite sceptical about this, when thinking more about it. Doing this on every hook_entity_load() for files could potentially have bad performance implications.

We probably should find another place to do this logic. Maybe hook_deploy_entity_alter() is the right place to do this. That hook is invoked just before deployment...

aspilicious’s picture

Status: Needs work » Needs review
FileSize
1.02 KB

Probably a better idea ;). New patch works!

I also used the patch in #7 for UUID.

wroxbox’s picture

First test:
Applied patches from #7 and #15 and running the deploy from test > live is hitting lives database with error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null: INSERT INTO {file_usage} (fid, module, type, id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => 11 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 664 /srv/bindings/52d84c13e3c54946bf6f04e478982407/code/includes/file.inc).

Second test:
Updated manually deploy.core.inc from #8 and use patch from #15

Same issue remains. The watchdog says these errors are in uuid_services and node bundle. Hitting two times to database.

PdoExceptionError

The php headers Error says
Warning: Header may not contain more than a single header, new line detected. drupal_send_headers() (line 1255 /srv/bindings/52d84c13e3c54946bf6f04e478982407/code/includes/bootstrap.inc).

So I am not quite sure, if those patches actually tries to fix the error I have :)

aspilicious’s picture

See #9

Awesome, thanks for posting this John! This was the missing piece of the puzzle. I also needed to manually create the target directory on the destination server, for some reason it was not auto-created (although permissions are fine).

Just pasting in the error message I was dealing with to help other people searching for this:

We probably want to catch an exception with a message like: "File transfer failed, are you sure you created the needed file directories"

Paul Kim Consulting’s picture

@aspilicious Re: Patch in comment #15

So I'm seeing that the latest Deploy (Mar 28th commit) has deprecated hook_deploy_entity_alter() ... am I correct?

aspilicious’s picture

? Where did you find that? :s

Paul Kim Consulting’s picture

Maybe i'm wrong :) It just magically appeared again :)

louis_sabet’s picture

I can confirm patches 7 (uuid) and 15 (deploy) worked for me fine.

aspilicious’s picture

I'm waiting for someone of the UUID team to get this in. But they are hard to catch ;)

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

I tested these patches and they worked for me too, plus the code seems to make sense.

Not sure you really needed another confirmation, but I'm marking it RTBC anyway :)

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
626 bytes

I actually ran across a bug with the UUID patch in #7. If the field is configured to store uploaded files in a subdirectory, then the deployment will fail to copy it (unless that subdirectory was already created on the target site first).

The attached patch should fix it. Combining this with the Deploy patch in #15, everything should work OK.

guillaumev’s picture

Status: Needs review » Reviewed & tested by the community

Working beautifully for me with the two patches mentioned by David_Rothstein

Dean Reilly’s picture

I can also confirm that the patches are working well.

dixon_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone for the work on this, and sorry for keeping you all waiting...

I've committed David's patch from #24 that fixed the subdirectory issue and Bram's patch from #15.

Again, thanks for your patience :)

Status: Fixed » Closed (fixed)

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

skalfyfan’s picture

Status: Closed (fixed) » Active

Re: #27 - the latest dev release of uuid (july 17, 2012) does not seem to contain the patch from #24 ?

skalfyfan’s picture

Status: Active » Closed (fixed)

scatch that! nevermind!

kenorb’s picture