Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ All notable changes to this project will be documented in this file.
### Added
- OpenAPI spec

### Fixed
- Fixed some code inconsitencies regarding nullish groupIds and pollIds.
- Added share repair fix to repair steps after updates.
- Purge soft-deleted entries after the documented 12 hour undo window

### Changes
- Added salt to user name obfuscation
- Support Nextcloud 31
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/CleanMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/CreateIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/FixDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/Purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Command\Db;

use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Db/Rebuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace OCA\Polls\Command\Db;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\TableManager;
use OCA\Polls\Db\V11\IndexManager;
use OCA\Polls\Command\Command;
use OCP\IDBConnection;

Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/RemoveFKConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/RemoveOptionalIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/RemoveUniqueIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Db/ResetUniqueIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Command/Db/ResetWatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\IndexManager;
use OCA\Polls\Db\V11\TableManager;
use OCA\Polls\Db\Watch;
use OCA\Polls\Migration\V10\TableSchema;
use OCA\Polls\Migration\V11\TableSchema;
use OCP\IDBConnection;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cron/JanitorCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Db\PollMapper;
use OCA\Polls\Db\ShareMapper;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCA\Polls\Db\VoteMapper;
use OCA\Polls\Model\Settings\AppSettings;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down
5 changes: 3 additions & 2 deletions lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class Share extends EntityWithUser implements JsonSerializable {

public function __construct() {
$this->addType('pollId', 'integer');
$this->addType('groupId', 'integer');
$this->addType('invitationSent', 'integer');
$this->addType('locked', 'integer');
$this->addType('reminderSent', 'integer');
Expand Down Expand Up @@ -204,7 +205,7 @@ public function getUser(): UserBase {
* @throws InvalidShareTypeException
*/
public function getPollIdOrFail(): int {
if ($this->pollId === null) {
if (!$this->pollId) {
throw new InvalidShareTypeException('Share is not associated with a poll');
}
return $this->pollId;
Expand Down Expand Up @@ -310,7 +311,7 @@ public function getLocale(): string {
}

public function getURL(): string {
if ($this->getPollId() === null) {
if (!$this->getPollId()) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/V10/DbManager.php → lib/Db/V11/DbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Polls\Db\V10;
namespace OCA\Polls\Db\V11;

use Doctrine\DBAL\Schema\Schema;
use Exception;
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/V10/IndexManager.php → lib/Db/V11/IndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Polls\Db\V10;
namespace OCA\Polls\Db\V11;

use Doctrine\DBAL\Schema\Exception\IndexAlreadyExists;
use Doctrine\DBAL\Schema\Exception\IndexDoesNotExist;
use Exception;
use OCA\Polls\Migration\V10\TableSchema;
use OCA\Polls\Migration\V11\TableSchema;
use OCP\IConfig;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
Expand Down
39 changes: 33 additions & 6 deletions lib/Db/V10/TableManager.php → lib/Db/V11/TableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Polls\Db\V10;
namespace OCA\Polls\Db\V11;

use Doctrine\DBAL\Types\Type;
use Exception;
Expand All @@ -20,7 +20,7 @@
use OCA\Polls\Db\Watch;
use OCA\Polls\Exceptions\PreconditionException;
use OCA\Polls\Helper\Hash;
use OCA\Polls\Migration\V10\TableSchema;
use OCA\Polls\Migration\V11\TableSchema;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
Expand Down Expand Up @@ -154,8 +154,11 @@ public function createTable(string $tableName): array {
foreach ($columns as $columnName => $columnDefinition) {
if ($table->hasColumn($columnName)) {
$column = $table->getColumn($columnName);
if (Type::lookupName($column->getType()) !== $columnDefinition['type']) {
$messages[] = 'Migrated type of ' . $table->getName() . '[\'' . $columnName . '\'] from ' . Type::lookupName($column->getType()) . ' to ' . $columnDefinition['type'];
// Use $column->getType()->getName() instead of the static Type::lookupName():
// since Nextcloud 35, ISchemaWrapper no longer returns a raw
// Doctrine\DBAL\Types\Type but an OCP\DB\Schema wrapper - getName() works on both.
if ($column->getType()->getName() !== $columnDefinition['type']) {
$messages[] = 'Migrated type of ' . $table->getName() . '[\'' . $columnName . '\'] from ' . $column->getType()->getName() . ' to ' . $columnDefinition['type'];
$column->setType(Type::getType($columnDefinition['type']));
}
$column->setOptions($columnDefinition['options']);
Expand Down Expand Up @@ -421,10 +424,34 @@ private function deleteDuplicates(string $table, array $columns):int {
return 0;
}

// NULL-safe comparison: a UNIQUE index never catches "duplicate" NULLs on
// its own. Where the schema declares a default, NULL and that default
// represent the same "unset" state (e.g. a nullish and an already
// normalized poll_id/group_id = 0 are the same logical value), so compare
// both sides through the declared default via COALESCE. Without a known
// default, fall back to treating two NULLs as equal.
$default = TableSchema::TABLES[$table][$column]['options']['default'] ?? null;

if ($default !== null) {
$defaultType = is_int($default) ? IQueryBuilder::PARAM_INT : IQueryBuilder::PARAM_STR;
$columnsMatch = $qb->expr()->eq(
$qb->createFunction('COALESCE(t1.' . $column . ', ' . $qb->createNamedParameter($default, $defaultType) . ')'),
$qb->createFunction('COALESCE(t2.' . $column . ', ' . $qb->createNamedParameter($default, $defaultType) . ')')
);
} else {
$columnsMatch = $qb->expr()->orX(
$qb->expr()->eq('t1.' . $column, 't2.' . $column),
$qb->expr()->andX(
$qb->expr()->isNull('t1.' . $column),
$qb->expr()->isNull('t2.' . $column)
)
);
}

if ($i > 0) {
$selection->andWhere($qb->expr()->eq('t1.' . $column, 't2.' . $column));
$selection->andWhere($columnsMatch);
} else {
$selection->where($qb->expr()->eq('t1.' . $column, 't2.' . $column));
$selection->where($columnsMatch);
}
$i++;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Listener/AddMissingIndicesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Listener;

use OCA\Polls\Migration\V10\TableSchema;
use OCA\Polls\Migration\V11\TableSchema;
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/FixVotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
5 changes: 4 additions & 1 deletion lib/Migration/RepairSteps/CleanTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Doctrine\DBAL\Schema\Schema;
use Exception;
use OCA\Polls\Db\Poll;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down Expand Up @@ -42,9 +42,12 @@ public function run(IOutput $output):void {
$this->tableManager->migrateShareLabels();
$this->tableManager->removeOrphaned();
$this->tableManager->deleteAllDuplicates();
$this->tableManager->fixNullishShares();
$this->tableManager->fixNullishPollGroupRelations();
$this->tableManager->tidyWatchTable(time());
} catch (Exception $e) {
// Simply skip repair, if it breaks and rely on the next run
$output->warning('Polls - CleanTables repair step failed: ' . $e->getMessage());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/CreateIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\Share;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/CreateTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration\RepairSteps;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/CreateUniqueIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Migration\RepairSteps;

use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/DropOrphanedColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration\RepairSteps;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/DropOrphanedIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration\RepairSteps;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/DropOrphanedTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration\RepairSteps;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/FixNullish.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Migration\RepairSteps;

use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Migration\RepairSteps;

use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/MigratePublicToOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Migration\RepairSteps;

use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/RemoveIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration\RepairSteps;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\IndexManager;
use OCA\Polls\Db\V11\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/RemoveObsoleteMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace OCA\Polls\Migration\RepairSteps;

use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/SetLastInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Migration\RepairSteps;

use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCA\Polls\Db\WatchMapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/UpdateHashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Polls\Migration\RepairSteps;

use OCA\Polls\Db\V10\TableManager;
use OCA\Polls\Db\V11\TableManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
Expand Down
Loading
Loading