code/FileVersion.php
public function onBeforeWrite()
    {
        if (!$this->isInDB()) {
            $this->CreatorID = Member::currentUserID();
        }

        if (!$this->VersionNumber) {
            $versions = DataObject::get(
                'FileVersion', sprintf('"FileID" = %d', $this->FileID)
            );

            if ($versions) {
                $this->VersionNumber = $versions->Count() + 1;
            } else {
                $this->VersionNumber = 1;
            }
        }

        if (!$this->Filename) {
            $this->Filename = $this->saveCurrentVersion();
        }

        parent::onBeforeWrite();
    }
public function onBeforeWrite()
    {
        if (!$this->isInDB()) {
            $this->CreatorID = Member::currentUserID();
        }

        if (!$this->VersionNumber) {
            $versions = DataObject::get(
                'FileVersion', sprintf('"FileID" = %d', $this->FileID)
            );

            if ($versions) {
                $this->VersionNumber = $versions->Count() + 1;
            } else {
                $this->VersionNumber = 1;
            }
        }

        if (!$this->Filename) {
            $this->Filename = $this->saveCurrentVersion();
        }

        parent::onBeforeWrite();
    }
public function onBeforeWrite ( ) { if ( ! $ this -> isInDB ( ) ) { $ this -> CreatorID = Member :: currentUserID ( ) ; } if ( ! $ this -> VersionNumber ) { $ versions = DataObject :: get ( 'FileVersion' , sprintf ( '"FileID" = %d' , $ this -> FileID ) ) ; if ( $ versions ) { $ this -> VersionNumber = $ versions -> Count ( ) + 1 ; } else { $ this -> VersionNumber = 1 ; } } if ( ! $ this -> Filename ) { $ this -> Filename = $ this -> saveCurrentVersion ( ) ; } parent :: onBeforeWrite ( ) ; }
Saves version meta-data, and generates the saved file version on first
write.
Saves version meta - data and generates the saved file version on first write .