Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AccountUserAuditLogDownloadLogic
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 executeImpl
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Account;
6
7use PeServer\App\Models\Dao\Entities\UserAuditLogsEntityDao;
8use PeServer\App\Models\Domain\Page\PageLogicBase;
9use PeServer\Core\Archiver;
10use PeServer\Core\Mime;
11use PeServer\Core\Mvc\LogicCallMode;
12use PeServer\Core\Mvc\LogicParameter;
13use PeServer\Core\Mvc\Pagination;
14use PeServer\Core\Serialization\JsonSerializer;
15use PeServer\Core\Throws\InvalidOperationException;
16use PeServer\Core\TypeUtility;
17
18class AccountUserAuditLogDownloadLogic extends PageLogicBase
19{
20    #region define
21
22    public const RAW_LOG_SIZE = 2 * 1024 * 1024;
23
24    #endregion
25
26    public function __construct(LogicParameter $parameter)
27    {
28        parent::__construct($parameter);
29    }
30
31    #region PageLogicBase
32
33    protected function validateImpl(LogicCallMode $callMode): void
34    {
35        //NOP
36    }
37
38    protected function executeImpl(LogicCallMode $callMode): void
39    {
40        $userInfo = $this->getAuditUserInfo();
41        if ($userInfo === null) {
42            throw new InvalidOperationException();
43        }
44        $userId = $userInfo->getUserId();
45
46        // $pageNumber = Pagination::FIRST_PAGE_NUMBER;
47        // if ($callMode === LogicCallMode::Submit) {
48        //     $requestPageNumber = $this->getRequest('page_number');
49        //     if (TypeUtility::tryParseInteger($requestPageNumber, $temp)) {
50        //         $pageNumber = $temp;
51        //     }
52        // }
53
54        $database = $this->openDatabase();
55        $userAuditLogsEntityDao = new UserAuditLogsEntityDao($database);
56
57        $result = $userAuditLogsEntityDao->selectAuditLogsFromUserId($userId);
58        $jsonSerializer = new JsonSerializer();
59        $items = $jsonSerializer->save($result->rows);
60
61        if ($items->count() < self::RAW_LOG_SIZE) {
62            $this->setDownloadContent(Mime::JSON, "audit-log.json", $items);
63        } else {
64            $data = Archiver::compressGzip($items, 9);
65            $this->setDownloadContent(Mime::GZ, "audit-log.json.gz", $data);
66        }
67    }
68
69    #endregion
70}