<commit_before><?php

/**
 * Class VersionedDataObjectDetailsForm
 */
class VersionedDataObjectDetailsForm extends GridFieldDetailForm
{
}

class VersionedDataObjectDetailsForm_ItemRequest extends GridFieldDetailForm_ItemRequest
{
    private static $allowed_actions = array(
        'edit',
        'view',
        'ItemEditForm'
    );

    /**
     * @return Form
     */
    public function ItemEditForm()
    {
        $form = parent::ItemEditForm();
        /* @var $actions FieldList */
        if ($form instanceof Form) {
            $actions = $form->Actions();

            $actions->replaceField(
                'action_doSave',
                FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))
                    ->setAttribute('data-icon', 'accept')
                    ->setAttribute('data-icon-alternate', 'addpage')
                    ->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))
                    ->setUseButtonTag(true)
            );

            $published = $this->record->isPublished();

            /* @var $publish FormAction */
            $publish = FormAction::create(
                'publish',
                $published ? _t('SiteTree.BUTTONPUBLISHED', 'Published') : _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish')
            )
                ->setAttribute('data-icon', 'accept')
                ->setAttribute('data-icon-alternate', 'disk')
                ->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))
                ->setUseButtonTag(true);

            if ($this->record->stagesDiffer('Stage', 'Live') && $published) {
                $publish->addExtraClass('ss-ui-alternate');

                $actions->push(
                    FormAction::create(
                        'rollback',
                        _t(
                            'SiteTree.BUTTONCANCELDRAFT',
                            'Cancel draft changes'
                        )
                    )->setDescription(
                            _t(
                                'SiteTree.BUTTONCANCELDRAFTDESC',
                                'Delete your draft and revert to the currently published page'
                            )
                        )
                );
            }

            $actions->push($publish);

            if ($published) {
                /* @var $unpublish FormAction */
                $unpublish = FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'))
                    ->addExtraClass('ss-ui-action-destructive');

                $actions->push($unpublish);

                $actions->removeByName('action_doDelete');
            }

        }

        return $form;
    }

    /**
     * @param $data
     * @param $form
     * @return HTMLText|SS_HTTPResponse|ViewableData_Customised
     */
    public function save($data, $form)
    {
        $reading_mode = \Versioned::get_reading_mode();
        \Versioned::set_reading_mode('Stage.Stage');

        $value = $this->doSave($data, $form);

        \Versioned::set_reading_mode($reading_mode);
        return $value;
    }

    /**
     * @param $data
     * @param $form
     * @return HTMLText|SS_HTTPResponse|ViewableData_Customised
     */
    public function publish($data, $form)
    {
        $new_record = $this->record->ID == 0;<commit_msg>Fix the delete action so that it deletes from the right table when the reading mode is Stage.Live while in the CMS<commit_after><?php

/**
 * Class VersionedDataObjectDetailsForm
 */
class VersionedDataObjectDetailsForm extends GridFieldDetailForm
{
}

class VersionedDataObjectDetailsForm_ItemRequest extends GridFieldDetailForm_ItemRequest
{
    private static $allowed_actions = array(
        'edit',
        'view',
        'ItemEditForm'
    );

    /**
     * @return Form
     */
    public function ItemEditForm()
    {
        $form = parent::ItemEditForm();
        /* @var $actions FieldList */
        if ($form instanceof Form) {
            $actions = $form->Actions();

            $actions->replaceField(
                'action_doSave',
                FormAction::create('save', _t('SiteTree.BUTTONSAVED', 'Saved'))
                    ->setAttribute('data-icon', 'accept')
                    ->setAttribute('data-icon-alternate', 'addpage')
                    ->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))
                    ->setUseButtonTag(true)
            );

            $published = $this->record->isPublished();

            /* @var $publish FormAction */
            $publish = FormAction::create(
                'publish',
                $published ? _t('SiteTree.BUTTONPUBLISHED', 'Published') : _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish')
            )
                ->setAttribute('data-icon', 'accept')
                ->setAttribute('data-icon-alternate', 'disk')
                ->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))
                ->setUseButtonTag(true);

            if ($this->record->stagesDiffer('Stage', 'Live') && $published) {
                $publish->addExtraClass('ss-ui-alternate');

                $actions->push(
                    FormAction::create(
                        'rollback',
                        _t(
                            'SiteTree.BUTTONCANCELDRAFT',
                            'Cancel draft changes'
                        )
                    )->setDescription(
                            _t(
                                'SiteTree.BUTTONCANCELDRAFTDESC',
                                'Delete your draft and revert to the currently published page'
                            )
                        )
                );
            }

            $actions->push($publish);

            if ($published) {
                /* @var $unpublish FormAction */
                $unpublish = FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'))
                    ->addExtraClass('ss-ui-action-destructive');

                $actions->push($unpublish);

                $actions->removeByName('action_doDelete');
            }
        }

        return $form;
    }

    /**
     * @param $data
     * @param $form
     * @return HTMLText|SS_HTTPResponse|ViewableData_Customised
     */
    public function save($data, $form)
    {
        $reading_mode = \Versioned::get_reading_mode();
        \Versioned::set_reading_mode('Stage.Stage');

        $value = $this->doSave($data, $form);

        \Versioned::set_reading_mode($reading_mode);
        return $value;
    }

    /**
     * @param $data
     * @param $form
     * @return bool|SS_HTTPResponse
     */
    public function doDelete($data, $form)
    {
        $reading_mode = \Versioned::get_reading_mode();
        \Versioned::set_reading_mode('Stage.Stage');

        $value = parent::doDelete($data, $form);

        \Versioned::set_reading_mode($reading_mode);
        return $value;
    }

    /**
     * @param $data
     * @param $form
     * @return HTMLText|SS_HTTPResponse|ViewableData_Customised
     */
    public function publish($data, $form)
    {
        $new_record = $this->record->ID == 0;
{'fraction_non_alphanumeric': 0.12720264317180616, 'fraction_numerical': 0.00027533039647577095, 'mean_word_length': 1.664099743307664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '808586', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1892, 'n_words': 327}