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

github.com/nextcloud/passman.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbinsky <timo@binsky.org>2021-10-02 17:46:47 +0300
committerbinsky <timo@binsky.org>2021-10-02 17:46:47 +0300
commita99a4529374a4fcfe97abd98c525ad45e81e27c3 (patch)
tree887c3627febf0d3f0a80eedcb46134734898cab5
parent1d75efad36600e267a38825f3c4d2e6b63a2eb3b (diff)
use try catch to not crash systems with untested databasesfix-726-v2
Signed-off-by: binsky <timo@binsky.org>
-rw-r--r--lib/Migration/Version02031335Date20211001122343.php33
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/Migration/Version02031335Date20211001122343.php b/lib/Migration/Version02031335Date20211001122343.php
index 4d738fd5..e5775218 100644
--- a/lib/Migration/Version02031335Date20211001122343.php
+++ b/lib/Migration/Version02031335Date20211001122343.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace OCA\Passman\Migration;
use Closure;
+use Doctrine\DBAL\Exception;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
@@ -68,21 +69,29 @@ class Version02031335Date20211001122343 extends SimpleMigrationStep {
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
if ($this->dataMigrationRequired) {
$updateQuery = $this->connection->getQueryBuilder();
- $updateQuery->update('passman_credentials')
- ->set($this->newColumn, $this->oldColumn)
- ->where($this->newColumn . ' IS NULL')
- ->andWhere($this->oldColumn . ' IS NOT NULL')
- ->executeStatement();
+ try {
+ $updateQuery->update('passman_credentials')
+ ->set($this->newColumn, $this->oldColumn)
+ ->where($this->newColumn . ' IS NULL')
+ ->andWhere($this->oldColumn . ' IS NOT NULL')
+ ->executeStatement();
- /** @var ISchemaWrapper $schema */
- $schema = $schemaClosure();
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
- if ($schema->hasTable('passman_credentials')) {
- $table = $schema->getTable('passman_credentials');
- if ($table->hasColumn($this->oldColumn) && $table->hasColumn($this->newColumn)) {
- $dropColumnStatement = $this->connection->prepare('ALTER TABLE ' . $table->getName() . ' DROP COLUMN ' . $this->oldColumn . ';');
- $dropColumnStatement->execute();
+ if ($schema->hasTable('passman_credentials')) {
+ $table = $schema->getTable('passman_credentials');
+ if ($table->hasColumn($this->oldColumn) && $table->hasColumn($this->newColumn)) {
+ $dropColumnStatement = $this->connection->prepare('ALTER TABLE ' . $table->getName() . ' DROP COLUMN ' . $this->oldColumn . ';');
+ try {
+ $dropColumnStatement->execute();
+ } catch (Exception $e) {
+ echo "Migration was not able to drop the old " . $this->oldColumn . "column" . PHP_EOL;
+ }
+ }
}
+ } catch (\OCP\DB\Exception $e) {
+ echo "Migration was not able to copy data from " . $this->oldColumn . " to " . $this->newColumn . PHP_EOL;
}
}
}