@@ -39,98 +39,98 @@ |
||
39 | 39 | |
40 | 40 | class ResetPassword extends Command { |
41 | 41 | |
42 | - /** @var IUserManager */ |
|
43 | - protected $userManager; |
|
44 | - |
|
45 | - public function __construct(IUserManager $userManager) { |
|
46 | - $this->userManager = $userManager; |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('user:resetpassword') |
|
53 | - ->setDescription('Resets the password of the named user') |
|
54 | - ->addArgument( |
|
55 | - 'user', |
|
56 | - InputArgument::REQUIRED, |
|
57 | - 'Username to reset password' |
|
58 | - ) |
|
59 | - ->addOption( |
|
60 | - 'password-from-env', |
|
61 | - null, |
|
62 | - InputOption::VALUE_NONE, |
|
63 | - 'read password from environment variable OC_PASS' |
|
64 | - ) |
|
65 | - ; |
|
66 | - } |
|
67 | - |
|
68 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
69 | - $username = $input->getArgument('user'); |
|
70 | - |
|
71 | - /** @var $user \OCP\IUser */ |
|
72 | - $user = $this->userManager->get($username); |
|
73 | - if (is_null($user)) { |
|
74 | - $output->writeln('<error>User does not exist</error>'); |
|
75 | - return 1; |
|
76 | - } |
|
77 | - |
|
78 | - if ($input->getOption('password-from-env')) { |
|
79 | - $password = getenv('OC_PASS'); |
|
80 | - if (!$password) { |
|
81 | - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
82 | - return 1; |
|
83 | - } |
|
84 | - } elseif ($input->isInteractive()) { |
|
85 | - /** @var QuestionHelper $helper */ |
|
86 | - $helper = $this->getHelper('question'); |
|
87 | - |
|
88 | - if (\OCP\App::isEnabled('encryption')) { |
|
89 | - $output->writeln( |
|
90 | - '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
91 | - ); |
|
92 | - |
|
93 | - $question = new ConfirmationQuestion('Do you want to continue?'); |
|
94 | - if (!$helper->ask($input, $output, $question)) { |
|
95 | - return 1; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - $question = new Question('Enter a new password: '); |
|
100 | - $question->setHidden(true); |
|
101 | - $password = $helper->ask($input, $output, $question); |
|
102 | - |
|
103 | - if ($password === null) { |
|
104 | - $output->writeln("<error>Password cannot be empty!</error>"); |
|
105 | - return 1; |
|
106 | - } |
|
107 | - |
|
108 | - $question = new Question('Confirm the new password: '); |
|
109 | - $question->setHidden(true); |
|
110 | - $confirm = $helper->ask($input, $output, $question); |
|
111 | - |
|
112 | - if ($password !== $confirm) { |
|
113 | - $output->writeln("<error>Passwords did not match!</error>"); |
|
114 | - return 1; |
|
115 | - } |
|
116 | - } else { |
|
117 | - $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
118 | - return 1; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - try { |
|
123 | - $success = $user->setPassword($password); |
|
124 | - } catch (\Exception $e) { |
|
125 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
126 | - return 1; |
|
127 | - } |
|
128 | - |
|
129 | - if ($success) { |
|
130 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
131 | - } else { |
|
132 | - $output->writeln("<error>Error while resetting password!</error>"); |
|
133 | - return 1; |
|
134 | - } |
|
135 | - } |
|
42 | + /** @var IUserManager */ |
|
43 | + protected $userManager; |
|
44 | + |
|
45 | + public function __construct(IUserManager $userManager) { |
|
46 | + $this->userManager = $userManager; |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('user:resetpassword') |
|
53 | + ->setDescription('Resets the password of the named user') |
|
54 | + ->addArgument( |
|
55 | + 'user', |
|
56 | + InputArgument::REQUIRED, |
|
57 | + 'Username to reset password' |
|
58 | + ) |
|
59 | + ->addOption( |
|
60 | + 'password-from-env', |
|
61 | + null, |
|
62 | + InputOption::VALUE_NONE, |
|
63 | + 'read password from environment variable OC_PASS' |
|
64 | + ) |
|
65 | + ; |
|
66 | + } |
|
67 | + |
|
68 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
69 | + $username = $input->getArgument('user'); |
|
70 | + |
|
71 | + /** @var $user \OCP\IUser */ |
|
72 | + $user = $this->userManager->get($username); |
|
73 | + if (is_null($user)) { |
|
74 | + $output->writeln('<error>User does not exist</error>'); |
|
75 | + return 1; |
|
76 | + } |
|
77 | + |
|
78 | + if ($input->getOption('password-from-env')) { |
|
79 | + $password = getenv('OC_PASS'); |
|
80 | + if (!$password) { |
|
81 | + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
82 | + return 1; |
|
83 | + } |
|
84 | + } elseif ($input->isInteractive()) { |
|
85 | + /** @var QuestionHelper $helper */ |
|
86 | + $helper = $this->getHelper('question'); |
|
87 | + |
|
88 | + if (\OCP\App::isEnabled('encryption')) { |
|
89 | + $output->writeln( |
|
90 | + '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
91 | + ); |
|
92 | + |
|
93 | + $question = new ConfirmationQuestion('Do you want to continue?'); |
|
94 | + if (!$helper->ask($input, $output, $question)) { |
|
95 | + return 1; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + $question = new Question('Enter a new password: '); |
|
100 | + $question->setHidden(true); |
|
101 | + $password = $helper->ask($input, $output, $question); |
|
102 | + |
|
103 | + if ($password === null) { |
|
104 | + $output->writeln("<error>Password cannot be empty!</error>"); |
|
105 | + return 1; |
|
106 | + } |
|
107 | + |
|
108 | + $question = new Question('Confirm the new password: '); |
|
109 | + $question->setHidden(true); |
|
110 | + $confirm = $helper->ask($input, $output, $question); |
|
111 | + |
|
112 | + if ($password !== $confirm) { |
|
113 | + $output->writeln("<error>Passwords did not match!</error>"); |
|
114 | + return 1; |
|
115 | + } |
|
116 | + } else { |
|
117 | + $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
118 | + return 1; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + try { |
|
123 | + $success = $user->setPassword($password); |
|
124 | + } catch (\Exception $e) { |
|
125 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
126 | + return 1; |
|
127 | + } |
|
128 | + |
|
129 | + if ($success) { |
|
130 | + $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
131 | + } else { |
|
132 | + $output->writeln("<error>Error while resetting password!</error>"); |
|
133 | + return 1; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | } |
@@ -29,141 +29,141 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function(IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function(IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | } |
@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | interface IEntry extends JsonSerializable { |
33 | 33 | |
34 | - /** |
|
35 | - * @since 12.0 |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getFullName(); |
|
34 | + /** |
|
35 | + * @since 12.0 |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getFullName(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 12.0 |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function getEMailAddresses(); |
|
40 | + /** |
|
41 | + * @since 12.0 |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function getEMailAddresses(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 12.0 |
|
48 | - * @return string|null image URI |
|
49 | - */ |
|
50 | - public function getAvatar(); |
|
46 | + /** |
|
47 | + * @since 12.0 |
|
48 | + * @return string|null image URI |
|
49 | + */ |
|
50 | + public function getAvatar(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 12.0 |
|
54 | - * @param IAction $action an action to show in the contacts menu |
|
55 | - */ |
|
56 | - public function addAction(IAction $action); |
|
52 | + /** |
|
53 | + * @since 12.0 |
|
54 | + * @param IAction $action an action to show in the contacts menu |
|
55 | + */ |
|
56 | + public function addAction(IAction $action); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get an arbitrary property from the contact |
|
60 | - * |
|
61 | - * @since 12.0 |
|
62 | - * @param string $key |
|
63 | - * @return mixed the value of the property or null |
|
64 | - */ |
|
65 | - public function getProperty($key); |
|
58 | + /** |
|
59 | + * Get an arbitrary property from the contact |
|
60 | + * |
|
61 | + * @since 12.0 |
|
62 | + * @param string $key |
|
63 | + * @return mixed the value of the property or null |
|
64 | + */ |
|
65 | + public function getProperty($key); |
|
66 | 66 | } |
@@ -7,23 +7,23 @@ |
||
7 | 7 | |
8 | 8 | class RootCollection extends AbstractPrincipalCollection { |
9 | 9 | |
10 | - /** |
|
11 | - * This method returns a node for a principal. |
|
12 | - * |
|
13 | - * The passed array contains principal information, and is guaranteed to |
|
14 | - * at least contain a uri item. Other properties may or may not be |
|
15 | - * supplied by the authentication backend. |
|
16 | - * |
|
17 | - * @param array $principalInfo |
|
18 | - * @return AvatarHome |
|
19 | - */ |
|
20 | - public function getChildForPrincipal(array $principalInfo) { |
|
21 | - $avatarManager = \OC::$server->getAvatarManager(); |
|
22 | - return new AvatarHome($principalInfo, $avatarManager); |
|
23 | - } |
|
10 | + /** |
|
11 | + * This method returns a node for a principal. |
|
12 | + * |
|
13 | + * The passed array contains principal information, and is guaranteed to |
|
14 | + * at least contain a uri item. Other properties may or may not be |
|
15 | + * supplied by the authentication backend. |
|
16 | + * |
|
17 | + * @param array $principalInfo |
|
18 | + * @return AvatarHome |
|
19 | + */ |
|
20 | + public function getChildForPrincipal(array $principalInfo) { |
|
21 | + $avatarManager = \OC::$server->getAvatarManager(); |
|
22 | + return new AvatarHome($principalInfo, $avatarManager); |
|
23 | + } |
|
24 | 24 | |
25 | - public function getName() { |
|
26 | - return 'avatars'; |
|
27 | - } |
|
25 | + public function getName() { |
|
26 | + return 'avatars'; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | } |
@@ -33,87 +33,87 @@ |
||
33 | 33 | |
34 | 34 | class CalDAVRemoveEmptyValue implements IRepairStep { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $db; |
|
38 | - |
|
39 | - /** @var CalDavBackend */ |
|
40 | - private $calDavBackend; |
|
41 | - |
|
42 | - /** @var ILogger */ |
|
43 | - private $logger; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param IDBConnection $db |
|
47 | - * @param CalDavBackend $calDavBackend |
|
48 | - * @param ILogger $logger |
|
49 | - */ |
|
50 | - public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) { |
|
51 | - $this->db = $db; |
|
52 | - $this->calDavBackend = $calDavBackend; |
|
53 | - $this->logger = $logger; |
|
54 | - } |
|
55 | - |
|
56 | - public function getName() { |
|
57 | - return 'Fix broken values of calendar objects'; |
|
58 | - } |
|
59 | - |
|
60 | - public function run(IOutput $output) { |
|
61 | - $pattern = ';VALUE=:'; |
|
62 | - $count = $warnings = 0; |
|
63 | - |
|
64 | - $objects = $this->getInvalidObjects($pattern); |
|
65 | - |
|
66 | - $output->startProgress(count($objects)); |
|
67 | - foreach ($objects as $row) { |
|
68 | - $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | - $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
70 | - |
|
71 | - if ($data !== $calObject['calendardata']) { |
|
72 | - $output->advance(); |
|
73 | - |
|
74 | - try { |
|
75 | - $this->calDavBackend->getDenormalizedData($data); |
|
76 | - } catch (InvalidDataException $e) { |
|
77 | - $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
78 | - 'app' => 'dav', |
|
79 | - 'cal' => (int)$row['calendarid'], |
|
80 | - 'uri' => $row['uri'], |
|
81 | - ]); |
|
82 | - $warnings++; |
|
83 | - continue; |
|
84 | - } |
|
85 | - |
|
86 | - $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
87 | - $count++; |
|
88 | - } |
|
89 | - } |
|
90 | - $output->finishProgress(); |
|
91 | - |
|
92 | - if ($warnings > 0) { |
|
93 | - $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings)); |
|
94 | - } |
|
95 | - if ($count > 0) { |
|
96 | - $output->info(sprintf('Updated %d events', $count)); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - protected function getInvalidObjects($pattern) { |
|
101 | - $query = $this->db->getQueryBuilder(); |
|
102 | - $query->select(['calendarid', 'uri']) |
|
103 | - ->from('calendarobjects') |
|
104 | - ->where($query->expr()->like( |
|
105 | - 'calendardata', |
|
106 | - $query->createNamedParameter( |
|
107 | - '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
108 | - IQueryBuilder::PARAM_STR |
|
109 | - ), |
|
110 | - IQueryBuilder::PARAM_STR |
|
111 | - )); |
|
112 | - |
|
113 | - $result = $query->execute(); |
|
114 | - $rows = $result->fetchAll(); |
|
115 | - $result->closeCursor(); |
|
116 | - |
|
117 | - return $rows; |
|
118 | - } |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $db; |
|
38 | + |
|
39 | + /** @var CalDavBackend */ |
|
40 | + private $calDavBackend; |
|
41 | + |
|
42 | + /** @var ILogger */ |
|
43 | + private $logger; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param IDBConnection $db |
|
47 | + * @param CalDavBackend $calDavBackend |
|
48 | + * @param ILogger $logger |
|
49 | + */ |
|
50 | + public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) { |
|
51 | + $this->db = $db; |
|
52 | + $this->calDavBackend = $calDavBackend; |
|
53 | + $this->logger = $logger; |
|
54 | + } |
|
55 | + |
|
56 | + public function getName() { |
|
57 | + return 'Fix broken values of calendar objects'; |
|
58 | + } |
|
59 | + |
|
60 | + public function run(IOutput $output) { |
|
61 | + $pattern = ';VALUE=:'; |
|
62 | + $count = $warnings = 0; |
|
63 | + |
|
64 | + $objects = $this->getInvalidObjects($pattern); |
|
65 | + |
|
66 | + $output->startProgress(count($objects)); |
|
67 | + foreach ($objects as $row) { |
|
68 | + $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | + $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
70 | + |
|
71 | + if ($data !== $calObject['calendardata']) { |
|
72 | + $output->advance(); |
|
73 | + |
|
74 | + try { |
|
75 | + $this->calDavBackend->getDenormalizedData($data); |
|
76 | + } catch (InvalidDataException $e) { |
|
77 | + $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
78 | + 'app' => 'dav', |
|
79 | + 'cal' => (int)$row['calendarid'], |
|
80 | + 'uri' => $row['uri'], |
|
81 | + ]); |
|
82 | + $warnings++; |
|
83 | + continue; |
|
84 | + } |
|
85 | + |
|
86 | + $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
87 | + $count++; |
|
88 | + } |
|
89 | + } |
|
90 | + $output->finishProgress(); |
|
91 | + |
|
92 | + if ($warnings > 0) { |
|
93 | + $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings)); |
|
94 | + } |
|
95 | + if ($count > 0) { |
|
96 | + $output->info(sprintf('Updated %d events', $count)); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + protected function getInvalidObjects($pattern) { |
|
101 | + $query = $this->db->getQueryBuilder(); |
|
102 | + $query->select(['calendarid', 'uri']) |
|
103 | + ->from('calendarobjects') |
|
104 | + ->where($query->expr()->like( |
|
105 | + 'calendardata', |
|
106 | + $query->createNamedParameter( |
|
107 | + '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
108 | + IQueryBuilder::PARAM_STR |
|
109 | + ), |
|
110 | + IQueryBuilder::PARAM_STR |
|
111 | + )); |
|
112 | + |
|
113 | + $result = $query->execute(); |
|
114 | + $rows = $result->fetchAll(); |
|
115 | + $result->closeCursor(); |
|
116 | + |
|
117 | + return $rows; |
|
118 | + } |
|
119 | 119 | } |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class CompFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class PropFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -27,72 +27,72 @@ |
||
27 | 27 | use Sabre\DAV\File; |
28 | 28 | |
29 | 29 | class AvatarNode extends File { |
30 | - private $ext; |
|
31 | - private $size; |
|
32 | - private $avatar; |
|
30 | + private $ext; |
|
31 | + private $size; |
|
32 | + private $avatar; |
|
33 | 33 | |
34 | - /** |
|
35 | - * AvatarNode constructor. |
|
36 | - * |
|
37 | - * @param integer $size |
|
38 | - * @param string $ext |
|
39 | - * @param IAvatar $avatar |
|
40 | - */ |
|
41 | - public function __construct($size, $ext, $avatar) { |
|
42 | - $this->size = $size; |
|
43 | - $this->ext = $ext; |
|
44 | - $this->avatar = $avatar; |
|
45 | - } |
|
34 | + /** |
|
35 | + * AvatarNode constructor. |
|
36 | + * |
|
37 | + * @param integer $size |
|
38 | + * @param string $ext |
|
39 | + * @param IAvatar $avatar |
|
40 | + */ |
|
41 | + public function __construct($size, $ext, $avatar) { |
|
42 | + $this->size = $size; |
|
43 | + $this->ext = $ext; |
|
44 | + $this->avatar = $avatar; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the name of the node. |
|
49 | - * |
|
50 | - * This is used to generate the url. |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getName() { |
|
55 | - return "$this->size.$this->ext"; |
|
56 | - } |
|
47 | + /** |
|
48 | + * Returns the name of the node. |
|
49 | + * |
|
50 | + * This is used to generate the url. |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getName() { |
|
55 | + return "$this->size.$this->ext"; |
|
56 | + } |
|
57 | 57 | |
58 | - public function get() { |
|
59 | - $image = $this->avatar->get($this->size); |
|
60 | - $res = $image->resource(); |
|
58 | + public function get() { |
|
59 | + $image = $this->avatar->get($this->size); |
|
60 | + $res = $image->resource(); |
|
61 | 61 | |
62 | - ob_start(); |
|
63 | - if ($this->ext === 'png') { |
|
64 | - imagepng($res); |
|
65 | - } else { |
|
66 | - imagejpeg($res); |
|
67 | - } |
|
62 | + ob_start(); |
|
63 | + if ($this->ext === 'png') { |
|
64 | + imagepng($res); |
|
65 | + } else { |
|
66 | + imagejpeg($res); |
|
67 | + } |
|
68 | 68 | |
69 | - return ob_get_clean(); |
|
70 | - } |
|
69 | + return ob_get_clean(); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Returns the mime-type for a file |
|
74 | - * |
|
75 | - * If null is returned, we'll assume application/octet-stream |
|
76 | - * |
|
77 | - * @return string|null |
|
78 | - */ |
|
79 | - public function getContentType() { |
|
80 | - if ($this->ext === 'png') { |
|
81 | - return 'image/png'; |
|
82 | - } |
|
83 | - return 'image/jpeg'; |
|
84 | - } |
|
72 | + /** |
|
73 | + * Returns the mime-type for a file |
|
74 | + * |
|
75 | + * If null is returned, we'll assume application/octet-stream |
|
76 | + * |
|
77 | + * @return string|null |
|
78 | + */ |
|
79 | + public function getContentType() { |
|
80 | + if ($this->ext === 'png') { |
|
81 | + return 'image/png'; |
|
82 | + } |
|
83 | + return 'image/jpeg'; |
|
84 | + } |
|
85 | 85 | |
86 | - public function getETag() { |
|
87 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
88 | - } |
|
86 | + public function getETag() { |
|
87 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
88 | + } |
|
89 | 89 | |
90 | - public function getLastModified() { |
|
91 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
92 | - if (!empty($timestamp)) { |
|
93 | - return (int)$timestamp; |
|
94 | - } |
|
95 | - return $timestamp; |
|
90 | + public function getLastModified() { |
|
91 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
92 | + if (!empty($timestamp)) { |
|
93 | + return (int)$timestamp; |
|
94 | + } |
|
95 | + return $timestamp; |
|
96 | 96 | |
97 | - } |
|
97 | + } |
|
98 | 98 | } |
@@ -31,66 +31,66 @@ |
||
31 | 31 | */ |
32 | 32 | class CappedMemoryCache implements ICache, \ArrayAccess { |
33 | 33 | |
34 | - private $capacity; |
|
35 | - private $cache = []; |
|
36 | - |
|
37 | - public function __construct($capacity = 512) { |
|
38 | - $this->capacity = $capacity; |
|
39 | - } |
|
40 | - |
|
41 | - public function hasKey($key) { |
|
42 | - return isset($this->cache[$key]); |
|
43 | - } |
|
44 | - |
|
45 | - public function get($key) { |
|
46 | - return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
47 | - } |
|
48 | - |
|
49 | - public function set($key, $value, $ttl = 0) { |
|
50 | - if (is_null($key)) { |
|
51 | - $this->cache[] = $value; |
|
52 | - } else { |
|
53 | - $this->cache[$key] = $value; |
|
54 | - } |
|
55 | - $this->garbageCollect(); |
|
56 | - } |
|
57 | - |
|
58 | - public function remove($key) { |
|
59 | - unset($this->cache[$key]); |
|
60 | - return true; |
|
61 | - } |
|
62 | - |
|
63 | - public function clear($prefix = '') { |
|
64 | - $this->cache = []; |
|
65 | - return true; |
|
66 | - } |
|
67 | - |
|
68 | - public function offsetExists($offset) { |
|
69 | - return $this->hasKey($offset); |
|
70 | - } |
|
71 | - |
|
72 | - public function &offsetGet($offset) { |
|
73 | - return $this->cache[$offset]; |
|
74 | - } |
|
75 | - |
|
76 | - public function offsetSet($offset, $value) { |
|
77 | - $this->set($offset, $value); |
|
78 | - } |
|
79 | - |
|
80 | - public function offsetUnset($offset) { |
|
81 | - $this->remove($offset); |
|
82 | - } |
|
83 | - |
|
84 | - public function getData() { |
|
85 | - return $this->cache; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - private function garbageCollect() { |
|
90 | - while (count($this->cache) > $this->capacity) { |
|
91 | - reset($this->cache); |
|
92 | - $key = key($this->cache); |
|
93 | - $this->remove($key); |
|
94 | - } |
|
95 | - } |
|
34 | + private $capacity; |
|
35 | + private $cache = []; |
|
36 | + |
|
37 | + public function __construct($capacity = 512) { |
|
38 | + $this->capacity = $capacity; |
|
39 | + } |
|
40 | + |
|
41 | + public function hasKey($key) { |
|
42 | + return isset($this->cache[$key]); |
|
43 | + } |
|
44 | + |
|
45 | + public function get($key) { |
|
46 | + return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
47 | + } |
|
48 | + |
|
49 | + public function set($key, $value, $ttl = 0) { |
|
50 | + if (is_null($key)) { |
|
51 | + $this->cache[] = $value; |
|
52 | + } else { |
|
53 | + $this->cache[$key] = $value; |
|
54 | + } |
|
55 | + $this->garbageCollect(); |
|
56 | + } |
|
57 | + |
|
58 | + public function remove($key) { |
|
59 | + unset($this->cache[$key]); |
|
60 | + return true; |
|
61 | + } |
|
62 | + |
|
63 | + public function clear($prefix = '') { |
|
64 | + $this->cache = []; |
|
65 | + return true; |
|
66 | + } |
|
67 | + |
|
68 | + public function offsetExists($offset) { |
|
69 | + return $this->hasKey($offset); |
|
70 | + } |
|
71 | + |
|
72 | + public function &offsetGet($offset) { |
|
73 | + return $this->cache[$offset]; |
|
74 | + } |
|
75 | + |
|
76 | + public function offsetSet($offset, $value) { |
|
77 | + $this->set($offset, $value); |
|
78 | + } |
|
79 | + |
|
80 | + public function offsetUnset($offset) { |
|
81 | + $this->remove($offset); |
|
82 | + } |
|
83 | + |
|
84 | + public function getData() { |
|
85 | + return $this->cache; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + private function garbageCollect() { |
|
90 | + while (count($this->cache) > $this->capacity) { |
|
91 | + reset($this->cache); |
|
92 | + $key = key($this->cache); |
|
93 | + $this->remove($key); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | } |