Well, I decided to can this hack due to deadline. What I have done instead is used FileDataObjectManager instead of DataObjectManager after looking at this doc: http://doc.silverstripe.org/doku.php?id=modules:dataobjectmanager (about 1/2 way down).
I still use the code above to create the directory when my page is made (not sure if the next lot of code would do a findOrMake()).
Note:
My page is "Publications" (magazines) - Extends Page
Publications has_many "PublicationIssues" (monthly releases) - Extends DataObject
PublicationIssues has_one "DigitalCopy", which is the File.
Then, in the same Page class, instead of:
// Setup the Issues table Dataobject manager
$issues = new DataObjectManager(
$this,
'PublicationIssues',
'PublicationIssue',
array('Name' => 'Name','ReleaseDate'=>'ReleaseDate'),
'getCMSFields_forPopup'
);
$issues->setAddTitle('PDF Issue');
I use:
// Setup the Issues table Dataobject manager
$issues = new FileDataObjectManager(
$this,
'PublicationIssues',
'PublicationIssue',
'DigitalCopy', // This is the name of the file object in PublicationIssue
array('Name' => 'Name','ReleaseDate'=>'ReleaseDate'),
'getCMSFields_forPopup'
);
$issues->setAddTitle('PDF Issue');
$dest = substr_replace(str_replace('assets/','',$this->Folder()->Filename),"", -1); // DIR is already created. Just get it here.
$issues->setUploadFolder($dest); // Set the file destination field
$issues->setUploadLimit(1); // Set the upload limit (We only want one)
The only difference in the process from the original, is that you upload the file first, and enter the other data afterwards.
The glaring downside that may not be any good for you is that editing existing records display's the same FileIframeField that defaults to "Uploads" when you do a "Replace File". Not so bad for us, as these are magazine issues that never change. If an incorrect PDF is uploaded, it's no big deal to delete the original and redo. Worst case scenario we have a few PDFs sitting in the Uploads directory.
Not the perfect solution, but will cover us until 2.4 is stable.
Aaron