PHP Action Hook/Filter to rename media file problem
-
Been going round in circles for way too long with walking back my code, adding debug statements, and still have no clue what is happening here. Things that come to mind are: Data Race conditions, Cache vs non Cache processing, Other unknown? The code I have written appears to be working as designed but the expected functionality is still broken
Using a FORM BUILDER Plugin that provides the ability to upload files which in turn are emailed as attachments … as the uploaded filenames are random, wanting to rename them automatically to simplify downstream email processing.
The Form Builder provides a before email hook filter which I am attempting to use to rename the uploaded files before they are emailed as attachments.
Added a FORMID-POSTID Prefix to all attachments PLUS each attachment has a unique Fixed name defined by the form’s field details … all attachment files simply get renamed to:
SomeRandomFilename.SomeAcceptablePrefix -> xFORMID-POSTID-FIELDNAME.SomeAcceptablePrefixThe hook logic written in PHP queries all relevant records in posts & postmeta tables followed by successfully renaming all appropriate files then finally updates the relevant records.
Files are renamed using builtin PHP functions: glob() and rename() … files all appear to be renamed properly
posts and postmeta Tables are updated using builtin PHP functions: str_replace() with:
$wpdb->update(table,array(‘data_field’ => $data),array(‘ref_field’ => $ref)while the filename data appears to be updated properly in both tables, for some reason the email processor is randomly ignoring some of the files. With renaming turned off, testing with 5 uploaded files, all 5 files are emailed. Same test with renaming turned on, files are randomly missing … review of folders, log files, and data shows that all files and records were updated correctly … plus … there are no error_log entries.
I went looking for wp functions to doing meta records updates in case there may be some inherent checksums that I am missing but maybe not using the right questions … regardless … if this was a checksup issue I wouldn’t expect ANY emailed files … if this is a race condition with the wpdb->update() function then perhaps I have to add a wait loop of some sort … if this is a CACHE issue where the Plugin is using previous data then I may have to build my own MAILER routine.
Thanks in advance for ideas
- The topic ‘PHP Action Hook/Filter to rename media file problem’ is closed to new replies.