Skip to content

Commit

Permalink
- Revert to oc_reader_prefs to avoid problem with "too long index na…
Browse files Browse the repository at this point in the history
…me", this undoes the change in 1.5.2.

 - reduce maximum database string column size to 3999 to get around '4000 length limit' (nextcloud/server#31791)
  • Loading branch information
Frank de Lange committed Sep 24, 2022
1 parent 5e20a5b commit d875ae5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 179 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## 1.5.3 - 2022-08-24
### Fixed
- Revert to oc_reader_prefs to avoid problem with "too long index name", this undoes the change in 1.5.2.
- reduce maximum database string column size to 3999 to get around '4000 length limit' (https://github.com/nextcloud/server/issues/31791)

## 1.5.2 - 2022-08-24
### Fixed
- Typo in (database) Migrations kept Reader working for those who did not already have the correct table in their database
- Typo in (database) Migrations kept Reader from working for those who did not already have the correct table in their database

## 1.5.1 - 2022-08-24
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See [README] for more exhaustive information on features and potential misfeatur
[README]: https://github.com/Yetangitu/owncloud-apps/blob/master/files_reader/README.md
]]>
</description>
<version>1.5.2</version>
<version>1.5.3</version>
<licence>AGPL</licence>
<author>Frank de Lange</author>
<documentation>
Expand Down
3 changes: 0 additions & 3 deletions js/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ document.onreadystatechange = function () {
options.session.basePath = $session.data('basepath');
options.session.downloadLink = $session.data('downloadlink');

console.log(options.session.basePath);


/* functions return jquery promises */
options.session.getPreference = function(name) {
return $.get(options.session.basePath + "preference/" + options.session.fileId + "/" + options.session.scope + "/" + name);
Expand Down
12 changes: 6 additions & 6 deletions lib/Db/PreferenceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
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;
}

/**
* @brief get preferences for $scope+$fileId+$userId(+$name)
* @brief get prefs for $scope+$fileId+$userId(+$name)
*
* @param string $scope
* @param int $fileId
Expand All @@ -30,14 +30,14 @@ public function __construct(IDBConnection $db, $UserId, Time $time) {
*/
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,
Expand Down Expand Up @@ -83,7 +83,7 @@ public function set($scope, $fileId, $name, $value) {

/* 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) {
Expand All @@ -94,7 +94,7 @@ function($entity) {

/* 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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected static function deleteFile(IDBConnection $connection, $fileId) {
$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();
}

Expand All @@ -43,7 +43,7 @@ protected static function deleteUser(IDBConnection $connection, $userId) {
$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();
}
}
6 changes: 3 additions & 3 deletions lib/Listeners/LoadViewerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function handle(Event $event): void {
if (!($event instanceof LoadViewer || $event instanceof LoadAdditionalScriptsEvent)) {
return;
}
$this->initialStateService->provideInitialState('epub_enabled', $this->config->getUserValue($this->userId, Application::APP_ID, 'epub_enable'));
$this->initialStateService->provideInitialState('pdf_enabled', $this->config->getUserValue($this->userId, Application::APP_ID, 'pdf_enable'));
$this->initialStateService->provideInitialState('cbx_enabled', $this->config->getUserValue($this->userId, Application::APP_ID, 'cbx_enable'));
$this->initialStateService->provideInitialState('epub_enabled', $this->config->getUserValue($this->userId, Application::APP_ID, 'epub_enable', 'true'));
$this->initialStateService->provideInitialState('pdf_enabled', $this->config->getUserValue($this->userId, Application::APP_ID, 'pdf_enable', 'true'));
$this->initialStateService->provideInitialState('cbx_enabled', $this->config->getUserValue($this->userId, Application::APP_ID, 'cbx_enable', 'true'));
Util::addScript(Application::APP_ID, 'plugin');
}
}
143 changes: 0 additions & 143 deletions lib/Migration/Version013000Date202209191710407.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Auto-generated migration step
*/
class Version015002Date20220924183940 extends SimpleMigrationStep {
class Version015003Date20220924233946 extends SimpleMigrationStep {

/**
* @param IOutput $output
Expand Down Expand Up @@ -40,13 +40,13 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'length' => 8,
'unsigned' => true,
]);
// user ID, maps bookmark to NC/OC user
// user ID, maps bookmark to NC user
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
'default' => '',
]);
// file ID, maps to NC/OC file ID
// file ID, maps to NC file ID
$table->addColumn('file_id', 'bigint', [
'notnull' => true,
'length' => 11,
Expand All @@ -70,7 +70,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
]);
$table->addColumn('content', 'string', [
'notnull' => false,
'length' => 4096,
'length' => 3999,
]);
$table->addColumn('last_modified', 'bigint', [
'notnull' => false,
Expand All @@ -84,21 +84,21 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$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,
'length' => 8,
'unsigned' => true,
]);
// user ID, maps preference to NC/OC user
// user ID, maps preference to NC user
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
'default' => '',
]);
// file ID, maps to NC/OC file ID
// file ID, maps to NC file ID
$table->addColumn('file_id', 'bigint', [
'notnull' => true,
'length' => 11,
Expand All @@ -116,7 +116,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
]);
$table->addColumn('value', 'string', [
'notnull' => true,
'length' => 4096,
'length' => 3999,
'default' => '',
]);
$table->addColumn('last_modified', 'bigint', [
Expand All @@ -126,17 +126,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'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');
}

if ($schema->hasTable('reader_prefs')) {
$table = $schema->getTable('reader_prefs');
$table->dropIndex('reader_prefs_file_id_index');
$table->dropIndex('reader_prefs_user_id_index');
$table->dropIndex('reader_prefs_scope_index');
$schema->dropTable('reader_prefs');
$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;
}
Expand Down

0 comments on commit d875ae5

Please sign in to comment.