PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 5.3.4
MailPoet – Newsletters, Email Marketing, and Automation v5.3.4
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / Form / FormSaveController.php

FormSaveController.php in MailPoet – Newsletters, Email Marketing, and Automation 5.3.4, at lib/Form/FormSaveController.php

39 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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