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 Restore extends Command |
||
15 | { |
||
16 | protected function configure() |
||
17 | { |
||
18 | $this->setName('revision:restore') |
||
19 | ->addArgument('tableName', Argument::REQUIRED, "Table name") |
||
20 | ->addArgument('originalId', Argument::REQUIRED, "Original Id") |
||
21 | ->addArgument('revisionId', Argument::REQUIRED, "Revision id") |
||
22 | ->setDescription('Restore a record from a specific revision of a table'); |
||
23 | } |
||
24 | |||
25 | protected function execute(Input $input, Output $output) |
||
26 | { |
||
27 | $output->writeln('<info>Processing...</info>'); |
||
28 | |||
29 | $tableName = trim($input->getArgument('tableName')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
30 | $originalId = trim($input->getArgument('originalId')); |
||
31 | $revisionId = trim($input->getArgument('revisionId')); |
||
32 | |||
33 | try { |
||
34 | (new RevisionAPI())->restoreAPI($tableName, (int)$originalId, (int)$revisionId); |
||
35 | $output->writeln('<info>...Complete successfully.</info>'); |
||
36 | } catch (Exception $e) { |
||
37 | $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 |