1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\Pages\Actions; |
4
|
|
|
|
5
|
|
|
use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex; |
6
|
|
|
use Backend\Core\Engine\Exception as BackendException; |
7
|
|
|
use Backend\Core\Engine\Model as BackendModel; |
8
|
|
|
use Backend\Core\Language\Locale; |
9
|
|
|
use Backend\Modules\Pages\Domain\Page\CopyPageDataTransferObject; |
10
|
|
|
use Backend\Modules\Pages\Domain\Page\Form\CopyPageToOtherLanguageType; |
11
|
|
|
use Backend\Modules\Pages\Domain\Page\PageRepository; |
12
|
|
|
use Exception; |
13
|
|
|
use ForkCMS\Utility\Module\CopyContentToOtherLocale\CopyContentFromModulesToOtherLocaleManager; |
14
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* BackendPagesCopy |
18
|
|
|
* This is the copy-action, it will copy pages from one language to another |
19
|
|
|
* Remark : IMPORTANT existing data will be removed, this feature is also experimental! |
20
|
|
|
*/ |
21
|
|
|
class PageCopyToOtherLanguage extends BackendBaseActionIndex |
22
|
|
|
{ |
23
|
|
|
/** @var CopyContentFromModulesToOtherLocaleManager */ |
24
|
|
|
private $copyManager; |
25
|
|
|
|
26
|
|
|
public function setKernel(KernelInterface $kernel = null): void |
27
|
|
|
{ |
28
|
|
|
parent::setKernel($kernel); |
29
|
|
|
|
30
|
|
|
$this->copyManager = $this->getContainer()->get(CopyContentFromModulesToOtherLocaleManager::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function execute(): void |
34
|
|
|
{ |
35
|
|
|
// call parent, this will probably add some general CSS/JS or other required files |
36
|
|
|
parent::execute(); |
37
|
|
|
|
38
|
|
|
$form = $this->createForm(CopyPageToOtherLanguageType::class, new CopyPageDataTransferObject()); |
39
|
|
|
$form->handleRequest($this->getRequest()); |
40
|
|
|
|
41
|
|
|
if (!$form->isSubmitted() || !$form->isValid()) { |
42
|
|
|
$this->redirect(BackendModel::createUrlForAction('PageIndex') . '&error=error-copy'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** @var CopyPageDataTransferObject $data */ |
46
|
|
|
$data = $form->getData(); |
47
|
|
|
|
48
|
|
|
// validate |
49
|
|
|
if ($data->from === null) { |
50
|
|
|
throw new BackendException('Specify a from parameter.'); |
51
|
|
|
} |
52
|
|
|
if ($data->to === null) { |
53
|
|
|
throw new BackendException('Specify a to parameter.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// copy pages |
57
|
|
|
try { |
58
|
|
|
$this->copyManager->copyOne( |
59
|
|
|
$data->pageToCopy, |
|
|
|
|
60
|
|
|
Locale::fromString($data->from), |
61
|
|
|
Locale::fromString($data->to) |
62
|
|
|
); |
63
|
|
|
} catch (Exception $e) { |
64
|
|
|
$this->redirect( |
65
|
|
|
BackendModel::createUrlForAction('PageEdit') |
66
|
|
|
. '&id=' |
67
|
|
|
. $data->pageToCopy->getId() |
|
|
|
|
68
|
|
|
. '&error=error-copy' |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// redirect |
73
|
|
|
$this->redirect( |
74
|
|
|
BackendModel::createUrlForAction('PageIndex') . '&report=copy-added&var=' . rawurlencode($data->to) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|