• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 19117175691

05 Nov 2025 09:40PM UTC coverage: 39.847%. First build
19117175691

Pull #5754

github

web-flow
Merge 499423ca1 into 681cce019
Pull Request #5754: feat: preserve previous root cert

86 of 120 new or added lines in 10 files covered. (71.67%)

4633 of 11627 relevant lines covered (39.85%)

3.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/Command/Developer/Reset.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Command\Developer;
10

11
use OC\Core\Command\Base;
12
use OCA\Libresign\AppInfo\Application;
13
use OCP\IAppConfig;
14
use OCP\IConfig;
15
use OCP\IDBConnection;
16
use Psr\Log\LoggerInterface;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20

21
class Reset extends Base {
22
        public function __construct(
23
                private IConfig $config,
24
                private IAppConfig $appConfig,
25
                private IDBConnection $db,
26
                private LoggerInterface $logger,
27
        ) {
28
                parent::__construct();
×
29
        }
30

31
        public function isEnabled(): bool {
32
                return $this->config->getSystemValue('debug', false) === true;
×
33
        }
34

35
        protected function configure(): void {
36
                $this
×
37
                        ->setName('libresign:developer:reset')
×
38
                        ->setDescription('Clean all LibreSign data')
×
39
                        ->addOption(
×
40
                                name: 'all',
×
41
                                shortcut: null,
×
42
                                mode: InputOption::VALUE_NONE,
×
43
                                description: 'Reset all'
×
44
                        )
×
45
                        ->addOption(
×
46
                                name: 'notifications',
×
47
                                shortcut: null,
×
48
                                mode: InputOption::VALUE_OPTIONAL,
×
49
                                description: 'Reset notifications'
×
50
                        )
×
51
                        ->addOption(
×
52
                                name: 'activity',
×
53
                                shortcut: null,
×
54
                                mode: InputOption::VALUE_OPTIONAL,
×
55
                                description: 'Reset activity'
×
56
                        )
×
57
                        ->addOption(
×
58
                                name: 'identify',
×
59
                                shortcut: null,
×
60
                                mode: InputOption::VALUE_NONE,
×
61
                                description: 'Reset identify'
×
62
                        )
×
63
                        ->addOption(
×
64
                                name: 'signrequest',
×
65
                                shortcut: null,
×
66
                                mode: InputOption::VALUE_NONE,
×
67
                                description: 'Reset sign request'
×
68
                        )
×
69
                        ->addOption(
×
70
                                name: 'file',
×
71
                                shortcut: null,
×
72
                                mode: InputOption::VALUE_NONE,
×
73
                                description: 'Reset file'
×
74
                        )
×
75
                        ->addOption(
×
76
                                name: 'fileelement',
×
77
                                shortcut: null,
×
78
                                mode: InputOption::VALUE_NONE,
×
79
                                description: 'Reset file element'
×
80
                        )
×
NEW
81
                        ->addOption(
×
NEW
82
                                name: 'crl',
×
NEW
83
                                shortcut: null,
×
NEW
84
                                mode: InputOption::VALUE_NONE,
×
NEW
85
                                description: 'Reset crl',
×
NEW
86
                        )
×
87
                        ->addOption(
×
88
                                name: 'userelement',
×
89
                                shortcut: null,
×
90
                                mode: InputOption::VALUE_NONE,
×
91
                                description: 'Reset user element'
×
92
                        )
×
93
                        ->addOption(
×
94
                                name: 'config',
×
95
                                shortcut: null,
×
96
                                mode: InputOption::VALUE_NONE,
×
97
                                description: 'Reset config'
×
98
                        )
×
99
                ;
×
100
        }
101

102
        protected function execute(InputInterface $input, OutputInterface $output): int {
103
                $ok = false;
×
104

105
                try {
106
                        $all = $input->getOption('all');
×
107
                        if ($input->getOption('notifications') || $all) {
×
108
                                $this->resetNotifications((string)$input->getOption('notifications'));
×
109
                                $ok = true;
×
110
                        }
111
                        if ($input->getOption('activity') || $all) {
×
112
                                $this->resetActivity((string)$input->getOption('activity'));
×
113
                                $ok = true;
×
114
                        }
115
                        if ($input->getOption('identify') || $all) {
×
116
                                $this->resetIdentifyMethods();
×
117
                                $ok = true;
×
118
                        }
119
                        if ($input->getOption('signrequest') || $all) {
×
120
                                $this->resetSignRequest();
×
121
                                $ok = true;
×
122
                        }
123
                        if ($input->getOption('file') || $all) {
×
124
                                $this->resetFile();
×
125
                                $ok = true;
×
126
                        }
127
                        if ($input->getOption('fileelement') || $all) {
×
128
                                $this->resetFileElement();
×
129
                                $ok = true;
×
130
                        }
NEW
131
                        if ($input->getOption('crl') || $all) {
×
NEW
132
                                $this->resetCrl();
×
NEW
133
                                $ok = true;
×
134
                        }
135
                        if ($input->getOption('userelement') || $all) {
×
136
                                $this->resetUserElement();
×
137
                                $ok = true;
×
138
                        }
139
                        if ($input->getOption('config') || $all) {
×
140
                                $this->resetConfig();
×
141
                                $ok = true;
×
142
                        }
143
                } catch (\Exception $e) {
×
144
                        $this->logger->error($e->getMessage());
×
145
                        throw $e;
×
146
                }
147

148
                if (!$ok) {
×
149
                        $output->writeln('<error>Please inform what you want to reset</error>');
×
150
                        $output->writeln('<error>--all to all</error>');
×
151
                        $output->writeln('<error>--help to check the available options</error>');
×
152
                        return 1;
×
153
                }
154
                return 0;
×
155
        }
156

157
        private function resetNotifications(string $user): void {
158
                try {
159
                        $delete = $this->db->getQueryBuilder();
×
160
                        $delete->delete('notifications')
×
161
                                ->where($delete->expr()->eq('app', $delete->createNamedParameter(Application::APP_ID)));
×
162
                        if ($user) {
×
163
                                $delete->andWhere($delete->expr()->eq('user', $delete->createNamedParameter($user)));
×
164
                        }
165
                        $delete->executeStatement();
×
166
                } catch (\Throwable) {
×
167
                }
168
        }
169

170
        private function resetActivity(string $user): void {
171
                try {
172
                        $delete = $this->db->getQueryBuilder();
×
173
                        $delete->delete('activity_mq')
×
174
                                ->where($delete->expr()->eq('amq_appid', $delete->createNamedParameter(Application::APP_ID)));
×
175
                        if ($user) {
×
176
                                $delete->andWhere($delete->expr()->eq('amq_affecteduser', $delete->createNamedParameter($user)));
×
177
                        }
178
                        $delete->executeStatement();
×
179

180
                        $delete = $this->db->getQueryBuilder();
×
181
                        $delete->delete('activity')
×
182
                                ->where($delete->expr()->eq('app', $delete->createNamedParameter(Application::APP_ID)));
×
183
                        if ($user) {
×
184
                                $delete->andWhere($delete->expr()->eq('user', $delete->createNamedParameter($user)));
×
185
                        }
186
                        $delete->executeStatement();
×
187
                } catch (\Throwable) {
×
188
                }
189
        }
190

191
        private function resetIdentifyMethods(): void {
192
                try {
193
                        $delete = $this->db->getQueryBuilder();
×
194
                        $delete->delete('libresign_identify_method')
×
195
                                ->executeStatement();
×
196
                } catch (\Throwable) {
×
197
                }
198
        }
199

200
        private function resetSignRequest(): void {
201
                try {
202
                        $delete = $this->db->getQueryBuilder();
×
203
                        $delete->delete('libresign_sign_request')
×
204
                                ->executeStatement();
×
205
                } catch (\Throwable) {
×
206
                }
207
        }
208

209
        private function resetFile(): void {
210
                try {
211
                        $delete = $this->db->getQueryBuilder();
×
212
                        $delete->delete('libresign_file')
×
213
                                ->executeStatement();
×
214
                } catch (\Throwable) {
×
215
                }
216
        }
217

218
        private function resetFileElement(): void {
219
                try {
220
                        $delete = $this->db->getQueryBuilder();
×
221
                        $delete->delete('libresign_file_element')
×
222
                                ->executeStatement();
×
223
                } catch (\Throwable) {
×
224
                }
225
        }
226

227
        private function resetCrl(): void {
228
                try {
NEW
229
                        $delete = $this->db->getQueryBuilder();
×
NEW
230
                        $delete->delete('libresign_crl')
×
NEW
231
                                ->executeStatement();
×
NEW
232
                } catch (\Throwable) {
×
233
                }
234
        }
235

236
        private function resetUserElement(): void {
237
                try {
238
                        $delete = $this->db->getQueryBuilder();
×
239
                        $delete->delete('libresign_user_element')
×
240
                                ->executeStatement();
×
241
                } catch (\Throwable) {
×
242
                }
243
        }
244

245
        private function resetConfig(): void {
246
                try {
247
                        $keys = $this->appConfig->getKeys(Application::APP_ID);
×
248
                        foreach ($keys as $key) {
×
249
                                if ($key === 'enabled' || $key === 'installed_version') {
×
250
                                        continue;
×
251
                                }
252
                                $this->appConfig->deleteKey(Application::APP_ID, $key);
×
253
                        }
254
                } catch (\Throwable) {
×
255
                }
256
        }
257
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc