public static function create_version(DMSDocument $doc)
    {
        $success = false;

        $existingPath = $doc->getFullPath();
        if (is_file($existingPath)) {
            $docData = $doc->toMap();
            unset($docData['ID']);
            $version = new DMSDocument_versions($docData);  //create a copy of the current DMSDocument as a version

            $previousVersionCounter  = 0;
            $newestExistingVersion = self::get_versions($doc)->sort(array('Created'=>'DESC', 'ID'=>'DESC'))->limit(1);
            if ($newestExistingVersion && $newestExistingVersion->Count() > 0) {
                $previousVersionCounter = $newestExistingVersion->first()->VersionCounter;
            }

            //change the filename field to a field containing the new soon-to-be versioned file
            $version->VersionCounter = $previousVersionCounter + 1; //start versions at 1
            $newFilename = $version->generateVersionedFilename($doc, $version->VersionCounter);
            $version->Filename = $newFilename;

            //add a relation back to the origin ID;
            $version->DocumentID = $doc->ID;
            $id = $version->write();

            if (!empty($id)) {
                rename($existingPath, $version->getFullPath());
                $success = true;
            }
        }

        return $success;
    }
public static function create_version(DMSDocument $doc)
    {
        $success = false;

        $existingPath = $doc->getFullPath();
        if (is_file($existingPath)) {
            $docData = $doc->toMap();
            unset($docData['ID']);
            $version = new DMSDocument_versions($docData);  //create a copy of the current DMSDocument as a version

            $previousVersionCounter  = 0;
            $newestExistingVersion = self::get_versions($doc)->sort(array('Created'=>'DESC', 'ID'=>'DESC'))->limit(1);
            if ($newestExistingVersion && $newestExistingVersion->Count() > 0) {
                $previousVersionCounter = $newestExistingVersion->first()->VersionCounter;
            }

            //change the filename field to a field containing the new soon-to-be versioned file
            $version->VersionCounter = $previousVersionCounter + 1; //start versions at 1
            $newFilename = $version->generateVersionedFilename($doc, $version->VersionCounter);
            $version->Filename = $newFilename;

            //add a relation back to the origin ID;
            $version->DocumentID = $doc->ID;
            $id = $version->write();

            if (!empty($id)) {
                rename($existingPath, $version->getFullPath());
                $success = true;
            }
        }

        return $success;
    }
public static function create_version ( DMSDocument $ doc ) { $ success = false ; $ existingPath = $ doc -> getFullPath ( ) ; if ( is_file ( $ existingPath ) ) { $ docData = $ doc -> toMap ( ) ; unset ( $ docData [ 'ID' ] ) ; $ version = new DMSDocument_versions ( $ docData ) ; //create a copy of the current DMSDocument as a version $ previousVersionCounter = 0 ; $ newestExistingVersion = self :: get_versions ( $ doc ) -> sort ( array ( 'Created' => 'DESC' , 'ID' => 'DESC' ) ) -> limit ( 1 ) ; if ( $ newestExistingVersion && $ newestExistingVersion -> Count ( ) > 0 ) { $ previousVersionCounter = $ newestExistingVersion -> first ( ) -> VersionCounter ; } //change the filename field to a field containing the new soon-to-be versioned file $ version -> VersionCounter = $ previousVersionCounter + 1 ; //start versions at 1 $ newFilename = $ version -> generateVersionedFilename ( $ doc , $ version -> VersionCounter ) ; $ version -> Filename = $ newFilename ; //add a relation back to the origin ID; $ version -> DocumentID = $ doc -> ID ; $ id = $ version -> write ( ) ; if ( ! empty ( $ id ) ) { rename ( $ existingPath , $ version -> getFullPath ( ) ) ; $ success = true ; } } return $ success ; }
Creates a new version of a document by moving the current file and
renaming it to the versioned filename.

This method assumes that the method calling this is just about to upload
a new file to replace the old file.

@static
@param DMSDocument $doc

@return bool Success or failure
Creates a new version of a document by moving the current file and renaming it to the versioned filename .