Block
1 week ago
Listing
1 month ago
RestApi
1 month ago
Templates
2 years ago
Util
2 months ago
ApiDataSanitizer.php
2 weeks ago
AssetsController.php
2 months ago
BlockStylesRenderer.php
3 years ago
BlockWrapperRenderer.php
3 years ago
BlocksRenderer.php
1 week ago
DisplayFormInWPContent.php
2 months ago
FormHtmlSanitizer.php
1 month ago
FormMessageController.php
4 years ago
FormSaveController.php
1 year ago
FormsRepository.php
1 year ago
PreviewPage.php
2 months ago
PreviewWidget.php
1 year ago
Renderer.php
2 months ago
Widget.php
2 months ago
index.php
3 years ago
FormSaveController.php
39 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Form; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\FormEntity; |
| 9 | use MailPoetVendor\Carbon\Carbon; |
| 10 | use MailPoetVendor\Doctrine\ORM\EntityManager; |
| 11 | |
| 12 | class FormSaveController { |
| 13 | /** @var EntityManager */ |
| 14 | private $entityManager; |
| 15 | |
| 16 | public function __construct( |
| 17 | EntityManager $entityManager |
| 18 | ) { |
| 19 | $this->entityManager = $entityManager; |
| 20 | } |
| 21 | |
| 22 | public function duplicate(FormEntity $formEntity): FormEntity { |
| 23 | $duplicate = clone $formEntity; |
| 24 | // translators: %s is name of the form which has been duplicated. |
| 25 | $duplicate->setName(sprintf(__('Copy of %s', 'mailpoet'), $formEntity->getName())); |
| 26 | |
| 27 | // reset timestamps |
| 28 | $now = Carbon::now()->millisecond(0); |
| 29 | $duplicate->setCreatedAt($now); |
| 30 | $duplicate->setUpdatedAt($now); |
| 31 | $duplicate->setDeletedAt(null); |
| 32 | |
| 33 | $this->entityManager->persist($duplicate); |
| 34 | $this->entityManager->flush(); |
| 35 | |
| 36 | return $duplicate; |
| 37 | } |
| 38 | } |
| 39 |