class DMSVersion extends DataObject {
private static $db = array(
'VersionNum' => 'Int',
'CheckIn' => 'Varchar(120)',
'OriginalFilename' => 'Varchar(120)'
);
private static $has_one = array(
'Document' => 'DMSDocument',
'DMSFile' => 'File'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', $UploadField = UploadField::Create('DMSFile', 'Upload version'));
$UploadField->setAllowedFileCategories(array('doc', 'image'));
$UploadField->setAllowedMaxFileNumber(1);
$UploadField->setCanAttachExisting(false);
$UploadField->setCanPreviewFolder( false );
$UploadField->setFolderName(Config::inst()->get('DMSDocument', 'upload_dir'));
$fields->addFieldToTab('Root.Main', new TextField('CheckIn', 'Checked In By'), 'DMSFile');
$fields->removeByName('VersionNum');
$fields->removeByName('OriginalFilename');
return $fields;
}
public function onBeforeWrite() {
trigger_error(basename($this->DMSFile()->Filename));
if(!$this->VersionNum) {
$version = $this->Document()->MaxVersion + 1;
$this->VersionNum = $version;
$this->Document()->MaxVersion = $version;
}
// store the original filename
$this->OriginalFilename = basename($this->DMSFile()->Filename);
return parent::onBeforeWrite();
}
public function onAfterWrite() {
// Make this the current version
$this->Document()->CurrentVersionID = $this->ID;
$this->Document()->write();
// change the filename
$this->DMSFile()->setFilename($this->newFilename());
$this->DMSFile()->write();
return parent::onAfterWrite();
}
public function onBeforeDelete() {
$this->DMSFile()->delete();
return parent::onBeforeDelete();
}
public function newFilename() {
return dirname($this->DMSFile()->Filename) . DIRECTORY_SEPARATOR . $this->ID . '.' . $this->DMSFile()->getExtension();
}
}
trigger_error(basename($this->DMSFile()->Filename)) in onBeforeWrite gives me the filename generated in onAfterWrite
How can I get the original uploaded filename??