PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.65.0
MailPoet – Newsletters, Email Marketing, and Automation v3.65.0
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 3.65.0, at lib/Form/FormSaveController.php

44 lines 1021 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailPoet\Form;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\Entities\FormEntity;
9 use MailPoet\WP\Functions as WPFunctions;
10 use MailPoetVendor\Carbon\Carbon;
11 use MailPoetVendor\Doctrine\ORM\EntityManager;
12
13 class FormSaveController {
14 /** @var EntityManager */
15 private $entityManager;
16
17 /** @var WPFunctions */
18 private $wp;
19
20 public function __construct(
21 EntityManager $entityManager,
22 WPFunctions $wp
23 ) {
24 $this->entityManager = $entityManager;
25 $this->wp = $wp;
26 }
27
28 public function duplicate(FormEntity $formEntity): FormEntity {
29 $duplicate = clone $formEntity;
30 $duplicate->setName(sprintf(__('Copy of %s', 'mailpoet'), $formEntity->getName()));
31
32 // reset timestamps
33 $now = Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
34 $duplicate->setCreatedAt($now);
35 $duplicate->setUpdatedAt($now);
36 $duplicate->setDeletedAt(null);
37
38 $this->entityManager->persist($duplicate);
39 $this->entityManager->flush();
40
41 return $duplicate;
42 }
43 }
44