pulsorock
Posts: 28
|
| Posted: 09/09/2009, 1:46 PM |
|
Hello,
I have a file upload component that has an AfterProcessFile event that copies the file to another folder and then updates a field column for that record. The problem I’m having is that the $Component->SetValue() is not working for setting that value to that specific field.
Here is an example code of the AfterProcessFile Custom code:
$original_path = "/var/www/file_upload/" . $component->file_upload->GetValue();
$copy_path = "/var/www/file_backups/" . $component->file_upload->GetValue();
if (!copy($original_path, $copy_path)) {
$component->Errors->addError(There was an error copying file.");
}else{
$component->file_backup->SetValue($copy_path);
}
The files get copied fine, but the component field “file_backup” is still null after the update (or insert), it seems like the SetValue() is doing nothing.
I’ve tried these methods without success:
$component->file_backup->SetText($copy_path);
$component->file_backup->SetValue($copy_path);
$component->file_backup->Value = $copy_path;
Any ideas of what could be wrong?
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 09/09/2009, 4:50 PM |
|
By the time the After Process File Event is fired The database has already been updated.
Soo.... No database fields are updated during this event.
You must do these field updates during an event that is fired before any updates or inserts occur.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
pulsorock
Posts: 28
|
| Posted: 09/09/2009, 5:31 PM |
|
Quote jjrjr1:
By the time the After Process File Event is fired The database has already been updated.
Soo.... No database fields are updated during this event.
You must do these field updates during an event that is fired before any updates or inserts occur.
I imagine it had something to do with that... So, what alternatives do I have to accomplish what I need? On what events prior to "AfterProcessFile" can I set those values?
Also, since I need that field be updated ONLY when a new file is uploaded to the server, how I can validate that a file is being uploaded rather than just a regular update to the record (on others fields other than the upload component)?
Thanks!
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 09/09/2009, 6:07 PM |
|
If you want to validate the file is uploaded then you will have to do all that in the after process file
This means you do what ever checks you need to do. Then do the database update.
eg:
$db = new clsYourDBConnection();
$SQL = Your Sql Command String
$db->query($SQL);
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
pulsorock
Posts: 28
|
| Posted: 09/10/2009, 10:35 AM |
|
Thanks!
Is there a way (maybe an internal (CC param) to identify the ID (the incremental ID) of the record I'm working. If either is a new insert or an update of an existing record. So I could create a command string like:
$SQL = "update table set file_backup = '". $copy_path ."' where id = '". $component->id->Value ."'";
Where $component->id->Value would be someway to identify the ID of the current working record.
Thanks!
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 09/10/2009, 11:25 AM |
|
Use the filename that was inserted into the database as the where= criteria
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
pulsorock
Posts: 28
|
| Posted: 09/10/2009, 11:42 AM |
|
Quote jjrjr1:
Use the filename that was inserted into the database as the where= criteria
That's a good suggestion... Will try it... thanks!
|
 |
 |