diff options
author | dartcafe <github@dartcafe.de> | 2018-12-22 13:33:19 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2018-12-22 13:33:19 +0300 |
commit | 4927dc22c0fcb2407ac052f899f91bee0a189899 (patch) | |
tree | ff0646cb9c0e994baa36528e42a2e50221d387d9 /lib/Migration | |
parent | 501510635a755348adc6f6f9c1f8e3fce2863632 (diff) |
Fix broken migration after orphaned votes
Diffstat (limited to 'lib/Migration')
-rw-r--r-- | lib/Migration/Version0009Date20181125051900.php | 83 | ||||
-rw-r--r-- | lib/Migration/Version0009Date20181125061900.php | 15 |
2 files changed, 89 insertions, 9 deletions
diff --git a/lib/Migration/Version0009Date20181125051900.php b/lib/Migration/Version0009Date20181125051900.php new file mode 100644 index 00000000..ffac48ed --- /dev/null +++ b/lib/Migration/Version0009Date20181125051900.php @@ -0,0 +1,83 @@ +<?php +/** + * @copyright Copyright (c) 2017 René Gieling <github@dartcafe.de> + * + * @author René Gieling <github@dartcafe.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Polls\Migration; + +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +/** + * Installation class for the polls app. + * Initial db creation + */ +class Version0009Date20181125051900 extends SimpleMigrationStep { + + /** @var IDBConnection */ + protected $connection; + + /** @var IConfig */ + protected $config; + + /** + * @param IDBConnection $connection + * @param IConfig $config + */ + public function __construct(IDBConnection $connection, IConfig $config) { + $this->connection = $connection; + $this->config = $config; + } + + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + * @since 13.0.0 + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if ($schema->hasTable('polls_particip') && + $schema->hasTable('polls_particip_text') && + $schema->hasTable('polls_votes')) { + + $schema->dropTable('polls_votes'); + } + + if ($schema->hasTable('polls_dts') && + $schema->hasTable('polls_txts') && + $schema->hasTable('polls_options')) { + + $schema->dropTable('polls_options'); + } + return $schema; + } +} diff --git a/lib/Migration/Version0009Date20181125061900.php b/lib/Migration/Version0009Date20181125061900.php index bcd282e7..967e71e2 100644 --- a/lib/Migration/Version0009Date20181125061900.php +++ b/lib/Migration/Version0009Date20181125061900.php @@ -301,10 +301,8 @@ class Version0009Date20181125061900 extends SimpleMigrationStep { ->values([ 'poll_id' => $insert->createParameter('poll_id'), 'user_id' => $insert->createParameter('user_id'), - // 'vote_date' => $insert->createParameter('vote_date'), 'vote_option_id' => $insert->createParameter('vote_option_id'), 'vote_option_text' => $insert->createParameter('vote_option_text'), - // 'vote_type' => $insert->createParameter('vote_type'), 'vote_answer' => $insert->createParameter('vote_answer'), ]); $query = $this->connection->getQueryBuilder(); @@ -315,10 +313,8 @@ class Version0009Date20181125061900 extends SimpleMigrationStep { $insert ->setParameter('poll_id', $row['poll_id']) ->setParameter('user_id', $row['user_id']) - // ->setParameter('vote_date', $row['dt']) ->setParameter('vote_option_id', $this->findOptionId($row['poll_id'], $row['dt'])) ->setParameter('vote_option_text', date($row['dt'])) - // ->setParameter('vote_type', $row['type']) ->setParameter('vote_answer', $this->translateVoteTypeToAnswer($row['type'])); $insert->execute(); } @@ -334,10 +330,8 @@ class Version0009Date20181125061900 extends SimpleMigrationStep { ->values([ 'poll_id' => $insert->createParameter('poll_id'), 'user_id' => $insert->createParameter('user_id'), - // 'vote_text' => $insert->createParameter('vote_text'), 'vote_option_id' => $insert->createParameter('vote_option_id'), 'vote_option_text' => $insert->createParameter('vote_option_text'), - // 'vote_type' => $insert->createParameter('vote_type'), 'vote_answer' => $insert->createParameter('vote_answer'), ]); $query = $this->connection->getQueryBuilder(); @@ -348,10 +342,8 @@ class Version0009Date20181125061900 extends SimpleMigrationStep { $insert ->setParameter('poll_id', $row['poll_id']) ->setParameter('user_id', $row['user_id']) - // ->setParameter('vote_text', $row['text']) ->setParameter('vote_option_id', $this->findOptionId($row['poll_id'], preg_replace("/_\d*$/", "$1", $row['text']))) ->setParameter('vote_option_text', preg_replace("/_\d*$/", "$1", $row['text'])) - // ->setParameter('vote_type', $row['type']) ->setParameter('vote_answer', $this->translateVoteTypeToAnswer($row['type'])); $insert->execute(); } @@ -373,8 +365,13 @@ class Version0009Date20181125061900 extends SimpleMigrationStep { $resultFind = $queryFind->execute(); $row = $resultFind->fetch(); - return $row['id']; + if ($row['id'] === null) { + // seems, we have an orphaned vote, return 0 as vote_option_id + return 0; + } else { + return $row['id']; + } } protected function translateVoteTypeToAnswer($voteType) { |