public function beginWorkflow(WorkflowDefinition $definition, DataObject $for = null)
    {
        if (!$this->ID) {
            $this->write();
        }

        if ($for
            && ($for->hasExtension(WorkflowApplicable::class)
                || $for->hasExtension(FileWorkflowApplicable::class))
        ) {
            $this->TargetClass = DataObject::getSchema()->baseDataClass($for);
            $this->TargetID = $for->ID;
        }

        // lets create the first WorkflowActionInstance.
        $action = $definition->getInitialAction()->getInstanceForWorkflow();
        $action->WorkflowID = $this->ID;
        $action->write();

        $title = $for && $for->hasField('Title')
            ? sprintf(_t('WorkflowInstance.TITLE_FOR_DO', '%s - %s'), $definition->Title, $for->Title)
            : sprintf(_t('WorkflowInstance.TITLE_STUB', 'Instance #%s of %s'), $this->ID, $definition->Title);

        $this->Title           = $title;
        $this->DefinitionID    = $definition->ID;
        $this->CurrentActionID = $action->ID;
        $this->InitiatorID     = Security::getCurrentUser()->ID;
        $this->write();

        $this->Users()->addMany($definition->Users());
        $this->Groups()->addMany($definition->Groups());
    }