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 Home extends Command |
||
15 | { |
||
16 | protected function configure() |
||
17 | { |
||
18 | $this->setName('revision:list') |
||
19 | ->addArgument('tableName', Argument::REQUIRED, "Table name") |
||
20 | ->addArgument('recordId', Argument::REQUIRED, "Record Id") |
||
21 | ->addArgument('page', Argument::OPTIONAL, "Current page number") |
||
22 | ->addArgument('perPage', Argument::OPTIONAL, "Per page number") |
||
23 | ->setDescription('Get the revision list of a specific record of a table'); |
||
24 | } |
||
25 | |||
26 | protected function execute(Input $input, Output $output) |
||
27 | { |
||
28 | $output->writeln('<info>Processing...</info>'); |
||
29 | |||
30 | $tableName = trim($input->getArgument('tableName')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
31 | $recordId = trim($input->getArgument('recordId')); |
||
32 | $page = $input->getArgument('page') ? (int)trim($input->getArgument('page')) : 1; |
||
33 | $perPage = $input->getArgument('perPage') ? (int)trim($input->getArgument('perPage')) : 5; |
||
34 | |||
35 | $result = (new RevisionAPI())->listAPI($tableName, (int)$recordId, (int)$page, (int)$perPage); |
||
36 | if ($result['success'] === true) { |
||
37 | $list = $result['data']['dataSource']; |
||
38 | foreach ($list as $item) { |
||
39 | $output->writeln('<comment> - [' . $item['id'] . '] ' . $item['title'] . ' @ ' . $item['create_time'] . '</comment>'); |
||
40 | } |
||
41 | } else { |
||
42 | $output->writeln('<error>' . $result['message'] . '</error>'); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 |