| @@ 205-230 (lines=26) @@ | ||
| 202 | * @param string $sectionClassName |
|
| 203 | * @param string $type either 'admin' or 'personal' |
|
| 204 | */ |
|
| 205 | private function setupSectionEntry($sectionClassName, $type) { |
|
| 206 | if (!class_exists($sectionClassName)) { |
|
| 207 | $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
| 208 | return; |
|
| 209 | } |
|
| 210 | try { |
|
| 211 | $section = $this->query($sectionClassName); |
|
| 212 | } catch (QueryException $e) { |
|
| 213 | // cancel |
|
| 214 | return; |
|
| 215 | } |
|
| 216 | ||
| 217 | if (!$section instanceof ISection) { |
|
| 218 | $this->log->error( |
|
| 219 | ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
| 220 | ['class' => $sectionClassName] |
|
| 221 | ); |
|
| 222 | return; |
|
| 223 | } |
|
| 224 | $table = $this->getSectionTableForType($type); |
|
| 225 | if(!$this->hasSection(get_class($section), $table)) { |
|
| 226 | $this->addSection($section, $table); |
|
| 227 | } else { |
|
| 228 | $this->updateSection($section, $table); |
|
| 229 | } |
|
| 230 | } |
|
| 231 | ||
| 232 | private function addSection(ISection $section, $table) { |
|
| 233 | $this->mapper->add($table, [ |
|
| @@ 289-316 (lines=28) @@ | ||
| 286 | return $this->mapper->has($table, $className); |
|
| 287 | } |
|
| 288 | ||
| 289 | private function setupSettingsEntry($settingsClassName, $type) { |
|
| 290 | if (!class_exists($settingsClassName)) { |
|
| 291 | $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
| 292 | return; |
|
| 293 | } |
|
| 294 | ||
| 295 | try { |
|
| 296 | /** @var ISettings $settings */ |
|
| 297 | $settings = $this->query($settingsClassName); |
|
| 298 | } catch (QueryException $e) { |
|
| 299 | // cancel |
|
| 300 | return; |
|
| 301 | } |
|
| 302 | ||
| 303 | if (!$settings instanceof ISettings) { |
|
| 304 | $this->log->error( |
|
| 305 | ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
| 306 | ['class' => $settingsClassName] |
|
| 307 | ); |
|
| 308 | return; |
|
| 309 | } |
|
| 310 | $table = $this->getSettingsTableForType($type); |
|
| 311 | if (!$this->hasSettings(get_class($settings), $table)) { |
|
| 312 | $this->addSettings($settings, $table); |
|
| 313 | } else { |
|
| 314 | $this->updateSettings($settings, $table); |
|
| 315 | } |
|
| 316 | } |
|
| 317 | ||
| 318 | private function getSectionTableForType($type) { |
|
| 319 | if($type === 'admin') { |
|