| 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 |
|