public function onBeforeDelete()
    {
        $currentVersion = $this->owner->CurrentVersion();

        // make sure there actually is a current version, otherwise we're going
        // to end up deleting a bunch of incorrect stuff!
        if ($currentVersion && $currentVersion->ID > 0) {
            $folder = dirname($this->owner->CurrentVersion()->getFullPath());

            if ($versions = $this->owner->Versions()) {
                foreach ($versions as $version) {
                    $version->delete();
                }
            }

            if (is_dir($folder)) {
                Filesystem::removeFolder($folder);
            }

            // If the _versions folder is now empty - because there are no other versions of any assets - then we can
            // delete the _versions folder
            $folder = dirname($folder); // We want the parent of $folder, as we just deleted $folder
            if (is_dir($folder)) {
                $dir = opendir($folder);
                $foundOtherFile = false;

                while ($file = readdir($dir)) {
                    if (($file == '.' || $file == '..')) {
                        continue;
                    }
                    $foundOtherFile = true;
                }

                if (!$foundOtherFile) {
                    // No other files found, so we can delete the _versions folder
                    rmdir($folder);
                }
            }
        }
    }