Skip to content

Commit ba7ef1e

Browse files
authored
Merge pull request #4969 from nextcloud/dep/prepare-nc-35
Prepare for Nextcloud 35
2 parents ec65e92 + 57f626b commit ba7ef1e

5 files changed

Lines changed: 73 additions & 10 deletions

File tree

‎appinfo/info.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<name>Polls</name>
55
<summary>A polls app, similar to Doodle/DuD-Poll with the possibility to restrict access.</summary>
66
<description>A polls app, similar to Doodle/DuD-Poll with the possibility to restrict access (members, certain groups/users, hidden and public).</description>
7-
<version>9.2.1</version>
7+
<version>9.3.0-beta.1</version>
88
<licence>agpl</licence>
99
<author>Vinzenz Rosenkranz</author>
1010
<author>René Gieling</author>
@@ -25,7 +25,7 @@
2525
<donation>https://buymeacoffee.com/dartcafe</donation>
2626
<dependencies>
2727
<php min-version="8.1"/>
28-
<nextcloud min-version="31" max-version="34"/>
28+
<nextcloud min-version="31" max-version="35"/>
2929
</dependencies>
3030
<background-jobs>
3131
<job>OCA\Polls\Cron\NotificationCron</job>

‎lib/Db/V11/IndexManager.php‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,44 @@ private function createForeignKeyConstraint(string $parentTableName, string $chi
102102
}
103103
}
104104

105-
$childTable->addForeignKeyConstraint($parentTable, [$constraintColumn], ['id'], ['onDelete' => 'CASCADE']);
105+
// $parentTable is always of the same concrete type as $childTable, since both
106+
// originate from the same schema instance ($this->schema).
107+
/**
108+
* @psalm-suppress UndefinedClass ITable only exists since Nextcloud 35
109+
* @psalm-suppress TypeDoesNotContainType ITable only exists since Nextcloud 35
110+
*/
111+
if ($childTable instanceof \OCP\DB\Schema\ITable) {
112+
/** @var \OCP\DB\Schema\ITable $parentTable */
113+
$this->addForeignKeyConstraintOnITable($childTable, $parentTable, $constraintColumn);
114+
} else {
115+
/**
116+
* @var \Doctrine\DBAL\Schema\Table $parentTable
117+
* @psalm-suppress UnnecessaryVarAnnotation needed for NC35, where $parentTable is still Table|ITable here
118+
*/
119+
$this->addForeignKeyConstraintOnTable($childTable, $parentTable, $constraintColumn);
120+
}
106121
return 'Added ' . $parentTableName . '[' . $constraintColumn . '] <- ' . $childTableName . '[id]';
107122
}
108123

124+
/**
125+
* Dedicated helper so Psalm resolves against OCP\DB\Schema\ITable exclusively.
126+
* Calling addForeignKeyConstraint() directly on a variable typed as
127+
* Doctrine\DBAL\Schema\Table|OCP\DB\Schema\ITable makes Psalm consider a
128+
* hypothetical Table&ITable hybrid (Table is not final), which it then
129+
* rejects against both signatures. A strictly-typed parameter sidesteps that.
130+
*
131+
* @psalm-suppress UndefinedClass ITable only exists since Nextcloud 35
132+
* @psalm-suppress UnusedMethod unreachable on NC < 35, where ITable does not exist
133+
*/
134+
private function addForeignKeyConstraintOnITable(\OCP\DB\Schema\ITable $childTable, \OCP\DB\Schema\ITable $parentTable, string $constraintColumn): void {
135+
$childTable->addForeignKeyConstraint($parentTable, [$constraintColumn], ['id'], ['onDelete' => 'CASCADE']);
136+
}
137+
138+
/** @see self::addForeignKeyConstraintOnITable() */
139+
private function addForeignKeyConstraintOnTable(\Doctrine\DBAL\Schema\Table $childTable, \Doctrine\DBAL\Schema\Table $parentTable, string $constraintColumn): void {
140+
$childTable->addForeignKeyConstraint($parentTable, [$constraintColumn], ['id'], ['onDelete' => 'CASCADE']);
141+
}
142+
109143
/**
110144
* @return string[]
111145
*

‎lib/Db/V11/TableManager.php‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,25 @@ public function createTable(string $tableName): array {
156156
$column = $table->getColumn($columnName);
157157
// Use $column->getType()->getName() instead of the static Type::lookupName():
158158
// since Nextcloud 35, ISchemaWrapper no longer returns a raw
159-
// Doctrine\DBAL\Types\Type but an OCP\DB\Schema wrapper - getName() works on both.
159+
// Doctrine\DBAL\Types\Type but an OCP\DB\Schema\IColumn wrapper - getName() works on both.
160+
// Psalm may complain, that TypeDoesNotContainType IColumn only exists since NC35,
161+
// Suppress psalm messages for now.
160162
if ($column->getType()->getName() !== $columnDefinition['type']) {
161163
$messages[] = 'Migrated type of ' . $table->getName() . '[\'' . $columnName . '\'] from ' . $column->getType()->getName() . ' to ' . $columnDefinition['type'];
162-
$column->setType(Type::getType($columnDefinition['type']));
164+
/**
165+
* @psalm-suppress UndefinedClass IColumn only exists since Nextcloud 35
166+
* @psalm-suppress TypeDoesNotContainType IColumn only exists since Nextcloud 35
167+
*/
168+
if ($column instanceof \OCP\DB\Schema\IColumn) {
169+
$this->setColumnTypeOnIColumn($column, $columnDefinition['type']);
170+
} else {
171+
$this->setColumnTypeOnColumn($column, $columnDefinition['type']);
172+
}
163173
}
164-
$column->setOptions($columnDefinition['options']);
165174

166-
// force change to current options definition
175+
// Column::setOptions() is gone since Nextcloud 35 (public API only allows typed
176+
// setters now). Table::modifyColumn() is unaffected and still takes an options
177+
// array, so it alone is enough to force the column's options to match the schema.
167178
$table->modifyColumn($columnName, $columnDefinition['options']);
168179
} else {
169180
$table->addColumn($columnName, $columnDefinition['type'], $columnDefinition['options']);
@@ -177,6 +188,24 @@ public function createTable(string $tableName): array {
177188
return $messages;
178189
}
179190

191+
/**
192+
* Dedicated helper so Psalm resolves against OCP\DB\Schema\IColumn exclusively.
193+
* Calling setType() directly on a variable typed as
194+
* Doctrine\DBAL\Schema\Column|OCP\DB\Schema\IColumn makes Psalm consider a
195+
* hypothetical Column&IColumn hybrid (Column is not final), which it then
196+
* rejects against both signatures. A strictly-typed parameter sidesteps that.
197+
*
198+
* @psalm-suppress UndefinedClass IColumn only exists since Nextcloud 35
199+
*/
200+
private function setColumnTypeOnIColumn(\OCP\DB\Schema\IColumn $column, string $type): void {
201+
$column->setType($type);
202+
}
203+
204+
/** @see self::setColumnTypeOnIColumn() */
205+
private function setColumnTypeOnColumn(\Doctrine\DBAL\Schema\Column $column, string $type): void {
206+
$column->setType(Type::getType($type));
207+
}
208+
180209
/**
181210
* Create all tables defined in TableSchema::TABLES
182211
*

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polls",
3-
"version": "9.2.1",
3+
"version": "9.3.0-beta.1",
44
"private": true,
55
"description": "Polls app for nextcloud",
66
"homepage": "https://github.com/nextcloud/polls#readme",

0 commit comments

Comments
 (0)