public function onAfterWrite()
    {
        parent::onAfterWrite();

        // Request via ImportForm where TemplateVersion is already set, so unset it
        $posted = Controller::curr()->getRequest()->postVars();
        if (isset($posted['_CsvFile']) && $this->TemplateVersion) {
            $this->TemplateVersion = null;
        }
        if ($this->numChildren() == 0 && $this->Template && !$this->TemplateVersion) {
            $this->getWorkflowService()->defineFromTemplate($this, $this->Template);
        }
    }