Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

CB Auto action to move a file

  • GUEST
8 years 2 months ago - 8 years 2 months ago #284383 by
Replied by on topic CB Auto action to move a file
Hi Krileon

EDIT: OK something is happening

im using

onAfterUserUpdate
onAfterUpdateUser
onAfterUserRegistration
onAfterNewUser

It is amending the cb_resume field value but the last part is going weird

$newFilename = '[cb:parse function="clean" method="string"][firstname][/cb:parse]_[cb:parse function="clean" method="string"][lastname][/cb:parse]_[user_id]_[cb_resume]';

resulted in a filename like this

Jonathan_Appleton_47_http://chevronj3.jacl.co.uk/profile/view-profile/fieldclass?field=cb_resume&function=download&user=47&reason=profile

So it's like the [cb_resume] field value it's getting after the user profile is updated is not the true value but instead is the url used to show the fiel upload when viewing your profile

Does this mean I need to have a different trigger so this happens before the profile is displayed? eg OnBeforeUserUpdate?

Just tried OnBeforeUserUpdate and nothing happens.....
Last edit: 8 years 2 months ago by .

Please Log in or Create an account to join the conversation.

  • GUEST
8 years 2 months ago #284385 by
Replied by on topic CB Auto action to move a file
WOOOHOOOO! :)

It's working.... field and filename are renamed :)

I had to use [var1_cb_resume]

Can you please just tell me the difference between

[cb_resume]
[var1_cb_resume]
[var2_cb_resume]
[var3_cb_resume]

I know on another action I check to see if a fields value has changed and if it has update a certain timestamp.

[var3_cb_resume] not equal to [var1_cb_resume]

So is var3 the new value saved and var1 the old value before saving profile?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48459
  • Thanks: 8280
  • Karma: 1443
8 years 2 months ago #284395 by krileon
Replied by krileon on topic CB Auto action to move a file
The raw substitutions pass through APIs now and the PHP output for file fields is the download URL. So yes you need to use [var1_cb_resume] for the raw filename.

So is var3 the new value saved and var1 the old value before saving profile?

No, var1 is the new and var3 is the old.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You:

Please Log in or Create an account to join the conversation.

  • GUEST
8 years 2 months ago #284436 by
Replied by on topic CB Auto action to move a file
Thank you again for taking the time to explain that to me, very much appreciated.

Now all I'm looking for is CB function to grab the file extension of the uploaded file be it pdf doc or docx so I can pin that to the end of my new filename.

Does CB have its own GetExt function or should I use the JFile::GetExt?

Thanks and ps the read more links in the forum notifications that im receiving are broken links so dont seem to be working in case you didnt realise?

thanks

Please Log in or Create an account to join the conversation.

  • GUEST
8 years 2 months ago #284439 by
Replied by on topic CB Auto action to move a file
Hi all sorted and putting the code here for anyone wanting to do the same thing

This code renames the uploaded file to have this format [firstname]_[lastname]_[userid].pdf (or doc/docx etc)
Code:
jimport('joomla.filesystem.folder'); $basePath = JPATH_SITE . '/images/comprofiler/plug_cbfilefield/[user_id]'; $oldPath = $basePath . '/[var1_cb_resume]'; $fileExt = JFile::getExt('[var1_cb_resume]'); $newFilename = '[cb:parse function="clean" method="string"][firstname][/cb:parse]_[cb:parse function="clean" method="string"][lastname][/cb:parse]_[user_id].'.$fileExt; if ( file_exists( $oldPath ) ) { @rename( $oldPath, $basePath . '/' . $newFilename ); $user->set( 'cb_resume', $newFilename ); $user->store(); }

Please Log in or Create an account to join the conversation.

  • GUEST
8 years 2 months ago #284445 by
Replied by on topic CB Auto action to move a file
Note of caution I found that having this same code running after new registration as well as after user updates was breaking the password encryption for some reason

new users passwords are being stored in plain text format in SQL

am trying to find out why

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum