Fix database index name length issue

This commit is contained in:
Alfred Egger 2020-10-31 21:05:16 +01:00
parent ff68682b75
commit 048b77192e
3 changed files with 12 additions and 12 deletions

View File

@ -16,7 +16,7 @@ use OCP\IDBConnection;
class PreferenceMapper extends ReaderMapper {
public function __construct(IDBConnection $db, $UserId, Time $time) {
parent::__construct($db, 'reader_preferences', Preference::class, $time);
parent::__construct($db, 'reader_prefs', Preference::class, $time);
$this->userId = $UserId;
}
@ -30,14 +30,14 @@ class PreferenceMapper extends ReaderMapper {
*/
public function get($scope, $fileId, $name=null) {
if(!empty($name)) {
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `name`=?";
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `name`=?";
$args = array(
$scope,
$fileId,
$this->userId,
$name);
} else {
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE `scope`=? AND `file_id`=? AND `user_id`=?";
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=?";
$args = array(
$scope,
$fileId,
@ -83,7 +83,7 @@ class PreferenceMapper extends ReaderMapper {
/* currently not used*/
public function deleteForFileId($fileId) {
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE file_id=?";
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE file_id=?";
$args = [ $fileId ];
array_map(
function($entity) {
@ -94,7 +94,7 @@ class PreferenceMapper extends ReaderMapper {
/* currently not used*/
public function deleteForUserId($userId) {
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE user_id=?";
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE user_id=?";
$args = [ $userId ];
array_map(
function($entity) {

View File

@ -50,7 +50,7 @@ class Hooks {
$queryBuilder->execute();
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_preferences')->where('file_id = :file_id')->setParameter(':file_id', $fileId);
$queryBuilder->delete('reader_prefs')->where('file_id = :file_id')->setParameter(':file_id', $fileId);
$queryBuilder->execute();
}
@ -60,7 +60,7 @@ class Hooks {
$queryBuilder->execute();
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_preferences')->where('user_id = :user_id')->setParameter(':user_id', $userId);
$queryBuilder->delete('reader_prefs')->where('user_id = :user_id')->setParameter(':user_id', $userId);
$queryBuilder->execute();
}

View File

@ -84,8 +84,8 @@ class Version010402Date20200508180941 extends SimpleMigrationStep {
$table->addIndex(['name'], 'reader_bookmarks_name_index');
}
if (!$schema->hasTable('reader_preferences')) {
$table = $schema->createTable('reader_preferences');
if (!$schema->hasTable('reader_prefs')) {
$table = $schema->createTable('reader_prefs');
$table->addColumn('id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
@ -126,9 +126,9 @@ class Version010402Date20200508180941 extends SimpleMigrationStep {
'unsigned' => true,
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['file_id'], 'reader_preferences_file_id_index');
$table->addIndex(['user_id'], 'reader_preferences_user_id_index');
$table->addIndex(['scope'], 'reader_preferences_scope_index');
$table->addIndex(['file_id'], 'reader_prefs_file_id_index');
$table->addIndex(['user_id'], 'reader_prefs_user_id_index');
$table->addIndex(['scope'], 'reader_prefs_scope_index');
}
return $schema;
}