<commit_before><?php

namespace Backend\Modules\Pages\Actions;

use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex;
use Backend\Core\Engine\Exception as BackendException;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Pages\Domain\Page\Page;
use Backend\Modules\Pages\Domain\Page\PageRepository;
use Backend\Modules\Pages\Engine\Model as BackendPagesModel;
use Exception;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * BackendPagesCopy
 * This is the copy-action, it will copy pages from one language to another
 * Remark :    IMPORTANT existing data will be removed, this feature is also experimental!
 */
class Copy extends BackendBaseActionIndex
{
    public function execute(): void
    {
        // call parent, this will probably add some general CSS/JS or other required files
        parent::execute();

        // get parameters
        $from = $this->getRequest()->query->get('from');
        $to = $this->getRequest()->query->get('to');
        $pageId = $this->getRequest()->query->get('id');

        // validate
        if ($from === null) {
            throw new BackendException('Specify a from-parameter.');
        }
        if ($to === null) {
            throw new BackendException('Specify a to-parameter.');
        }

        $page = null;
        if ($pageId !== null) {
            /** @var PageRepository $pageRepository */
            $pageRepository = $this->get(PageRepository::class);
            $page = $pageRepository->findOneBy(['id' => $pageId]);

            if (!$page instanceof Page) {
                throw new NotFoundHttpException();
            }
        }

        // copy pages
        try {
            BackendPagesModel::copy($from, $to, $page);
        } catch (Exception $e) {
            throw new NotFoundHttpException();
        }

        // redirect
        $this->redirect(BackendModel::createUrlForAction('Index') . '&report=copy-added&var=' . rawurlencode($to));
    }
}<commit_msg>Change copy action to use the copy form<commit_after><?php

namespace Backend\Modules\Pages\Actions;

use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex;
use Backend\Core\Engine\Exception as BackendException;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Pages\Domain\Page\CopyPageDataTransferObject;
use Backend\Modules\Pages\Domain\Page\Form\CopyPageType;
use Backend\Modules\Pages\Engine\Model as BackendPagesModel;
use Exception;

/**
 * BackendPagesCopy
 * This is the copy-action, it will copy pages from one language to another
 * Remark :    IMPORTANT existing data will be removed, this feature is also experimental!
 */
class Copy extends BackendBaseActionIndex
{
    public function execute(): void
    {
        // call parent, this will probably add some general CSS/JS or other required files
        parent::execute();

        $form = $this->createForm(CopyPageType::class, new CopyPageDataTransferObject());
        $form->handleRequest($this->getRequest());

        if (!$form->isSubmitted() || !$form->isValid()) {
            $this->redirect(BackendModel::createUrlForAction('Index') . '&error=error-copy');
        }

        /** @var CopyPageDataTransferObject $data */
        $data = $form->getData();

        // validate
        if ($data->from === null) {
            throw new BackendException('Specify a from parameter.');
        }
        if ($data->to === null) {
            throw new BackendException('Specify a to parameter.');
        }

        // copy pages
        try {
            BackendPagesModel::copy($data->from, $data->to, $data->pageToCopy);
        } catch (Exception $e) {
            $this->redirect(
                BackendModel::createUrlForAction('Edit')
                . '&id='
                . $data->pageToCopy->getRevisionId()
                . '&error=error-copy'
            );
        }

        // redirect
        $this->redirect(
            BackendModel::createUrlForAction('Index') . '&report=copy-added&var=' . rawurlencode($data->to)
        );
    }
}
{'fraction_non_alphanumeric': 0.1277695716395864, 'fraction_numerical': 0.0, 'mean_word_length': 2.5892226148409896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '2878416', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1104, 'n_words': 269}