1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Cli\Plugins\DebugSendPlugin |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 7 |
13
|
|
|
* |
14
|
|
|
* @author Marcus Döllerer <[email protected]> |
15
|
|
|
* @copyright 2020 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-cli |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli\Plugins; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Console\Question\Question; |
24
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
25
|
|
|
use TechDivision\Import\Configuration\SwiftMailerConfigurationInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Plugin that creates and sends a debug report via email. |
29
|
|
|
* |
30
|
|
|
* @author Marcus Döllerer <[email protected]> |
31
|
|
|
* @copyright 2020 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/techdivision/import |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class DebugSendPlugin extends AbstractConsolePlugin |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Process the plugin functionality. |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function process() |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// retrieve the SwiftMailer configuration |
48
|
|
|
$swiftMailerConfiguration = $this->getPluginConfiguration()->getSwiftMailer(); |
49
|
|
|
|
50
|
|
|
// retrieve the question helper |
51
|
|
|
$questionHelper = $this->getHelper('question'); |
52
|
|
|
|
53
|
|
|
// use the configured SwiftMail recipient address as default if possible |
54
|
|
|
if ($swiftMailerConfiguration instanceof SwiftMailerConfigurationInterface && $swiftMailerConfiguration->hasParam('to')) { |
55
|
|
|
$recipient = $swiftMailerConfiguration->getParam('to'); |
56
|
|
|
// ask the user for the recipient address to send the debug report to |
57
|
|
|
$recipientQuestion = new Question( |
58
|
|
|
"<question>Please enter the email address of the debug report recipient (Configured: " . $recipient . "):\n</question>", |
59
|
|
|
$recipient |
60
|
|
|
); |
61
|
|
|
} else { |
62
|
|
|
$recipientQuestion = new Question( |
63
|
|
|
"<question>Please enter the email address of the debug report recipient:\n</question>" |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// ask the user to confirm the configured recipient address or enter a new one |
68
|
|
|
$recipient = $questionHelper->ask($this->getInput(), $this->getOutput(), $recipientQuestion); |
|
|
|
|
69
|
|
|
|
70
|
|
|
// warn the user about the impact of submitting their report and ask for confirmation |
71
|
|
|
$confirmationQuestion = new ConfirmationQuestion( |
72
|
|
|
"<comment>The debug report may contain confidential information (depending on the data you were importing).\n</comment>" |
73
|
|
|
. "<question>Do you really want to send the report to " . $recipient . "? (Y/n)\n</question>" |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
// abort the operation if the user does not confirm with 'y' or enter |
77
|
|
|
if (!$questionHelper->ask($this->getInput(), $this->getOutput(), $confirmationQuestion)) { |
78
|
|
|
$this->getOutput()->writeln('<info>Aborting operation - debug report has NOT been sent.</info>'); |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->getOutput()->writeln('<info>The debug report has successfully been submitted to ' . $recipient . '</info>'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|