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

LibreSign / libresign / 19104825259

05 Nov 2025 02:12PM UTC coverage: 39.581%. First build
19104825259

Pull #5738

github

web-flow
Merge 0ad469eeb into da11e5511
Pull Request #5738: fix: force cache update

0 of 5 new or added lines in 1 file covered. (0.0%)

4570 of 11546 relevant lines covered (39.58%)

2.95 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
                        )
×
81
                        ->addOption(
×
82
                                name: 'userelement',
×
83
                                shortcut: null,
×
84
                                mode: InputOption::VALUE_NONE,
×
85
                                description: 'Reset user element'
×
86
                        )
×
87
                        ->addOption(
×
88
                                name: 'config',
×
89
                                shortcut: null,
×
90
                                mode: InputOption::VALUE_NONE,
×
91
                                description: 'Reset config'
×
92
                        )
×
93
                ;
×
94
        }
95

96
        protected function execute(InputInterface $input, OutputInterface $output): int {
97
                $ok = false;
×
98

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

138
                if (!$ok) {
×
139
                        $output->writeln('<error>Please inform what you want to reset</error>');
×
140
                        $output->writeln('<error>--all to all</error>');
×
141
                        $output->writeln('<error>--help to check the available options</error>');
×
142
                        return 1;
×
143
                }
144
                return 0;
×
145
        }
146

147
        private function resetNotifications(string $user): void {
148
                try {
149
                        $delete = $this->db->getQueryBuilder();
×
150
                        $delete->delete('notifications')
×
151
                                ->where($delete->expr()->eq('app', $delete->createNamedParameter(Application::APP_ID)));
×
152
                        if ($user) {
×
153
                                $delete->andWhere($delete->expr()->eq('user', $delete->createNamedParameter($user)));
×
154
                        }
155
                        $delete->executeStatement();
×
156
                } catch (\Throwable) {
×
157
                }
158
        }
159

160
        private function resetActivity(string $user): void {
161
                try {
162
                        $delete = $this->db->getQueryBuilder();
×
163
                        $delete->delete('activity_mq')
×
164
                                ->where($delete->expr()->eq('amq_appid', $delete->createNamedParameter(Application::APP_ID)));
×
165
                        if ($user) {
×
166
                                $delete->andWhere($delete->expr()->eq('amq_affecteduser', $delete->createNamedParameter($user)));
×
167
                        }
168
                        $delete->executeStatement();
×
169

170
                        $delete = $this->db->getQueryBuilder();
×
171
                        $delete->delete('activity')
×
172
                                ->where($delete->expr()->eq('app', $delete->createNamedParameter(Application::APP_ID)));
×
173
                        if ($user) {
×
174
                                $delete->andWhere($delete->expr()->eq('user', $delete->createNamedParameter($user)));
×
175
                        }
176
                        $delete->executeStatement();
×
177
                } catch (\Throwable) {
×
178
                }
179
        }
180

181
        private function resetIdentifyMethods(): void {
182
                try {
183
                        $delete = $this->db->getQueryBuilder();
×
184
                        $delete->delete('libresign_identify_method')
×
185
                                ->executeStatement();
×
186
                } catch (\Throwable) {
×
187
                }
188
        }
189

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

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

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

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

226
        private function resetConfig(): void {
227
                try {
NEW
228
                        $keys = $this->appConfig->getKeys(Application::APP_ID);
×
NEW
229
                        foreach ($keys as $key) {
×
NEW
230
                                if ($key === 'enabled' || $key === 'installed_version') {
×
NEW
231
                                        continue;
×
232
                                }
NEW
233
                                $this->appConfig->deleteKey(Application::APP_ID, $key);
×
234
                        }
235
                } catch (\Throwable) {
×
236
                }
237
        }
238
}
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