1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace aspirantzhang\octopusRevision\command; |
||
6 | |||
7 | use think\console\Command; |
||
8 | use think\console\Input; |
||
9 | use think\console\input\Argument; |
||
10 | use think\console\Output; |
||
11 | use think\Exception; |
||
12 | use aspirantzhang\octopusRevision\RevisionAPI; |
||
13 | |||
14 | class Save extends Command |
||
15 | { |
||
16 | protected function configure() |
||
17 | { |
||
18 | $this->setName('revision:save') |
||
19 | ->addArgument('revisionTitle', Argument::REQUIRED, "Revision title") |
||
20 | ->addArgument('tableName', Argument::REQUIRED, "Table name") |
||
21 | ->addArgument('originalId', Argument::REQUIRED, "Original id") |
||
22 | ->setDescription('Save a revision of a specific record of a table'); |
||
23 | } |
||
24 | |||
25 | protected function execute(Input $input, Output $output) |
||
26 | { |
||
27 | $output->writeln('<info>Processing...</info>'); |
||
28 | |||
29 | $revisionTitle = trim($input->getArgument('revisionTitle')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
30 | $tableName = trim($input->getArgument('tableName')); |
||
31 | $originalId = trim($input->getArgument('originalId')); |
||
32 | |||
33 | try { |
||
34 | $revisionId = (new RevisionAPI())->saveAPI($revisionTitle, $tableName, (int)$originalId); |
||
35 | $output->writeln('<comment>Revision ID: ' . $revisionId . '</comment>'); |
||
36 | $output->writeln('<info>...Complete successfully.</info>'); |
||
37 | } catch (Exception $e) { |
||
38 | $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 |