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;
    }