Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-12-02 13:40:36 +0300
committerJoas Schilling <coding@schilljs.com>2020-12-07 16:19:37 +0300
commiteaba155a09ea7d226b538c5c8d046d2ea839b452 (patch)
treef6ea38804766d9347a6785bf343d541511dde1c4
parentefe79f293764225b6036565cb0b5f5a29a16d0ca (diff)
Add a database table for the accounts data so we can search it better
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--core/Migrations/Version21000Date20201202095923.php75
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Accounts/AccountManager.php49
-rw-r--r--version.php2
5 files changed, 125 insertions, 3 deletions
diff --git a/core/Migrations/Version21000Date20201202095923.php b/core/Migrations/Version21000Date20201202095923.php
new file mode 100644
index 00000000000..6433d8c9b7a
--- /dev/null
+++ b/core/Migrations/Version21000Date20201202095923.php
@@ -0,0 +1,75 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Core\Migrations;
+
+use Closure;
+use Doctrine\DBAL\Types\Types;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+class Version21000Date20201202095923 extends SimpleMigrationStep {
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ if (!$schema->hasTable('accounts_data')) {
+ $table = $schema->createTable('accounts_data');
+ $table->addColumn('id', Types::BIGINT, [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ 'length' => 20,
+ ]);
+ $table->addColumn('uid', Types::STRING, [
+ 'notnull' => true,
+ 'length' => 64,
+ ]);
+ $table->addColumn('name', Types::STRING, [
+ 'notnull' => true,
+ 'length' => 64,
+ ]);
+ $table->addColumn('value', Types::STRING, [
+ 'notnull' => false,
+ 'length' => 255,
+ 'default' => '',
+ ]);
+ $table->setPrimaryKey(['id']);
+ $table->addIndex(['uid'], 'accounts_data_uid');
+ $table->addIndex(['name'], 'accounts_data_name');
+ $table->addIndex(['value'], 'accounts_data_value');
+
+ return $schema;
+ }
+
+ return null;
+ }
+}
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 0400e681090..c043ef4d3ba 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -930,6 +930,7 @@ return array(
'OC\\Core\\Migrations\\Version20000Date20201109081918' => $baseDir . '/core/Migrations/Version20000Date20201109081918.php',
'OC\\Core\\Migrations\\Version20000Date20201109081919' => $baseDir . '/core/Migrations/Version20000Date20201109081919.php',
'OC\\Core\\Migrations\\Version20000Date20201111081915' => $baseDir . '/core/Migrations/Version20000Date20201111081915.php',
+ 'OC\\Core\\Migrations\\Version21000Date20201202095923' => $baseDir . '/core/Migrations/Version21000Date20201202095923.php',
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index b9b4f2f307b..f9177dbb048 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -959,6 +959,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Migrations\\Version20000Date20201109081918' => __DIR__ . '/../../..' . '/core/Migrations/Version20000Date20201109081918.php',
'OC\\Core\\Migrations\\Version20000Date20201109081919' => __DIR__ . '/../../..' . '/core/Migrations/Version20000Date20201109081919.php',
'OC\\Core\\Migrations\\Version20000Date20201111081915' => __DIR__ . '/../../..' . '/core/Migrations/Version20000Date20201111081915.php',
+ 'OC\\Core\\Migrations\\Version21000Date20201202095923' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20201202095923.php',
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index 0c488eec635..c473d563781 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -58,6 +58,9 @@ class AccountManager implements IAccountManager {
/** @var string table name */
private $table = 'accounts';
+ /** @var string table name */
+ private $dataTable = 'accounts_data';
+
/** @var EventDispatcherInterface */
private $eventDispatcher;
@@ -116,6 +119,21 @@ class AccountManager implements IAccountManager {
$query->delete($this->table)
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
->execute();
+
+ $this->deleteUserData($user);
+ }
+
+ /**
+ * delete user from accounts table
+ *
+ * @param IUser $user
+ */
+ public function deleteUserData(IUser $user): void {
+ $uid = $user->getUID();
+ $query = $this->connection->getQueryBuilder();
+ $query->delete($this->dataTable)
+ ->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
+ ->execute();
}
/**
@@ -256,7 +274,7 @@ class AccountManager implements IAccountManager {
* @param IUser $user
* @param array $data
*/
- protected function insertNewUser(IUser $user, $data) {
+ protected function insertNewUser(IUser $user, array $data): void {
$uid = $user->getUID();
$jsonEncodedData = json_encode($data);
$query = $this->connection->getQueryBuilder();
@@ -268,6 +286,9 @@ class AccountManager implements IAccountManager {
]
)
->execute();
+
+ $this->deleteUserData($user);
+ $this->writeUserData($user, $data);
}
/**
@@ -276,7 +297,7 @@ class AccountManager implements IAccountManager {
* @param IUser $user
* @param array $data
*/
- protected function updateExistingUser(IUser $user, $data) {
+ protected function updateExistingUser(IUser $user, array $data): void {
$uid = $user->getUID();
$jsonEncodedData = json_encode($data);
$query = $this->connection->getQueryBuilder();
@@ -284,6 +305,30 @@ class AccountManager implements IAccountManager {
->set('data', $query->createNamedParameter($jsonEncodedData))
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
->execute();
+
+ $this->deleteUserData($user);
+ $this->writeUserData($user, $data);
+ }
+
+ protected function writeUserData(IUser $user, array $data): void {
+ $query = $this->connection->getQueryBuilder();
+ $query->insert($this->dataTable)
+ ->values(
+ [
+ 'uid' => $query->createNamedParameter($user->getUID()),
+ 'name' => $query->createParameter('name'),
+ 'value' => $query->createParameter('value'),
+ ]
+ );
+ foreach ($data as $propertyName => $property) {
+ if ($propertyName === self::PROPERTY_AVATAR) {
+ continue;
+ }
+
+ $query->setParameter('name', $propertyName)
+ ->setParameter('value', $property['value']);
+ $query->execute();
+ }
}
/**
diff --git a/version.php b/version.php
index 24e3e8db6ae..299855816a9 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number.
-$OC_Version = [21, 0, 0, 7];
+$OC_Version = [21, 0, 0, 8];
// The human readable string
$OC_VersionString = '21.0.0 alpha';