REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.67 KB
Close
/home/nshryvcy/himaltourism.com/wp-content/plugins/mailpoet/lib/Automation/Engine/Builder/DuplicateAutomationController.php
Text
Base64
<?php declare(strict_types = 1); namespace MailPoet\Automation\Engine\Builder; if (!defined('ABSPATH')) exit; use MailPoet\Automation\Engine\Data\Automation; use MailPoet\Automation\Engine\Data\NextStep; use MailPoet\Automation\Engine\Data\Step; use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Exceptions\InvalidStateException; use MailPoet\Automation\Engine\Storage\AutomationStorage; use MailPoet\Automation\Engine\WordPress; use MailPoet\Util\Security; class DuplicateAutomationController { /** @var WordPress */ private $wordPress; /** @var AutomationStorage */ private $automationStorage; public function __construct( WordPress $wordPress, AutomationStorage $automationStorage ) { $this->wordPress = $wordPress; $this->automationStorage = $automationStorage; } public function duplicateAutomation(int $id): Automation { $automation = $this->automationStorage->getAutomation($id); if (!$automation) { throw Exceptions::automationNotFound($id); } $duplicate = new Automation( $this->getName($automation->getName()), $this->getSteps($automation->getSteps()), $this->wordPress->wpGetCurrentUser() ); $duplicate->setStatus(Automation::STATUS_DRAFT); $automationId = $this->automationStorage->createAutomation($duplicate); $savedAutomation = $this->automationStorage->getAutomation($automationId); if (!$savedAutomation) { throw new InvalidStateException('Automation not found.'); } return $savedAutomation; } private function getName(string $name): string { // translators: %s is the original automation name. $newName = sprintf(__('Copy of %s', 'mailpoet'), $name); $maxLength = $this->automationStorage->getNameColumnLength(); if (strlen($newName) > $maxLength) { $append = '…'; return substr($newName, 0, $maxLength - strlen($append)) . $append; } return $newName; } /** * @param Step[] $steps * @return Step[] */ private function getSteps(array $steps): array { $newIds = []; foreach ($steps as $step) { $id = $step->getId(); $newIds[$id] = $id === 'root' ? 'root' : $this->getId(); } $newSteps = []; foreach ($steps as $step) { $newId = $newIds[$step->getId()]; $newSteps[$newId] = new Step( $newId, $step->getType(), $step->getKey(), $step->getArgs(), array_map(function (NextStep $nextStep) use ($newIds): NextStep { return new NextStep($newIds[$nextStep->getId()]); }, $step->getNextSteps()) ); } return $newSteps; } private function getId(): string { return Security::generateRandomString(16); } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 6
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
CreateAutomationFromTemplateController.php
1.55 KB
lrw-r--r--
2023-04-04 05:35:40
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DeleteAutomationController.php
912 B
lrw-r--r--
2023-04-04 05:35:40
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
DuplicateAutomationController.php
2.67 KB
lrw-r--r--
2023-04-04 05:35:40
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
index.php
0 B
lrw-r--r--
2023-04-04 05:35:40
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
UpdateAutomationController.php
4.36 KB
lrw-r--r--
2023-04-04 05:35:40
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
UpdateStepsController.php
1.08 KB
lrw-r--r--
2023-04-04 05:35:40
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).