Using Rules to update a file location

Events happening in the community are now at Drupal community events on www.drupal.org.
el_reverend's picture

Hi all,

I have a little dilemma that I need some help on. I am building a site that allows anonymous users to upload three files during the account creation process. This is enabled through content profile and uses the filefield to upload the file. The account is then blocked pending review from a manager of the site via Drupals default account creation settings.

Since the user that uploads the file(s) does not yet exist in the system by the time the file(s) are uploaded, the file(s) are created under user 0. I am using the following filefield path settings: profile/[uid]/audio.

So when user BOB is created; the files are uploaded to www.site.com/files/profile/0/audio/file.ext. Files that are uploaded later are placed in www.site.com/files/profile/24/audio/file.ext using the actual user id. Unless the user removes the files and uploads them again they stay in that User 0 folder.

Since I have many users uploading files and creating new accounts I would like this User 0 folder to remain empty so a) files aren't mixed up, b) am concerned with file security (using private file system - just so that other users cannot access other users files).

Can I move these files from that User 0 folder to a new folder created under the users actual user id once the user account is approved (via Rules?)?

Do I even need to worry about that in the first place?

Greatly appreciate any input and help,

Sebastian

Comments

Check "Active updating"

nadavoid's picture

It would not be a very good idea to just move the files manually. You would also need to update database tables manually, and that just gets messy and unmanageable in quantity.

I think that this is essentially your route forward:

  • Check "Active updating" in your field configuration under FileField Path Settings. (This is essential, and maybe the missing ingredient for you.)
  • If the nodes that the files are attached are assigned the author of the new user and then saved, I think you are in good shape. Also, you might try using the [author-uid] token.

If all of that ends up working, you don't even need rules for this task. It'll all be handled by the filefield_paths module.

Hope that helps a little!
-david

Maybe I should clarify a little

el_reverend's picture

First off; thank you David for the recommendation. I have tried it, but am running into errors (referencing the bootstrap.ini) and a few more problems with that. I have to it does some of the job and I am still investigating this issue.

Now to some clarification:
I am trying ton sign up users to the site sitex.dev by filling out a form and user account information. This information is composed of a profile built by the content profile module and some CCK fields.

One of the fields is a file upload.

When the new user submits the profile signup the system blocks the account until an administrator activates the account. Once the account is activated the user has access to the system and also the ability to add more files to his/her profile.

These added files are stored in the 'right' location while the files uploaded when the profile was created originally are not (see file paths above).

This is currently a single step process. What I think should happen is that the files are stored in the correct directory and not in the common one.

Shouldni make this a multi-step process and create an intermediary user role (to limit the permissions) until the user is approved or can I get the system to update the file paths and the paths in the db once the user account is approved?

I am using the 'private' option for the file handling within Drupal. Do I have to worry about files being switched in that common user folder with many new users signing up?

Thank you for any input or advice.

Adjust the workflow?

itangalo's picture

It seems that you could get rid of your problems by changing the workflow for registering a litte:
1) User creates account
2) User fills in required fields in profile (including the three files)
3) Account is blocked until editor has reviewed and approved the files.

In this workflow the user already has an account when the files are uploaded, and the files are thus stored in the right folder.
I'm pretty sure you can do this with Content Profile right out of the box – if you set some CCK fields in the profile as required they will show up on registration, and when the profile is created there is already a user account available.

To achieve the third step, just use Rules to block an account when its profile page is created.

Good luck!
//Johan Falk, NodeOne, Sweden

Hallo Johan, Thanks for the

el_reverend's picture

Hallo Johan,

Thanks for the reply. I have thought about this as well. Not necessarily the prettiest solution in the way of end-user experience, but that will have to do. Currently I have exposed some text fields upon registration and using the rules module to redirect to the profile page upon submission. Then the user is shown a message that asks for the required picture and file upload. What I am currently struggling with is a way to check via rules that both picture field and file field (music file - up to three) are present. Since I cannot use a token-replacement I have tried php, but Im failing to use the right syntax.

I think this is what I am using:

return isset($node_unchanged->field_profile_pic)

But I am getting a message the rule is not evaluated because the variable node cannot be found. Any hints?

Greatly appreciate your input,

Sebastian

PHP filter and dpm

itangalo's picture

In cases like these I usually do two things: make sure that the PHP filter is enabled, and then do a

<?php
dpm
(get_defined_vars());
?>
.

If you have an object $node_unchanged available, it should show up in the dpm output. If not, you should get a pretty good hint on what variables are there to use. (The PHP filter often make a list of variables show up in Rules settings, so take a look at these first.)

Good luck!
//Johan Falk, NodeOne, Sweden

Thank you Johan, Maybe I am a

el_reverend's picture

Thank you Johan,

Maybe I am a little slow here, but I am not sure how to do this. In the rule condition itself I only have advanced field in which I am able to post the dpm function. However nothing happens. I am a little new to this and the rules module is anything but user friendly. I have looked at various examples, but I can't figure out how to check if a field has ANY value in it. I am just trying to verify that a field has been filled out.

Would you mind shedding some more light on this for me?

Thanks a lot,

Sebastian

Two clarifications

itangalo's picture

Don't give up! Rules might be a bit tricky in its interface, but it's well worth taking the fight. :-)

Two clarifications:

-1-
The variable you want to change is most likely an array, with values like $node_unchanged->field_profile_pic[0]['value'] and $node_unchanged->field_profile_pic[0]['mime'] and stuff like that. That's probably why your isset() check fails -- the variable itself is set, and you'll have to do a check like is_null($node_unchanged->field_profile_pic[0]['value']) instead.

-2-
The cleanest way to run the dpm() function is probably to add another action in the rule. Use the action type called execute custom php code (or something similar). If you're certain that your node object is called $node_unchanged, then run dpm($node_unchanged) to check the object out -- you'll be able to check the structure of the array mentioned above.
If you're not certain of the object name, PHP filter should present you a nice list of objects on the action edit screen. As last resort you can try dpm(get_defined_vars()) -- it will show you almost all variables you have available (but in a way that is more difficult to interpret).

Good luck!
//Johan Falk, NodeOne, Sweden

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: