@@ -21,10 +21,10 @@ |
||
21 | 21 | * |
22 | 22 | */ |
23 | 23 | script('settings', [ |
24 | - 'authtoken', |
|
25 | - 'authtoken_collection', |
|
26 | - 'authtoken_view', |
|
27 | - 'settings/authtoken-init' |
|
24 | + 'authtoken', |
|
25 | + 'authtoken_collection', |
|
26 | + 'authtoken_view', |
|
27 | + 'settings/authtoken-init' |
|
28 | 28 | ]); |
29 | 29 | |
30 | 30 | ?> |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | /** @var array $_ */ |
26 | 26 | |
27 | 27 | script('settings', [ |
28 | - 'usersettings', |
|
29 | - 'federationsettingsview', |
|
30 | - 'federationscopemenu', |
|
31 | - 'settings/personalInfo', |
|
28 | + 'usersettings', |
|
29 | + 'federationsettingsview', |
|
30 | + 'federationscopemenu', |
|
31 | + 'settings/personalInfo', |
|
32 | 32 | ]); |
33 | 33 | vendor_script('strengthify/jquery.strengthify'); |
34 | 34 | vendor_style('strengthify/strengthify'); |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | <p id="quotatext"> |
47 | 47 | <?php if ($_['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED): ?> |
48 | 48 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong>', |
49 | - [$_['usage'], $_['total_space']]));?> |
|
49 | + [$_['usage'], $_['total_space']]));?> |
|
50 | 50 | <?php else: ?> |
51 | 51 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong> (<strong>%s %%</strong>)', |
52 | - [$_['usage'], $_['total_space'], $_['usage_relative']]));?> |
|
52 | + [$_['usage'], $_['total_space'], $_['usage_relative']]));?> |
|
53 | 53 | <?php endif ?> |
54 | 54 | </p> |
55 | 55 | </div> |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | <div class="verify <?php if ($_['email'] === '' || $_['emailScope'] !== 'public') p('hidden'); ?>"> |
119 | 119 | <img id="verify-email" title="<?php p($_['emailMessage']); ?>" data-status="<?php p($_['emailVerification']) ?>" src=" |
120 | 120 | <?php |
121 | - switch($_['emailVerification']) { |
|
122 | - case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
|
123 | - p(image_path('core', 'actions/verifying.svg')); |
|
124 | - break; |
|
125 | - case \OC\Accounts\AccountManager::VERIFIED: |
|
126 | - p(image_path('core', 'actions/verified.svg')); |
|
127 | - break; |
|
128 | - default: |
|
129 | - p(image_path('core', 'actions/verify.svg')); |
|
130 | - } |
|
131 | - ?>"> |
|
121 | + switch($_['emailVerification']) { |
|
122 | + case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
|
123 | + p(image_path('core', 'actions/verifying.svg')); |
|
124 | + break; |
|
125 | + case \OC\Accounts\AccountManager::VERIFIED: |
|
126 | + p(image_path('core', 'actions/verified.svg')); |
|
127 | + break; |
|
128 | + default: |
|
129 | + p(image_path('core', 'actions/verify.svg')); |
|
130 | + } |
|
131 | + ?>"> |
|
132 | 132 | </div> |
133 | 133 | <input type="email" name="email" id="email" value="<?php p($_['email']); ?>" |
134 | 134 | <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
@@ -185,17 +185,17 @@ discard block |
||
185 | 185 | <div class="verify <?php if ($_['website'] === '' || $_['websiteScope'] !== 'public') p('hidden'); ?>"> |
186 | 186 | <img id="verify-website" title="<?php p($_['websiteMessage']); ?>" data-status="<?php p($_['websiteVerification']) ?>" src=" |
187 | 187 | <?php |
188 | - switch($_['websiteVerification']) { |
|
189 | - case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
|
190 | - p(image_path('core', 'actions/verifying.svg')); |
|
191 | - break; |
|
192 | - case \OC\Accounts\AccountManager::VERIFIED: |
|
193 | - p(image_path('core', 'actions/verified.svg')); |
|
194 | - break; |
|
195 | - default: |
|
196 | - p(image_path('core', 'actions/verify.svg')); |
|
197 | - } |
|
198 | - ?>" |
|
188 | + switch($_['websiteVerification']) { |
|
189 | + case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
|
190 | + p(image_path('core', 'actions/verifying.svg')); |
|
191 | + break; |
|
192 | + case \OC\Accounts\AccountManager::VERIFIED: |
|
193 | + p(image_path('core', 'actions/verified.svg')); |
|
194 | + break; |
|
195 | + default: |
|
196 | + p(image_path('core', 'actions/verify.svg')); |
|
197 | + } |
|
198 | + ?>" |
|
199 | 199 | <?php if($_['websiteVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['websiteVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) print_unescaped(' class="verify-action"') ?> |
200 | 200 | > |
201 | 201 | <div class="verification-dialog popovermenu bubble menu"> |
@@ -222,17 +222,17 @@ discard block |
||
222 | 222 | <div class="verify <?php if ($_['twitter'] === '' || $_['twitterScope'] !== 'public') p('hidden'); ?>"> |
223 | 223 | <img id="verify-twitter" title="<?php p($_['twitterMessage']); ?>" data-status="<?php p($_['twitterVerification']) ?>" src=" |
224 | 224 | <?php |
225 | - switch($_['twitterVerification']) { |
|
226 | - case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
|
227 | - p(image_path('core', 'actions/verifying.svg')); |
|
228 | - break; |
|
229 | - case \OC\Accounts\AccountManager::VERIFIED: |
|
230 | - p(image_path('core', 'actions/verified.svg')); |
|
231 | - break; |
|
232 | - default: |
|
233 | - p(image_path('core', 'actions/verify.svg')); |
|
234 | - } |
|
235 | - ?>" |
|
225 | + switch($_['twitterVerification']) { |
|
226 | + case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS: |
|
227 | + p(image_path('core', 'actions/verifying.svg')); |
|
228 | + break; |
|
229 | + case \OC\Accounts\AccountManager::VERIFIED: |
|
230 | + p(image_path('core', 'actions/verified.svg')); |
|
231 | + break; |
|
232 | + default: |
|
233 | + p(image_path('core', 'actions/verify.svg')); |
|
234 | + } |
|
235 | + ?>" |
|
236 | 236 | <?php if($_['twitterVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['twitterVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) print_unescaped(' class="verify-action"') ?> |
237 | 237 | > |
238 | 238 | <div class="verification-dialog popovermenu bubble menu"> |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | |
266 | 266 | <?php |
267 | 267 | if($_['passwordChangeSupported']) { |
268 | - script('jquery-showpassword'); |
|
269 | - ?> |
|
268 | + script('jquery-showpassword'); |
|
269 | + ?> |
|
270 | 270 | <form id="passwordform" class="section"> |
271 | 271 | <h2 class="inlineblock"><?php p($l->t('Password'));?></h2> |
272 | 272 | <div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div> |
@@ -22,10 +22,10 @@ |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | script('settings', [ |
25 | - 'authtoken', |
|
26 | - 'authtoken_collection', |
|
27 | - 'authtoken_view', |
|
28 | - 'settings/authtoken-init' |
|
25 | + 'authtoken', |
|
26 | + 'authtoken_collection', |
|
27 | + 'authtoken_view', |
|
28 | + 'settings/authtoken-init' |
|
29 | 29 | ]); |
30 | 30 | |
31 | 31 | ?> |
@@ -42,15 +42,15 @@ |
||
42 | 42 | |
43 | 43 | <p> |
44 | 44 | <?php print_unescaped(str_replace( |
45 | - [ |
|
46 | - '{contributeopen}', |
|
47 | - '{linkclose}', |
|
48 | - ], |
|
49 | - [ |
|
50 | - '<a href="https://nextcloud.com/contribute" target="_blank" rel="noreferrer">', |
|
51 | - '</a>', |
|
52 | - ], |
|
53 | - $l->t('If you want to support the project {contributeopen}join development{linkclose} or {contributeopen}spread the word{linkclose}!'))); ?> |
|
45 | + [ |
|
46 | + '{contributeopen}', |
|
47 | + '{linkclose}', |
|
48 | + ], |
|
49 | + [ |
|
50 | + '<a href="https://nextcloud.com/contribute" target="_blank" rel="noreferrer">', |
|
51 | + '</a>', |
|
52 | + ], |
|
53 | + $l->t('If you want to support the project {contributeopen}join development{linkclose} or {contributeopen}spread the word{linkclose}!'))); ?> |
|
54 | 54 | </p> |
55 | 55 | |
56 | 56 | <?php if(OC_APP::isEnabled('firstrunwizard')) {?> |
@@ -29,31 +29,31 @@ |
||
29 | 29 | |
30 | 30 | class Additional implements ISettings { |
31 | 31 | |
32 | - /** |
|
33 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
34 | - * @since 9.1 |
|
35 | - */ |
|
36 | - public function getForm() { |
|
37 | - return new TemplateResponse('settings', 'settings/empty'); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
34 | + * @since 9.1 |
|
35 | + */ |
|
36 | + public function getForm() { |
|
37 | + return new TemplateResponse('settings', 'settings/empty'); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string the section ID, e.g. 'sharing' |
|
42 | - * @since 9.1 |
|
43 | - */ |
|
44 | - public function getSection() { |
|
45 | - return 'additional'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return string the section ID, e.g. 'sharing' |
|
42 | + * @since 9.1 |
|
43 | + */ |
|
44 | + public function getSection() { |
|
45 | + return 'additional'; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return int whether the form should be rather on the top or bottom of |
|
50 | - * the admin section. The forms are arranged in ascending order of the |
|
51 | - * priority values. It is required to return a value between 0 and 100. |
|
52 | - * |
|
53 | - * E.g.: 70 |
|
54 | - * @since 9.1 |
|
55 | - */ |
|
56 | - public function getPriority() { |
|
57 | - return '5'; |
|
58 | - } |
|
48 | + /** |
|
49 | + * @return int whether the form should be rather on the top or bottom of |
|
50 | + * the admin section. The forms are arranged in ascending order of the |
|
51 | + * priority values. It is required to return a value between 0 and 100. |
|
52 | + * |
|
53 | + * E.g.: 70 |
|
54 | + * @since 9.1 |
|
55 | + */ |
|
56 | + public function getPriority() { |
|
57 | + return '5'; |
|
58 | + } |
|
59 | 59 | } |
@@ -31,78 +31,78 @@ |
||
31 | 31 | use OCP\Template; |
32 | 32 | |
33 | 33 | class PersonalSettingsController extends Controller { |
34 | - use CommonSettingsTrait { |
|
35 | - getSettings as private; |
|
36 | - } |
|
34 | + use CommonSettingsTrait { |
|
35 | + getSettings as private; |
|
36 | + } |
|
37 | 37 | |
38 | - /** @var INavigationManager */ |
|
39 | - private $navigationManager; |
|
38 | + /** @var INavigationManager */ |
|
39 | + private $navigationManager; |
|
40 | 40 | |
41 | - public function __construct( |
|
42 | - $appName, |
|
43 | - IRequest $request, |
|
44 | - INavigationManager $navigationManager, |
|
45 | - ISettingsManager $settingsManager |
|
46 | - ) { |
|
47 | - parent::__construct($appName, $request); |
|
48 | - $this->navigationManager = $navigationManager; |
|
49 | - $this->settingsManager = $settingsManager; |
|
50 | - } |
|
41 | + public function __construct( |
|
42 | + $appName, |
|
43 | + IRequest $request, |
|
44 | + INavigationManager $navigationManager, |
|
45 | + ISettingsManager $settingsManager |
|
46 | + ) { |
|
47 | + parent::__construct($appName, $request); |
|
48 | + $this->navigationManager = $navigationManager; |
|
49 | + $this->settingsManager = $settingsManager; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $section |
|
54 | - * @return TemplateResponse |
|
55 | - * |
|
56 | - * @NoCSRFRequired |
|
57 | - * @NoAdminRequired |
|
58 | - * @NoSubadminRequired |
|
59 | - */ |
|
60 | - public function index($section) { |
|
61 | - $this->navigationManager->setActiveEntry('personal'); |
|
62 | - return $this->getIndexResponse($section); |
|
63 | - } |
|
52 | + /** |
|
53 | + * @param string $section |
|
54 | + * @return TemplateResponse |
|
55 | + * |
|
56 | + * @NoCSRFRequired |
|
57 | + * @NoAdminRequired |
|
58 | + * @NoSubadminRequired |
|
59 | + */ |
|
60 | + public function index($section) { |
|
61 | + $this->navigationManager->setActiveEntry('personal'); |
|
62 | + return $this->getIndexResponse($section); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param string $section |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - private function getSettings($section) { |
|
70 | - // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
71 | - $settings = $this->settingsManager->getPersonalSettings($section); |
|
72 | - $formatted = $this->formatSettings($settings); |
|
73 | - if($section === 'additional') { |
|
74 | - $formatted['content'] .= $this->getLegacyForms(); |
|
75 | - } |
|
76 | - return $formatted; |
|
77 | - } |
|
65 | + /** |
|
66 | + * @param string $section |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + private function getSettings($section) { |
|
70 | + // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
71 | + $settings = $this->settingsManager->getPersonalSettings($section); |
|
72 | + $formatted = $this->formatSettings($settings); |
|
73 | + if($section === 'additional') { |
|
74 | + $formatted['content'] .= $this->getLegacyForms(); |
|
75 | + } |
|
76 | + return $formatted; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return bool|string |
|
81 | - */ |
|
82 | - private function getLegacyForms() { |
|
83 | - $forms = \OC_App::getForms('personal'); |
|
79 | + /** |
|
80 | + * @return bool|string |
|
81 | + */ |
|
82 | + private function getLegacyForms() { |
|
83 | + $forms = \OC_App::getForms('personal'); |
|
84 | 84 | |
85 | - $forms = array_map(function ($form) { |
|
86 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
87 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
88 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
89 | - $anchor = strtolower($sectionName); |
|
90 | - $anchor = str_replace(' ', '-', $anchor); |
|
85 | + $forms = array_map(function ($form) { |
|
86 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
87 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
88 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
89 | + $anchor = strtolower($sectionName); |
|
90 | + $anchor = str_replace(' ', '-', $anchor); |
|
91 | 91 | |
92 | - return array( |
|
93 | - 'anchor' => $anchor, |
|
94 | - 'section-name' => $sectionName, |
|
95 | - 'form' => $form |
|
96 | - ); |
|
97 | - } |
|
98 | - return array( |
|
99 | - 'form' => $form |
|
100 | - ); |
|
101 | - }, $forms); |
|
92 | + return array( |
|
93 | + 'anchor' => $anchor, |
|
94 | + 'section-name' => $sectionName, |
|
95 | + 'form' => $form |
|
96 | + ); |
|
97 | + } |
|
98 | + return array( |
|
99 | + 'form' => $form |
|
100 | + ); |
|
101 | + }, $forms); |
|
102 | 102 | |
103 | - $out = new Template('settings', 'settings/additional'); |
|
104 | - $out->assign('forms', $forms); |
|
103 | + $out = new Template('settings', 'settings/additional'); |
|
104 | + $out->assign('forms', $forms); |
|
105 | 105 | |
106 | - return $out->fetchPage(); |
|
107 | - } |
|
106 | + return $out->fetchPage(); |
|
107 | + } |
|
108 | 108 | } |
@@ -35,84 +35,84 @@ |
||
35 | 35 | * @package OC\Settings\Controller |
36 | 36 | */ |
37 | 37 | class AdminSettingsController extends Controller { |
38 | - use CommonSettingsTrait; |
|
38 | + use CommonSettingsTrait; |
|
39 | 39 | |
40 | - /** @var INavigationManager */ |
|
41 | - private $navigationManager; |
|
42 | - /** @var ISettingsManager */ |
|
43 | - private $settingsManager; |
|
40 | + /** @var INavigationManager */ |
|
41 | + private $navigationManager; |
|
42 | + /** @var ISettingsManager */ |
|
43 | + private $settingsManager; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $appName |
|
47 | - * @param IRequest $request |
|
48 | - * @param INavigationManager $navigationManager |
|
49 | - * @param ISettingsManager $settingsManager |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - $appName, |
|
53 | - IRequest $request, |
|
54 | - INavigationManager $navigationManager, |
|
55 | - ISettingsManager $settingsManager |
|
56 | - ) { |
|
57 | - parent::__construct($appName, $request); |
|
58 | - $this->navigationManager = $navigationManager; |
|
59 | - $this->settingsManager = $settingsManager; |
|
60 | - } |
|
45 | + /** |
|
46 | + * @param string $appName |
|
47 | + * @param IRequest $request |
|
48 | + * @param INavigationManager $navigationManager |
|
49 | + * @param ISettingsManager $settingsManager |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + $appName, |
|
53 | + IRequest $request, |
|
54 | + INavigationManager $navigationManager, |
|
55 | + ISettingsManager $settingsManager |
|
56 | + ) { |
|
57 | + parent::__construct($appName, $request); |
|
58 | + $this->navigationManager = $navigationManager; |
|
59 | + $this->settingsManager = $settingsManager; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $section |
|
64 | - * @return TemplateResponse |
|
65 | - * |
|
66 | - * @NoCSRFRequired |
|
67 | - */ |
|
68 | - public function index($section) { |
|
69 | - $this->navigationManager->setActiveEntry('admin'); |
|
70 | - return $this->getIndexResponse($section); |
|
71 | - } |
|
62 | + /** |
|
63 | + * @param string $section |
|
64 | + * @return TemplateResponse |
|
65 | + * |
|
66 | + * @NoCSRFRequired |
|
67 | + */ |
|
68 | + public function index($section) { |
|
69 | + $this->navigationManager->setActiveEntry('admin'); |
|
70 | + return $this->getIndexResponse($section); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $section |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - private function getSettings($section) { |
|
78 | - // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
79 | - $settings = $this->settingsManager->getAdminSettings($section); |
|
80 | - $formatted = $this->formatSettings($settings); |
|
81 | - if($section === 'additional') { |
|
82 | - $formatted['content'] .= $this->getLegacyForms(); |
|
83 | - } |
|
84 | - return $formatted; |
|
85 | - } |
|
73 | + /** |
|
74 | + * @param string $section |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + private function getSettings($section) { |
|
78 | + // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
79 | + $settings = $this->settingsManager->getAdminSettings($section); |
|
80 | + $formatted = $this->formatSettings($settings); |
|
81 | + if($section === 'additional') { |
|
82 | + $formatted['content'] .= $this->getLegacyForms(); |
|
83 | + } |
|
84 | + return $formatted; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return bool|string |
|
89 | - */ |
|
90 | - private function getLegacyForms() { |
|
91 | - $forms = \OC_App::getForms('admin'); |
|
87 | + /** |
|
88 | + * @return bool|string |
|
89 | + */ |
|
90 | + private function getLegacyForms() { |
|
91 | + $forms = \OC_App::getForms('admin'); |
|
92 | 92 | |
93 | - $forms = array_map(function ($form) { |
|
94 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
95 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
96 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
97 | - $anchor = strtolower($sectionName); |
|
98 | - $anchor = str_replace(' ', '-', $anchor); |
|
93 | + $forms = array_map(function ($form) { |
|
94 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
95 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
96 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
97 | + $anchor = strtolower($sectionName); |
|
98 | + $anchor = str_replace(' ', '-', $anchor); |
|
99 | 99 | |
100 | - return array( |
|
101 | - 'anchor' => $anchor, |
|
102 | - 'section-name' => $sectionName, |
|
103 | - 'form' => $form |
|
104 | - ); |
|
105 | - } |
|
106 | - return array( |
|
107 | - 'form' => $form |
|
108 | - ); |
|
109 | - }, $forms); |
|
100 | + return array( |
|
101 | + 'anchor' => $anchor, |
|
102 | + 'section-name' => $sectionName, |
|
103 | + 'form' => $form |
|
104 | + ); |
|
105 | + } |
|
106 | + return array( |
|
107 | + 'form' => $form |
|
108 | + ); |
|
109 | + }, $forms); |
|
110 | 110 | |
111 | - $out = new Template('settings', 'settings/additional'); |
|
112 | - $out->assign('forms', $forms); |
|
111 | + $out = new Template('settings', 'settings/additional'); |
|
112 | + $out->assign('forms', $forms); |
|
113 | 113 | |
114 | - return $out->fetchPage(); |
|
115 | - } |
|
114 | + return $out->fetchPage(); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | } |
@@ -41,467 +41,467 @@ |
||
41 | 41 | use OCP\Settings\ISection; |
42 | 42 | |
43 | 43 | class Manager implements IManager { |
44 | - /** @var ILogger */ |
|
45 | - private $log; |
|
46 | - /** @var IDBConnection */ |
|
47 | - private $dbc; |
|
48 | - /** @var Mapper */ |
|
49 | - private $mapper; |
|
50 | - /** @var IL10N */ |
|
51 | - private $l; |
|
52 | - /** @var IConfig */ |
|
53 | - private $config; |
|
54 | - /** @var EncryptionManager */ |
|
55 | - private $encryptionManager; |
|
56 | - /** @var IUserManager */ |
|
57 | - private $userManager; |
|
58 | - /** @var ILockingProvider */ |
|
59 | - private $lockingProvider; |
|
60 | - /** @var IRequest */ |
|
61 | - private $request; |
|
62 | - /** @var IURLGenerator */ |
|
63 | - private $url; |
|
64 | - /** @var AccountManager */ |
|
65 | - private $accountManager; |
|
66 | - /** @var IGroupManager */ |
|
67 | - private $groupManager; |
|
68 | - /** @var IFactory */ |
|
69 | - private $l10nFactory; |
|
70 | - /** @var \OC_Defaults */ |
|
71 | - private $defaults; |
|
72 | - |
|
73 | - /** |
|
74 | - * @param ILogger $log |
|
75 | - * @param IDBConnection $dbc |
|
76 | - * @param IL10N $l |
|
77 | - * @param IConfig $config |
|
78 | - * @param EncryptionManager $encryptionManager |
|
79 | - * @param IUserManager $userManager |
|
80 | - * @param ILockingProvider $lockingProvider |
|
81 | - * @param IRequest $request |
|
82 | - * @param Mapper $mapper |
|
83 | - * @param IURLGenerator $url |
|
84 | - * @param AccountManager $accountManager |
|
85 | - * @param IGroupManager $groupManager |
|
86 | - * @param IFactory $l10nFactory |
|
87 | - * @param \OC_Defaults $defaults |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - ILogger $log, |
|
91 | - IDBConnection $dbc, |
|
92 | - IL10N $l, |
|
93 | - IConfig $config, |
|
94 | - EncryptionManager $encryptionManager, |
|
95 | - IUserManager $userManager, |
|
96 | - ILockingProvider $lockingProvider, |
|
97 | - IRequest $request, |
|
98 | - Mapper $mapper, |
|
99 | - IURLGenerator $url, |
|
100 | - AccountManager $accountManager, |
|
101 | - IGroupManager $groupManager, |
|
102 | - IFactory $l10nFactory, |
|
103 | - \OC_Defaults $defaults |
|
104 | - ) { |
|
105 | - $this->log = $log; |
|
106 | - $this->dbc = $dbc; |
|
107 | - $this->mapper = $mapper; |
|
108 | - $this->l = $l; |
|
109 | - $this->config = $config; |
|
110 | - $this->encryptionManager = $encryptionManager; |
|
111 | - $this->userManager = $userManager; |
|
112 | - $this->lockingProvider = $lockingProvider; |
|
113 | - $this->request = $request; |
|
114 | - $this->url = $url; |
|
115 | - $this->accountManager = $accountManager; |
|
116 | - $this->groupManager = $groupManager; |
|
117 | - $this->l10nFactory = $l10nFactory; |
|
118 | - $this->defaults = $defaults; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @inheritdoc |
|
123 | - */ |
|
124 | - public function setupSettings(array $settings) { |
|
125 | - if (isset($settings[IManager::KEY_ADMIN_SECTION])) { |
|
126 | - $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin'); |
|
127 | - } |
|
128 | - if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
129 | - $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin'); |
|
130 | - } |
|
131 | - |
|
132 | - if (isset($settings[IManager::KEY_PERSONAL_SECTION])) { |
|
133 | - $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal'); |
|
134 | - } |
|
135 | - if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) { |
|
136 | - $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal'); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * attempts to remove an apps section and/or settings entry. A listener is |
|
142 | - * added centrally making sure that this method is called ones an app was |
|
143 | - * disabled. |
|
144 | - * |
|
145 | - * @param string $appId |
|
146 | - * @since 9.1.0 |
|
147 | - */ |
|
148 | - public function onAppDisabled($appId) { |
|
149 | - $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
150 | - |
|
151 | - if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
152 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\')); |
|
153 | - } |
|
154 | - if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
155 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\')); |
|
156 | - } |
|
157 | - |
|
158 | - if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) { |
|
159 | - $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\')); |
|
160 | - } |
|
161 | - if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) { |
|
162 | - $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\')); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - public function checkForOrphanedClassNames() { |
|
167 | - $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS]; |
|
168 | - foreach ($tables as $table) { |
|
169 | - $classes = $this->mapper->getClasses($table); |
|
170 | - foreach ($classes as $className) { |
|
171 | - try { |
|
172 | - \OC::$server->query($className); |
|
173 | - } catch (QueryException $e) { |
|
174 | - $this->mapper->remove($table, $className); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $sectionClassName |
|
182 | - * @param string $type either 'admin' or 'personal' |
|
183 | - */ |
|
184 | - private function setupSectionEntry($sectionClassName, $type) { |
|
185 | - if (!class_exists($sectionClassName)) { |
|
186 | - $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
187 | - return; |
|
188 | - } |
|
189 | - try { |
|
190 | - $section = $this->query($sectionClassName); |
|
191 | - } catch (QueryException $e) { |
|
192 | - // cancel |
|
193 | - return; |
|
194 | - } |
|
195 | - |
|
196 | - if (!$section instanceof ISection) { |
|
197 | - $this->log->error( |
|
198 | - ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
199 | - ['class' => $sectionClassName] |
|
200 | - ); |
|
201 | - return; |
|
202 | - } |
|
203 | - $table = $this->getSectionTableForType($type); |
|
204 | - if(!$this->hasSection(get_class($section), $table)) { |
|
205 | - $this->addSection($section, $table); |
|
206 | - } else { |
|
207 | - $this->updateSection($section, $table); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - private function addSection(ISection $section, $table) { |
|
212 | - $this->mapper->add($table, [ |
|
213 | - 'id' => $section->getID(), |
|
214 | - 'class' => get_class($section), |
|
215 | - 'priority' => $section->getPriority(), |
|
216 | - ]); |
|
217 | - } |
|
218 | - |
|
219 | - private function addSettings(ISettings $settings, $table) { |
|
220 | - $this->mapper->add($table, [ |
|
221 | - 'class' => get_class($settings), |
|
222 | - 'section' => $settings->getSection(), |
|
223 | - 'priority' => $settings->getPriority(), |
|
224 | - ]); |
|
225 | - } |
|
226 | - |
|
227 | - private function updateSettings(ISettings $settings, $table) { |
|
228 | - $this->mapper->update( |
|
229 | - $table, |
|
230 | - 'class', |
|
231 | - get_class($settings), |
|
232 | - [ |
|
233 | - 'section' => $settings->getSection(), |
|
234 | - 'priority' => $settings->getPriority(), |
|
235 | - ] |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - private function updateSection(ISection $section, $table) { |
|
240 | - $this->mapper->update( |
|
241 | - $table, |
|
242 | - 'class', |
|
243 | - get_class($section), |
|
244 | - [ |
|
245 | - 'id' => $section->getID(), |
|
246 | - 'priority' => $section->getPriority(), |
|
247 | - ] |
|
248 | - ); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @param string $className |
|
253 | - * @param string $table |
|
254 | - * @return bool |
|
255 | - */ |
|
256 | - private function hasSection($className, $table) { |
|
257 | - return $this->mapper->has($table, $className); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @param string $className |
|
262 | - * @return bool |
|
263 | - */ |
|
264 | - private function hasSettings($className, $table) { |
|
265 | - return $this->mapper->has($table, $className); |
|
266 | - } |
|
267 | - |
|
268 | - private function setupSettingsEntry($settingsClassName, $type) { |
|
269 | - if (!class_exists($settingsClassName)) { |
|
270 | - $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
271 | - return; |
|
272 | - } |
|
273 | - |
|
274 | - try { |
|
275 | - /** @var ISettings $settings */ |
|
276 | - $settings = $this->query($settingsClassName); |
|
277 | - } catch (QueryException $e) { |
|
278 | - // cancel |
|
279 | - return; |
|
280 | - } |
|
281 | - |
|
282 | - if (!$settings instanceof ISettings) { |
|
283 | - $this->log->error( |
|
284 | - ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
285 | - ['class' => $settingsClassName] |
|
286 | - ); |
|
287 | - return; |
|
288 | - } |
|
289 | - $table = $this->getSettingsTableForType($type); |
|
290 | - if (!$this->hasSettings(get_class($settings), $table)) { |
|
291 | - $this->addSettings($settings, $table); |
|
292 | - } else { |
|
293 | - $this->updateSettings($settings, $table); |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - private function getSectionTableForType($type) { |
|
298 | - if($type === 'admin') { |
|
299 | - return Mapper::TABLE_ADMIN_SECTIONS; |
|
300 | - } else if($type === 'personal') { |
|
301 | - return Mapper::TABLE_PERSONAL_SECTIONS; |
|
302 | - } |
|
303 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
304 | - } |
|
305 | - |
|
306 | - private function getSettingsTableForType($type) { |
|
307 | - if($type === 'admin') { |
|
308 | - return Mapper::TABLE_ADMIN_SETTINGS; |
|
309 | - } else if($type === 'personal') { |
|
310 | - return Mapper::TABLE_PERSONAL_SETTINGS; |
|
311 | - } |
|
312 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
313 | - } |
|
314 | - |
|
315 | - private function query($className) { |
|
316 | - try { |
|
317 | - return \OC::$server->query($className); |
|
318 | - } catch (QueryException $e) { |
|
319 | - $this->log->logException($e); |
|
320 | - throw $e; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @inheritdoc |
|
326 | - */ |
|
327 | - public function getAdminSections() { |
|
328 | - // built-in sections |
|
329 | - $sections = [ |
|
330 | - 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
331 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
332 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
333 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
334 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
335 | - 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
336 | - ]; |
|
337 | - |
|
338 | - $rows = $this->mapper->getAdminSectionsFromDB(); |
|
339 | - |
|
340 | - foreach ($rows as $row) { |
|
341 | - if (!isset($sections[$row['priority']])) { |
|
342 | - $sections[$row['priority']] = []; |
|
343 | - } |
|
344 | - try { |
|
345 | - $sections[$row['priority']][] = $this->query($row['class']); |
|
346 | - } catch (QueryException $e) { |
|
347 | - // skip |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - ksort($sections); |
|
352 | - |
|
353 | - return $sections; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * @param string $section |
|
358 | - * @return ISection[] |
|
359 | - */ |
|
360 | - private function getBuiltInAdminSettings($section) { |
|
361 | - $forms = []; |
|
362 | - try { |
|
363 | - if ($section === 'server') { |
|
364 | - /** @var ISettings $form */ |
|
365 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
366 | - $forms[$form->getPriority()] = [$form]; |
|
367 | - $form = new Admin\ServerDevNotice(); |
|
368 | - $forms[$form->getPriority()] = [$form]; |
|
369 | - } |
|
370 | - if ($section === 'encryption') { |
|
371 | - /** @var ISettings $form */ |
|
372 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
373 | - $forms[$form->getPriority()] = [$form]; |
|
374 | - } |
|
375 | - if ($section === 'sharing') { |
|
376 | - /** @var ISettings $form */ |
|
377 | - $form = new Admin\Sharing($this->config); |
|
378 | - $forms[$form->getPriority()] = [$form]; |
|
379 | - } |
|
380 | - if ($section === 'additional') { |
|
381 | - /** @var ISettings $form */ |
|
382 | - $form = new Admin\Additional($this->config); |
|
383 | - $forms[$form->getPriority()] = [$form]; |
|
384 | - } |
|
385 | - if ($section === 'tips-tricks') { |
|
386 | - /** @var ISettings $form */ |
|
387 | - $form = new Admin\TipsTricks($this->config); |
|
388 | - $forms[$form->getPriority()] = [$form]; |
|
389 | - } |
|
390 | - } catch (QueryException $e) { |
|
391 | - // skip |
|
392 | - } |
|
393 | - return $forms; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @param string $section |
|
398 | - * @return ISection[] |
|
399 | - */ |
|
400 | - private function getBuiltInPersonalSettings($section) { |
|
401 | - $forms = []; |
|
402 | - try { |
|
403 | - if ($section === 'personal-info') { |
|
404 | - /** @var ISettings $form */ |
|
405 | - $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->l); |
|
406 | - $forms[$form->getPriority()] = [$form]; |
|
407 | - } |
|
408 | - if($section === 'sessions') { |
|
409 | - /** @var ISettings $form */ |
|
410 | - $form = new Personal\Sessions(); |
|
411 | - $forms[$form->getPriority()] = [$form]; |
|
412 | - } |
|
413 | - if($section === 'app-passwords') { |
|
414 | - /** @var ISettings $form */ |
|
415 | - $form = new Personal\AppPasswords(); |
|
416 | - $forms[$form->getPriority()] = [$form]; |
|
417 | - } |
|
418 | - if($section === 'sync-clients') { |
|
419 | - /** @var ISettings $form */ |
|
420 | - $form = new Personal\SyncClients($this->config, $this->defaults); |
|
421 | - $forms[$form->getPriority()] = [$form]; |
|
422 | - } |
|
423 | - if ($section === 'additional') { |
|
424 | - /** @var ISettings $form */ |
|
425 | - $form = new Personal\Additional($this->config); |
|
426 | - $forms[$form->getPriority()] = [$form]; |
|
427 | - } |
|
428 | - } catch (QueryException $e) { |
|
429 | - // skip |
|
430 | - } |
|
431 | - return $forms; |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * @inheritdoc |
|
436 | - */ |
|
437 | - public function getAdminSettings($section) { |
|
438 | - $settings = $this->getBuiltInAdminSettings($section); |
|
439 | - $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
440 | - |
|
441 | - foreach ($dbRows as $row) { |
|
442 | - if (!isset($settings[$row['priority']])) { |
|
443 | - $settings[$row['priority']] = []; |
|
444 | - } |
|
445 | - try { |
|
446 | - $settings[$row['priority']][] = $this->query($row['class']); |
|
447 | - } catch (QueryException $e) { |
|
448 | - // skip |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - ksort($settings); |
|
453 | - return $settings; |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * @inheritdoc |
|
458 | - */ |
|
459 | - public function getPersonalSections() { |
|
460 | - $sections = [ |
|
461 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
462 | - 5 => [new Section('sessions', $this->l->t('Sessions'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
463 | - 10 => [new Section('app-passwords', $this->l->t('App passwords'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
464 | - 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
465 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
466 | - ]; |
|
467 | - |
|
468 | - $rows = $this->mapper->getPersonalSectionsFromDB(); |
|
469 | - |
|
470 | - foreach ($rows as $row) { |
|
471 | - if (!isset($sections[$row['priority']])) { |
|
472 | - $sections[$row['priority']] = []; |
|
473 | - } |
|
474 | - try { |
|
475 | - $sections[$row['priority']][] = $this->query($row['class']); |
|
476 | - } catch (QueryException $e) { |
|
477 | - // skip |
|
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - ksort($sections); |
|
482 | - |
|
483 | - return $sections; |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * @inheritdoc |
|
488 | - */ |
|
489 | - public function getPersonalSettings($section) { |
|
490 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
491 | - $dbRows = $this->mapper->getPersonalSettingsFromDB($section); |
|
492 | - |
|
493 | - foreach ($dbRows as $row) { |
|
494 | - if (!isset($settings[$row['priority']])) { |
|
495 | - $settings[$row['priority']] = []; |
|
496 | - } |
|
497 | - try { |
|
498 | - $settings[$row['priority']][] = $this->query($row['class']); |
|
499 | - } catch (QueryException $e) { |
|
500 | - // skip |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - ksort($settings); |
|
505 | - return $settings; |
|
506 | - } |
|
44 | + /** @var ILogger */ |
|
45 | + private $log; |
|
46 | + /** @var IDBConnection */ |
|
47 | + private $dbc; |
|
48 | + /** @var Mapper */ |
|
49 | + private $mapper; |
|
50 | + /** @var IL10N */ |
|
51 | + private $l; |
|
52 | + /** @var IConfig */ |
|
53 | + private $config; |
|
54 | + /** @var EncryptionManager */ |
|
55 | + private $encryptionManager; |
|
56 | + /** @var IUserManager */ |
|
57 | + private $userManager; |
|
58 | + /** @var ILockingProvider */ |
|
59 | + private $lockingProvider; |
|
60 | + /** @var IRequest */ |
|
61 | + private $request; |
|
62 | + /** @var IURLGenerator */ |
|
63 | + private $url; |
|
64 | + /** @var AccountManager */ |
|
65 | + private $accountManager; |
|
66 | + /** @var IGroupManager */ |
|
67 | + private $groupManager; |
|
68 | + /** @var IFactory */ |
|
69 | + private $l10nFactory; |
|
70 | + /** @var \OC_Defaults */ |
|
71 | + private $defaults; |
|
72 | + |
|
73 | + /** |
|
74 | + * @param ILogger $log |
|
75 | + * @param IDBConnection $dbc |
|
76 | + * @param IL10N $l |
|
77 | + * @param IConfig $config |
|
78 | + * @param EncryptionManager $encryptionManager |
|
79 | + * @param IUserManager $userManager |
|
80 | + * @param ILockingProvider $lockingProvider |
|
81 | + * @param IRequest $request |
|
82 | + * @param Mapper $mapper |
|
83 | + * @param IURLGenerator $url |
|
84 | + * @param AccountManager $accountManager |
|
85 | + * @param IGroupManager $groupManager |
|
86 | + * @param IFactory $l10nFactory |
|
87 | + * @param \OC_Defaults $defaults |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + ILogger $log, |
|
91 | + IDBConnection $dbc, |
|
92 | + IL10N $l, |
|
93 | + IConfig $config, |
|
94 | + EncryptionManager $encryptionManager, |
|
95 | + IUserManager $userManager, |
|
96 | + ILockingProvider $lockingProvider, |
|
97 | + IRequest $request, |
|
98 | + Mapper $mapper, |
|
99 | + IURLGenerator $url, |
|
100 | + AccountManager $accountManager, |
|
101 | + IGroupManager $groupManager, |
|
102 | + IFactory $l10nFactory, |
|
103 | + \OC_Defaults $defaults |
|
104 | + ) { |
|
105 | + $this->log = $log; |
|
106 | + $this->dbc = $dbc; |
|
107 | + $this->mapper = $mapper; |
|
108 | + $this->l = $l; |
|
109 | + $this->config = $config; |
|
110 | + $this->encryptionManager = $encryptionManager; |
|
111 | + $this->userManager = $userManager; |
|
112 | + $this->lockingProvider = $lockingProvider; |
|
113 | + $this->request = $request; |
|
114 | + $this->url = $url; |
|
115 | + $this->accountManager = $accountManager; |
|
116 | + $this->groupManager = $groupManager; |
|
117 | + $this->l10nFactory = $l10nFactory; |
|
118 | + $this->defaults = $defaults; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @inheritdoc |
|
123 | + */ |
|
124 | + public function setupSettings(array $settings) { |
|
125 | + if (isset($settings[IManager::KEY_ADMIN_SECTION])) { |
|
126 | + $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin'); |
|
127 | + } |
|
128 | + if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
129 | + $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin'); |
|
130 | + } |
|
131 | + |
|
132 | + if (isset($settings[IManager::KEY_PERSONAL_SECTION])) { |
|
133 | + $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal'); |
|
134 | + } |
|
135 | + if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) { |
|
136 | + $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal'); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * attempts to remove an apps section and/or settings entry. A listener is |
|
142 | + * added centrally making sure that this method is called ones an app was |
|
143 | + * disabled. |
|
144 | + * |
|
145 | + * @param string $appId |
|
146 | + * @since 9.1.0 |
|
147 | + */ |
|
148 | + public function onAppDisabled($appId) { |
|
149 | + $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
150 | + |
|
151 | + if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
152 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\')); |
|
153 | + } |
|
154 | + if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
155 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\')); |
|
156 | + } |
|
157 | + |
|
158 | + if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) { |
|
159 | + $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\')); |
|
160 | + } |
|
161 | + if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) { |
|
162 | + $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\')); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + public function checkForOrphanedClassNames() { |
|
167 | + $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS]; |
|
168 | + foreach ($tables as $table) { |
|
169 | + $classes = $this->mapper->getClasses($table); |
|
170 | + foreach ($classes as $className) { |
|
171 | + try { |
|
172 | + \OC::$server->query($className); |
|
173 | + } catch (QueryException $e) { |
|
174 | + $this->mapper->remove($table, $className); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $sectionClassName |
|
182 | + * @param string $type either 'admin' or 'personal' |
|
183 | + */ |
|
184 | + private function setupSectionEntry($sectionClassName, $type) { |
|
185 | + if (!class_exists($sectionClassName)) { |
|
186 | + $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
187 | + return; |
|
188 | + } |
|
189 | + try { |
|
190 | + $section = $this->query($sectionClassName); |
|
191 | + } catch (QueryException $e) { |
|
192 | + // cancel |
|
193 | + return; |
|
194 | + } |
|
195 | + |
|
196 | + if (!$section instanceof ISection) { |
|
197 | + $this->log->error( |
|
198 | + ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
199 | + ['class' => $sectionClassName] |
|
200 | + ); |
|
201 | + return; |
|
202 | + } |
|
203 | + $table = $this->getSectionTableForType($type); |
|
204 | + if(!$this->hasSection(get_class($section), $table)) { |
|
205 | + $this->addSection($section, $table); |
|
206 | + } else { |
|
207 | + $this->updateSection($section, $table); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + private function addSection(ISection $section, $table) { |
|
212 | + $this->mapper->add($table, [ |
|
213 | + 'id' => $section->getID(), |
|
214 | + 'class' => get_class($section), |
|
215 | + 'priority' => $section->getPriority(), |
|
216 | + ]); |
|
217 | + } |
|
218 | + |
|
219 | + private function addSettings(ISettings $settings, $table) { |
|
220 | + $this->mapper->add($table, [ |
|
221 | + 'class' => get_class($settings), |
|
222 | + 'section' => $settings->getSection(), |
|
223 | + 'priority' => $settings->getPriority(), |
|
224 | + ]); |
|
225 | + } |
|
226 | + |
|
227 | + private function updateSettings(ISettings $settings, $table) { |
|
228 | + $this->mapper->update( |
|
229 | + $table, |
|
230 | + 'class', |
|
231 | + get_class($settings), |
|
232 | + [ |
|
233 | + 'section' => $settings->getSection(), |
|
234 | + 'priority' => $settings->getPriority(), |
|
235 | + ] |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + private function updateSection(ISection $section, $table) { |
|
240 | + $this->mapper->update( |
|
241 | + $table, |
|
242 | + 'class', |
|
243 | + get_class($section), |
|
244 | + [ |
|
245 | + 'id' => $section->getID(), |
|
246 | + 'priority' => $section->getPriority(), |
|
247 | + ] |
|
248 | + ); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @param string $className |
|
253 | + * @param string $table |
|
254 | + * @return bool |
|
255 | + */ |
|
256 | + private function hasSection($className, $table) { |
|
257 | + return $this->mapper->has($table, $className); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @param string $className |
|
262 | + * @return bool |
|
263 | + */ |
|
264 | + private function hasSettings($className, $table) { |
|
265 | + return $this->mapper->has($table, $className); |
|
266 | + } |
|
267 | + |
|
268 | + private function setupSettingsEntry($settingsClassName, $type) { |
|
269 | + if (!class_exists($settingsClassName)) { |
|
270 | + $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
271 | + return; |
|
272 | + } |
|
273 | + |
|
274 | + try { |
|
275 | + /** @var ISettings $settings */ |
|
276 | + $settings = $this->query($settingsClassName); |
|
277 | + } catch (QueryException $e) { |
|
278 | + // cancel |
|
279 | + return; |
|
280 | + } |
|
281 | + |
|
282 | + if (!$settings instanceof ISettings) { |
|
283 | + $this->log->error( |
|
284 | + ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
285 | + ['class' => $settingsClassName] |
|
286 | + ); |
|
287 | + return; |
|
288 | + } |
|
289 | + $table = $this->getSettingsTableForType($type); |
|
290 | + if (!$this->hasSettings(get_class($settings), $table)) { |
|
291 | + $this->addSettings($settings, $table); |
|
292 | + } else { |
|
293 | + $this->updateSettings($settings, $table); |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + private function getSectionTableForType($type) { |
|
298 | + if($type === 'admin') { |
|
299 | + return Mapper::TABLE_ADMIN_SECTIONS; |
|
300 | + } else if($type === 'personal') { |
|
301 | + return Mapper::TABLE_PERSONAL_SECTIONS; |
|
302 | + } |
|
303 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
304 | + } |
|
305 | + |
|
306 | + private function getSettingsTableForType($type) { |
|
307 | + if($type === 'admin') { |
|
308 | + return Mapper::TABLE_ADMIN_SETTINGS; |
|
309 | + } else if($type === 'personal') { |
|
310 | + return Mapper::TABLE_PERSONAL_SETTINGS; |
|
311 | + } |
|
312 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
313 | + } |
|
314 | + |
|
315 | + private function query($className) { |
|
316 | + try { |
|
317 | + return \OC::$server->query($className); |
|
318 | + } catch (QueryException $e) { |
|
319 | + $this->log->logException($e); |
|
320 | + throw $e; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @inheritdoc |
|
326 | + */ |
|
327 | + public function getAdminSections() { |
|
328 | + // built-in sections |
|
329 | + $sections = [ |
|
330 | + 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
331 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
332 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
333 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
334 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
335 | + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
336 | + ]; |
|
337 | + |
|
338 | + $rows = $this->mapper->getAdminSectionsFromDB(); |
|
339 | + |
|
340 | + foreach ($rows as $row) { |
|
341 | + if (!isset($sections[$row['priority']])) { |
|
342 | + $sections[$row['priority']] = []; |
|
343 | + } |
|
344 | + try { |
|
345 | + $sections[$row['priority']][] = $this->query($row['class']); |
|
346 | + } catch (QueryException $e) { |
|
347 | + // skip |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + ksort($sections); |
|
352 | + |
|
353 | + return $sections; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * @param string $section |
|
358 | + * @return ISection[] |
|
359 | + */ |
|
360 | + private function getBuiltInAdminSettings($section) { |
|
361 | + $forms = []; |
|
362 | + try { |
|
363 | + if ($section === 'server') { |
|
364 | + /** @var ISettings $form */ |
|
365 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
366 | + $forms[$form->getPriority()] = [$form]; |
|
367 | + $form = new Admin\ServerDevNotice(); |
|
368 | + $forms[$form->getPriority()] = [$form]; |
|
369 | + } |
|
370 | + if ($section === 'encryption') { |
|
371 | + /** @var ISettings $form */ |
|
372 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
373 | + $forms[$form->getPriority()] = [$form]; |
|
374 | + } |
|
375 | + if ($section === 'sharing') { |
|
376 | + /** @var ISettings $form */ |
|
377 | + $form = new Admin\Sharing($this->config); |
|
378 | + $forms[$form->getPriority()] = [$form]; |
|
379 | + } |
|
380 | + if ($section === 'additional') { |
|
381 | + /** @var ISettings $form */ |
|
382 | + $form = new Admin\Additional($this->config); |
|
383 | + $forms[$form->getPriority()] = [$form]; |
|
384 | + } |
|
385 | + if ($section === 'tips-tricks') { |
|
386 | + /** @var ISettings $form */ |
|
387 | + $form = new Admin\TipsTricks($this->config); |
|
388 | + $forms[$form->getPriority()] = [$form]; |
|
389 | + } |
|
390 | + } catch (QueryException $e) { |
|
391 | + // skip |
|
392 | + } |
|
393 | + return $forms; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @param string $section |
|
398 | + * @return ISection[] |
|
399 | + */ |
|
400 | + private function getBuiltInPersonalSettings($section) { |
|
401 | + $forms = []; |
|
402 | + try { |
|
403 | + if ($section === 'personal-info') { |
|
404 | + /** @var ISettings $form */ |
|
405 | + $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->l); |
|
406 | + $forms[$form->getPriority()] = [$form]; |
|
407 | + } |
|
408 | + if($section === 'sessions') { |
|
409 | + /** @var ISettings $form */ |
|
410 | + $form = new Personal\Sessions(); |
|
411 | + $forms[$form->getPriority()] = [$form]; |
|
412 | + } |
|
413 | + if($section === 'app-passwords') { |
|
414 | + /** @var ISettings $form */ |
|
415 | + $form = new Personal\AppPasswords(); |
|
416 | + $forms[$form->getPriority()] = [$form]; |
|
417 | + } |
|
418 | + if($section === 'sync-clients') { |
|
419 | + /** @var ISettings $form */ |
|
420 | + $form = new Personal\SyncClients($this->config, $this->defaults); |
|
421 | + $forms[$form->getPriority()] = [$form]; |
|
422 | + } |
|
423 | + if ($section === 'additional') { |
|
424 | + /** @var ISettings $form */ |
|
425 | + $form = new Personal\Additional($this->config); |
|
426 | + $forms[$form->getPriority()] = [$form]; |
|
427 | + } |
|
428 | + } catch (QueryException $e) { |
|
429 | + // skip |
|
430 | + } |
|
431 | + return $forms; |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * @inheritdoc |
|
436 | + */ |
|
437 | + public function getAdminSettings($section) { |
|
438 | + $settings = $this->getBuiltInAdminSettings($section); |
|
439 | + $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
440 | + |
|
441 | + foreach ($dbRows as $row) { |
|
442 | + if (!isset($settings[$row['priority']])) { |
|
443 | + $settings[$row['priority']] = []; |
|
444 | + } |
|
445 | + try { |
|
446 | + $settings[$row['priority']][] = $this->query($row['class']); |
|
447 | + } catch (QueryException $e) { |
|
448 | + // skip |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + ksort($settings); |
|
453 | + return $settings; |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * @inheritdoc |
|
458 | + */ |
|
459 | + public function getPersonalSections() { |
|
460 | + $sections = [ |
|
461 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
462 | + 5 => [new Section('sessions', $this->l->t('Sessions'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
463 | + 10 => [new Section('app-passwords', $this->l->t('App passwords'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
464 | + 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
465 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
466 | + ]; |
|
467 | + |
|
468 | + $rows = $this->mapper->getPersonalSectionsFromDB(); |
|
469 | + |
|
470 | + foreach ($rows as $row) { |
|
471 | + if (!isset($sections[$row['priority']])) { |
|
472 | + $sections[$row['priority']] = []; |
|
473 | + } |
|
474 | + try { |
|
475 | + $sections[$row['priority']][] = $this->query($row['class']); |
|
476 | + } catch (QueryException $e) { |
|
477 | + // skip |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + ksort($sections); |
|
482 | + |
|
483 | + return $sections; |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * @inheritdoc |
|
488 | + */ |
|
489 | + public function getPersonalSettings($section) { |
|
490 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
491 | + $dbRows = $this->mapper->getPersonalSettingsFromDB($section); |
|
492 | + |
|
493 | + foreach ($dbRows as $row) { |
|
494 | + if (!isset($settings[$row['priority']])) { |
|
495 | + $settings[$row['priority']] = []; |
|
496 | + } |
|
497 | + try { |
|
498 | + $settings[$row['priority']][] = $this->query($row['class']); |
|
499 | + } catch (QueryException $e) { |
|
500 | + // skip |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + ksort($settings); |
|
505 | + return $settings; |
|
506 | + } |
|
507 | 507 | } |
@@ -26,189 +26,189 @@ |
||
26 | 26 | use OCP\IDBConnection; |
27 | 27 | |
28 | 28 | class Mapper { |
29 | - const TABLE_ADMIN_SETTINGS = 'admin_settings'; |
|
30 | - const TABLE_ADMIN_SECTIONS = 'admin_sections'; |
|
31 | - const TABLE_PERSONAL_SETTINGS = 'personal_settings'; |
|
32 | - const TABLE_PERSONAL_SECTIONS = 'personal_sections'; |
|
33 | - |
|
34 | - /** @var IDBConnection */ |
|
35 | - private $dbc; |
|
36 | - |
|
37 | - /** |
|
38 | - * @param IDBConnection $dbc |
|
39 | - */ |
|
40 | - public function __construct(IDBConnection $dbc) { |
|
41 | - $this->dbc = $dbc; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Get the configured admin settings from the database for the provided section |
|
46 | - * |
|
47 | - * @param string $section |
|
48 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
49 | - */ |
|
50 | - public function getAdminSettingsFromDB($section) { |
|
51 | - return $this->getSettingsFromDB(self::TABLE_ADMIN_SETTINGS, $section); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Get the configured personal settings from the database for the provided section |
|
56 | - * |
|
57 | - * @param string $section |
|
58 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
59 | - */ |
|
60 | - public function getPersonalSettingsFromDB($section) { |
|
61 | - return $this->getSettingsFromDB(self::TABLE_PERSONAL_SETTINGS, $section); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Get the configured settings from the database for the provided table and section |
|
66 | - * |
|
67 | - * @param $table |
|
68 | - * @param $section |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - private function getSettingsFromDB($table, $section) { |
|
72 | - $query = $this->dbc->getQueryBuilder(); |
|
73 | - $query->select(['class', 'priority']) |
|
74 | - ->from($table) |
|
75 | - ->where($query->expr()->eq('section', $this->dbc->getQueryBuilder()->createParameter('section'))) |
|
76 | - ->setParameter('section', $section); |
|
77 | - |
|
78 | - $result = $query->execute(); |
|
79 | - return $result->fetchAll(); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Get the configured admin sections from the database |
|
84 | - * |
|
85 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
86 | - */ |
|
87 | - public function getAdminSectionsFromDB() { |
|
88 | - return $this->getSectionsFromDB('admin'); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Get the configured admin sections from the database |
|
93 | - * |
|
94 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
95 | - */ |
|
96 | - public function getPersonalSectionsFromDB() { |
|
97 | - return $this->getSectionsFromDB('personal'); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Get the configured sections from the database by table |
|
102 | - * |
|
103 | - * @param string $type either 'personal' or 'admin' |
|
104 | - * @return array[] [['class' => string, 'priority' => int], ...] |
|
105 | - */ |
|
106 | - public function getSectionsFromDB($type) { |
|
107 | - if($type === 'personal') { |
|
108 | - $sectionsTable = self::TABLE_ADMIN_SECTIONS; |
|
109 | - $settingsTable = self::TABLE_ADMIN_SETTINGS; |
|
110 | - } else if($type === 'admin') { |
|
111 | - $sectionsTable = self::TABLE_PERSONAL_SECTIONS; |
|
112 | - $settingsTable = self::TABLE_PERSONAL_SETTINGS; |
|
113 | - } else { |
|
114 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
115 | - } |
|
116 | - $query = $this->dbc->getQueryBuilder(); |
|
117 | - $query->selectDistinct('s.class') |
|
118 | - ->addSelect('s.priority') |
|
119 | - ->from($sectionsTable, 's') |
|
120 | - ->from($settingsTable, 'f') |
|
121 | - ->where($query->expr()->eq('s.id', 'f.section')); |
|
122 | - $result = $query->execute(); |
|
123 | - return array_map(function ($row) { |
|
124 | - $row['priority'] = (int)$row['priority']; |
|
125 | - return $row; |
|
126 | - }, $result->fetchAll()); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @param string $table one of the Mapper::TABLE_* constants |
|
131 | - * @param array $values |
|
132 | - */ |
|
133 | - public function add($table, array $values) { |
|
134 | - $query = $this->dbc->getQueryBuilder(); |
|
135 | - $values = array_map(function ($value) use ($query) { |
|
136 | - return $query->createNamedParameter($value); |
|
137 | - }, $values); |
|
138 | - $query->insert($table)->values($values); |
|
139 | - $query->execute(); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * returns the registered classes in the given table |
|
144 | - * |
|
145 | - * @param string $table one of the Mapper::TABLE_* constants |
|
146 | - * @return string[] |
|
147 | - */ |
|
148 | - public function getClasses($table) { |
|
149 | - $q = $this->dbc->getQueryBuilder(); |
|
150 | - $resultStatement = $q->select('class') |
|
151 | - ->from($table) |
|
152 | - ->execute(); |
|
153 | - $data = $resultStatement->fetchAll(); |
|
154 | - $resultStatement->closeCursor(); |
|
155 | - |
|
156 | - return array_map(function ($row) { |
|
157 | - return $row['class']; |
|
158 | - }, $data); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Check if a class is configured in the database |
|
163 | - * |
|
164 | - * @param string $table one of the Mapper::TABLE_* constants |
|
165 | - * @param string $className |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function has($table, $className) { |
|
169 | - $query = $this->dbc->getQueryBuilder(); |
|
170 | - $query->select('class') |
|
171 | - ->from($table) |
|
172 | - ->where($query->expr()->eq('class', $query->createNamedParameter($className))) |
|
173 | - ->setMaxResults(1); |
|
174 | - |
|
175 | - $result = $query->execute(); |
|
176 | - $row = $result->fetch(); |
|
177 | - $result->closeCursor(); |
|
178 | - |
|
179 | - return (bool)$row; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * deletes an settings or admin entry from the given table |
|
184 | - * |
|
185 | - * @param string $table one of the Mapper::TABLE_* constants |
|
186 | - * @param string $className |
|
187 | - */ |
|
188 | - public function remove($table, $className) { |
|
189 | - $query = $this->dbc->getQueryBuilder(); |
|
190 | - $query->delete($table) |
|
191 | - ->where($query->expr()->eq('class', $query->createNamedParameter($className))); |
|
192 | - |
|
193 | - $query->execute(); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param string $table one of the Mapper::TABLE_* constants |
|
198 | - * @param string $idCol |
|
199 | - * @param string $id |
|
200 | - * @param array $values |
|
201 | - */ |
|
202 | - public function update($table, $idCol, $id, $values) { |
|
203 | - $query = $this->dbc->getQueryBuilder(); |
|
204 | - $query->update($table); |
|
205 | - foreach ($values as $key => $value) { |
|
206 | - $query->set($key, $query->createNamedParameter($value)); |
|
207 | - } |
|
208 | - $query |
|
209 | - ->where($query->expr()->eq($idCol, $query->createParameter($idCol))) |
|
210 | - ->setParameter($idCol, $id) |
|
211 | - ->execute(); |
|
212 | - } |
|
29 | + const TABLE_ADMIN_SETTINGS = 'admin_settings'; |
|
30 | + const TABLE_ADMIN_SECTIONS = 'admin_sections'; |
|
31 | + const TABLE_PERSONAL_SETTINGS = 'personal_settings'; |
|
32 | + const TABLE_PERSONAL_SECTIONS = 'personal_sections'; |
|
33 | + |
|
34 | + /** @var IDBConnection */ |
|
35 | + private $dbc; |
|
36 | + |
|
37 | + /** |
|
38 | + * @param IDBConnection $dbc |
|
39 | + */ |
|
40 | + public function __construct(IDBConnection $dbc) { |
|
41 | + $this->dbc = $dbc; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Get the configured admin settings from the database for the provided section |
|
46 | + * |
|
47 | + * @param string $section |
|
48 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
49 | + */ |
|
50 | + public function getAdminSettingsFromDB($section) { |
|
51 | + return $this->getSettingsFromDB(self::TABLE_ADMIN_SETTINGS, $section); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Get the configured personal settings from the database for the provided section |
|
56 | + * |
|
57 | + * @param string $section |
|
58 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
59 | + */ |
|
60 | + public function getPersonalSettingsFromDB($section) { |
|
61 | + return $this->getSettingsFromDB(self::TABLE_PERSONAL_SETTINGS, $section); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Get the configured settings from the database for the provided table and section |
|
66 | + * |
|
67 | + * @param $table |
|
68 | + * @param $section |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + private function getSettingsFromDB($table, $section) { |
|
72 | + $query = $this->dbc->getQueryBuilder(); |
|
73 | + $query->select(['class', 'priority']) |
|
74 | + ->from($table) |
|
75 | + ->where($query->expr()->eq('section', $this->dbc->getQueryBuilder()->createParameter('section'))) |
|
76 | + ->setParameter('section', $section); |
|
77 | + |
|
78 | + $result = $query->execute(); |
|
79 | + return $result->fetchAll(); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Get the configured admin sections from the database |
|
84 | + * |
|
85 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
86 | + */ |
|
87 | + public function getAdminSectionsFromDB() { |
|
88 | + return $this->getSectionsFromDB('admin'); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Get the configured admin sections from the database |
|
93 | + * |
|
94 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
95 | + */ |
|
96 | + public function getPersonalSectionsFromDB() { |
|
97 | + return $this->getSectionsFromDB('personal'); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Get the configured sections from the database by table |
|
102 | + * |
|
103 | + * @param string $type either 'personal' or 'admin' |
|
104 | + * @return array[] [['class' => string, 'priority' => int], ...] |
|
105 | + */ |
|
106 | + public function getSectionsFromDB($type) { |
|
107 | + if($type === 'personal') { |
|
108 | + $sectionsTable = self::TABLE_ADMIN_SECTIONS; |
|
109 | + $settingsTable = self::TABLE_ADMIN_SETTINGS; |
|
110 | + } else if($type === 'admin') { |
|
111 | + $sectionsTable = self::TABLE_PERSONAL_SECTIONS; |
|
112 | + $settingsTable = self::TABLE_PERSONAL_SETTINGS; |
|
113 | + } else { |
|
114 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
115 | + } |
|
116 | + $query = $this->dbc->getQueryBuilder(); |
|
117 | + $query->selectDistinct('s.class') |
|
118 | + ->addSelect('s.priority') |
|
119 | + ->from($sectionsTable, 's') |
|
120 | + ->from($settingsTable, 'f') |
|
121 | + ->where($query->expr()->eq('s.id', 'f.section')); |
|
122 | + $result = $query->execute(); |
|
123 | + return array_map(function ($row) { |
|
124 | + $row['priority'] = (int)$row['priority']; |
|
125 | + return $row; |
|
126 | + }, $result->fetchAll()); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @param string $table one of the Mapper::TABLE_* constants |
|
131 | + * @param array $values |
|
132 | + */ |
|
133 | + public function add($table, array $values) { |
|
134 | + $query = $this->dbc->getQueryBuilder(); |
|
135 | + $values = array_map(function ($value) use ($query) { |
|
136 | + return $query->createNamedParameter($value); |
|
137 | + }, $values); |
|
138 | + $query->insert($table)->values($values); |
|
139 | + $query->execute(); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * returns the registered classes in the given table |
|
144 | + * |
|
145 | + * @param string $table one of the Mapper::TABLE_* constants |
|
146 | + * @return string[] |
|
147 | + */ |
|
148 | + public function getClasses($table) { |
|
149 | + $q = $this->dbc->getQueryBuilder(); |
|
150 | + $resultStatement = $q->select('class') |
|
151 | + ->from($table) |
|
152 | + ->execute(); |
|
153 | + $data = $resultStatement->fetchAll(); |
|
154 | + $resultStatement->closeCursor(); |
|
155 | + |
|
156 | + return array_map(function ($row) { |
|
157 | + return $row['class']; |
|
158 | + }, $data); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Check if a class is configured in the database |
|
163 | + * |
|
164 | + * @param string $table one of the Mapper::TABLE_* constants |
|
165 | + * @param string $className |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function has($table, $className) { |
|
169 | + $query = $this->dbc->getQueryBuilder(); |
|
170 | + $query->select('class') |
|
171 | + ->from($table) |
|
172 | + ->where($query->expr()->eq('class', $query->createNamedParameter($className))) |
|
173 | + ->setMaxResults(1); |
|
174 | + |
|
175 | + $result = $query->execute(); |
|
176 | + $row = $result->fetch(); |
|
177 | + $result->closeCursor(); |
|
178 | + |
|
179 | + return (bool)$row; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * deletes an settings or admin entry from the given table |
|
184 | + * |
|
185 | + * @param string $table one of the Mapper::TABLE_* constants |
|
186 | + * @param string $className |
|
187 | + */ |
|
188 | + public function remove($table, $className) { |
|
189 | + $query = $this->dbc->getQueryBuilder(); |
|
190 | + $query->delete($table) |
|
191 | + ->where($query->expr()->eq('class', $query->createNamedParameter($className))); |
|
192 | + |
|
193 | + $query->execute(); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param string $table one of the Mapper::TABLE_* constants |
|
198 | + * @param string $idCol |
|
199 | + * @param string $id |
|
200 | + * @param array $values |
|
201 | + */ |
|
202 | + public function update($table, $idCol, $id, $values) { |
|
203 | + $query = $this->dbc->getQueryBuilder(); |
|
204 | + $query->update($table); |
|
205 | + foreach ($values as $key => $value) { |
|
206 | + $query->set($key, $query->createNamedParameter($value)); |
|
207 | + } |
|
208 | + $query |
|
209 | + ->where($query->expr()->eq($idCol, $query->createParameter($idCol))) |
|
210 | + ->setParameter($idCol, $id) |
|
211 | + ->execute(); |
|
212 | + } |
|
213 | 213 | |
214 | 214 | } |