public function delete()
    {
        // delete the file (and previous versions of files)
        $filesToDelete = array();
        $storageFolder = $this->getStorageFolder();

        if (file_exists($storageFolder)) {
            if ($handle = opendir($storageFolder)) {
                while (false !== ($entry = readdir($handle))) {
                    // only delete if filename starts the the relevant ID
                    if (strpos($entry, $this->ID.'~') === 0) {
                        $filesToDelete[] = $entry;
                    }
                }

                closedir($handle);

                //delete all this files that have the id of this document
                foreach ($filesToDelete as $file) {
                    $filePath = $storageFolder .DIRECTORY_SEPARATOR . $file;

                    if (is_file($filePath)) {
                        unlink($filePath);
                    }
                }
            }
        }

        // get rid of any versions have saved for this DMSDocument, too
        if (DMSDocument_versions::$enable_versions) {
            $versions = $this->getVersions();

            if ($versions->Count() > 0) {
                foreach ($versions as $v) {
                    $v->delete();
                }
            }
        }

        return parent::delete();
    }