summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-05-19 12:11:07 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-06-23 12:36:38 +0200
commit7f48b6f14faf42774332ef90a7fa660f1bbd1633 (patch)
tree7c287a7ee91a69b038ca63ea0020a824b0525569 /lib/private
parentd56e86cfde49910d3af564fb7e6dd553279dfc3c (diff)
downloadnextcloud-server-7f48b6f14faf42774332ef90a7fa660f1bbd1633.tar.gz
nextcloud-server-7f48b6f14faf42774332ef90a7fa660f1bbd1633.zip
Adopt DB and Manager to personal settings structure
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Settings/Manager.php100
-rw-r--r--lib/private/Settings/Mapper.php37
2 files changed, 97 insertions, 40 deletions
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index 19937bd7afd..707550c0bb7 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -41,9 +41,6 @@ use OCP\Settings\IManager;
use OCP\Settings\ISection;
class Manager implements IManager {
- const TABLE_ADMIN_SETTINGS = 'admin_settings';
- const TABLE_ADMIN_SECTIONS = 'admin_sections';
-
/** @var ILogger */
private $log;
/** @var IDBConnection */
@@ -87,6 +84,7 @@ class Manager implements IManager {
* @param AccountManager $accountManager
* @param IGroupManager $groupManager
* @param IFactory $l10nFactory
+ * @param \OC_Defaults $defaults
*/
public function __construct(
ILogger $log,
@@ -125,10 +123,17 @@ class Manager implements IManager {
*/
public function setupSettings(array $settings) {
if (isset($settings[IManager::KEY_ADMIN_SECTION])) {
- $this->setupAdminSection($settings[IManager::KEY_ADMIN_SECTION]);
+ $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin');
}
if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) {
- $this->setupAdminSettings($settings[IManager::KEY_ADMIN_SETTINGS]);
+ $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin');
+ }
+
+ if (isset($settings[IManager::KEY_PERSONAL_SECTION])) {
+ $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal');
+ }
+ if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) {
+ $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal');
}
}
@@ -144,15 +149,22 @@ class Manager implements IManager {
$appInfo = \OC_App::getAppInfo($appId); // hello static legacy
if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
- $this->mapper->remove(self::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
+ $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\'));
}
if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) {
- $this->mapper->remove(self::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
+ $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\'));
+ }
+
+ if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) {
+ $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\'));
+ }
+ if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) {
+ $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\'));
}
}
public function checkForOrphanedClassNames() {
- $tables = [self::TABLE_ADMIN_SECTIONS, self::TABLE_ADMIN_SETTINGS];
+ $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS];
foreach ($tables as $table) {
$classes = $this->mapper->getClasses($table);
foreach ($classes as $className) {
@@ -167,10 +179,11 @@ class Manager implements IManager {
/**
* @param string $sectionClassName
+ * @param string $type either 'admin' or 'personal'
*/
- private function setupAdminSection($sectionClassName) {
+ private function setupSectionEntry($sectionClassName, $type) {
if (!class_exists($sectionClassName)) {
- $this->log->debug('Could not find admin section class ' . $sectionClassName);
+ $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName);
return;
}
try {
@@ -182,37 +195,38 @@ class Manager implements IManager {
if (!$section instanceof ISection) {
$this->log->error(
- 'Admin section instance must implement \OCP\ISection. Invalid class: {class}',
+ ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}',
['class' => $sectionClassName]
);
return;
}
- if (!$this->hasAdminSection(get_class($section))) {
- $this->addAdminSection($section);
+ $table = $this->getSectionTableForType($type);
+ if(!$this->hasSection(get_class($section), $table)) {
+ $this->addSection($section, $table);
} else {
- $this->updateAdminSection($section);
+ $this->updateSection($section, $table);
}
}
- private function addAdminSection(ISection $section) {
- $this->mapper->add(self::TABLE_ADMIN_SECTIONS, [
+ private function addSection(ISection $section, $table) {
+ $this->mapper->add($table, [
'id' => $section->getID(),
'class' => get_class($section),
'priority' => $section->getPriority(),
]);
}
- private function addAdminSettings(ISettings $settings) {
- $this->mapper->add(self::TABLE_ADMIN_SETTINGS, [
+ private function addSettings(ISettings $settings, $table) {
+ $this->mapper->add($table, [
'class' => get_class($settings),
'section' => $settings->getSection(),
'priority' => $settings->getPriority(),
]);
}
- private function updateAdminSettings(ISettings $settings) {
+ private function updateSettings(ISettings $settings, $table) {
$this->mapper->update(
- self::TABLE_ADMIN_SETTINGS,
+ $table,
'class',
get_class($settings),
[
@@ -222,9 +236,9 @@ class Manager implements IManager {
);
}
- private function updateAdminSection(ISection $section) {
+ private function updateSection(ISection $section, $table) {
$this->mapper->update(
- self::TABLE_ADMIN_SECTIONS,
+ $table,
'class',
get_class($section),
[
@@ -236,23 +250,24 @@ class Manager implements IManager {
/**
* @param string $className
+ * @param string $table
* @return bool
*/
- private function hasAdminSection($className) {
- return $this->mapper->has(self::TABLE_ADMIN_SECTIONS, $className);
+ private function hasSection($className, $table) {
+ return $this->mapper->has($table, $className);
}
/**
* @param string $className
* @return bool
*/
- private function hasAdminSettings($className) {
- return $this->mapper->has(self::TABLE_ADMIN_SETTINGS, $className);
+ private function hasSettings($className, $table) {
+ return $this->mapper->has($table, $className);
}
- private function setupAdminSettings($settingsClassName) {
+ private function setupSettingsEntry($settingsClassName, $type) {
if (!class_exists($settingsClassName)) {
- $this->log->debug('Could not find admin section class ' . $settingsClassName);
+ $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName);
return;
}
@@ -266,18 +281,37 @@ class Manager implements IManager {
if (!$settings instanceof ISettings) {
$this->log->error(
- 'Admin section instance must implement \OCP\Settings\ISection. Invalid class: {class}',
+ ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}',
['class' => $settingsClassName]
);
return;
}
- if (!$this->hasAdminSettings(get_class($settings))) {
- $this->addAdminSettings($settings);
+ $table = $this->getSettingsTableForType($type);
+ if (!$this->hasSettings(get_class($settings), $table)) {
+ $this->addSettings($settings, $table);
} else {
- $this->updateAdminSettings($settings);
+ $this->updateSettings($settings, $table);
}
}
+ private function getSectionTableForType($type) {
+ if($type === 'admin') {
+ return Mapper::TABLE_ADMIN_SECTIONS;
+ } else if($type === 'personal') {
+ return Mapper::TABLE_PERSONAL_SECTIONS;
+ }
+ throw new \InvalidArgumentException('"admin" or "personal" expected');
+ }
+
+ private function getSettingsTableForType($type) {
+ if($type === 'admin') {
+ return Mapper::TABLE_ADMIN_SETTINGS;
+ } else if($type === 'personal') {
+ return Mapper::TABLE_PERSONAL_SETTINGS;
+ }
+ throw new \InvalidArgumentException('"admin" or "personal" expected');
+ }
+
private function query($className) {
try {
return \OC::$server->query($className);
@@ -423,7 +457,7 @@ class Manager implements IManager {
5 => [new Section('sessions', $this->l->t('Sessions'), 0, $this->url->imagePath('settings', 'admin.svg'))],
10 => [new Section('app-passwords', $this->l->t('App passwords'), 0, $this->url->imagePath('settings', 'password.svg'))],
15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))],
-
+ 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
];
return $sections;
}
diff --git a/lib/private/Settings/Mapper.php b/lib/private/Settings/Mapper.php
index 7dea1fe3d81..44ba7dd9cbe 100644
--- a/lib/private/Settings/Mapper.php
+++ b/lib/private/Settings/Mapper.php
@@ -28,6 +28,8 @@ use OCP\IDBConnection;
class Mapper {
const TABLE_ADMIN_SETTINGS = 'admin_settings';
const TABLE_ADMIN_SECTIONS = 'admin_sections';
+ const TABLE_PERSONAL_SETTINGS = 'personal_settings';
+ const TABLE_PERSONAL_SECTIONS = 'personal_sections';
/** @var IDBConnection */
private $dbc;
@@ -46,9 +48,30 @@ class Mapper {
* @return array[] [['class' => string, 'priority' => int], ...]
*/
public function getAdminSettingsFromDB($section) {
+ return $this->getSettingsFromDB(self::TABLE_ADMIN_SETTINGS, $section);
+ }
+
+ /**
+ * Get the configured personal settings from the database for the provided section
+ *
+ * @param string $section
+ * @return array[] [['class' => string, 'priority' => int], ...]
+ */
+ public function getPersonalSettingsFromDB($section) {
+ return $this->getSettingsFromDB(self::TABLE_PERSONAL_SETTINGS, $section);
+ }
+
+ /**
+ * Get the configured settings from the database for the provided table and section
+ *
+ * @param $table
+ * @param $section
+ * @return array
+ */
+ private function getSettingsFromDB($table, $section) {
$query = $this->dbc->getQueryBuilder();
$query->select(['class', 'priority'])
- ->from(self::TABLE_ADMIN_SETTINGS)
+ ->from($table)
->where($query->expr()->eq('section', $this->dbc->getQueryBuilder()->createParameter('section')))
->setParameter('section', $section);
@@ -76,7 +99,7 @@ class Mapper {
}
/**
- * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
+ * @param string $table one of the Mapper::TABLE_* constants
* @param array $values
*/
public function add($table, array $values) {
@@ -91,7 +114,7 @@ class Mapper {
/**
* returns the registered classes in the given table
*
- * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
+ * @param string $table one of the Mapper::TABLE_* constants
* @return string[]
*/
public function getClasses($table) {
@@ -110,7 +133,7 @@ class Mapper {
/**
* Check if a class is configured in the database
*
- * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
+ * @param string $table one of the Mapper::TABLE_* constants
* @param string $className
* @return bool
*/
@@ -131,8 +154,8 @@ class Mapper {
/**
* deletes an settings or admin entry from the given table
*
- * @param $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
- * @param $className
+ * @param string $table one of the Mapper::TABLE_* constants
+ * @param string $className
*/
public function remove($table, $className) {
$query = $this->dbc->getQueryBuilder();
@@ -143,7 +166,7 @@ class Mapper {
}
/**
- * @param string $table Mapper::TABLE_ADMIN_SECTIONS or Mapper::TABLE_ADMIN_SETTINGS
+ * @param string $table one of the Mapper::TABLE_* constants
* @param string $idCol
* @param string $id
* @param array $values