@@ -31,78 +31,78 @@ |
||
| 31 | 31 | |
| 32 | 32 | class CopyEntriesFromOldTable implements IRepairStep { |
| 33 | 33 | |
| 34 | - /** @var IDBConnection */ |
|
| 35 | - protected $connection; |
|
| 34 | + /** @var IDBConnection */ |
|
| 35 | + protected $connection; |
|
| 36 | 36 | |
| 37 | - /** @var IConfig */ |
|
| 38 | - protected $config; |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + protected $config; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param IDBConnection $connection |
|
| 42 | - * @param IConfig $config |
|
| 43 | - */ |
|
| 44 | - public function __construct(IDBConnection $connection, IConfig $config) { |
|
| 45 | - $this->connection = $connection; |
|
| 46 | - $this->config = $config; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * @param IDBConnection $connection |
|
| 42 | + * @param IConfig $config |
|
| 43 | + */ |
|
| 44 | + public function __construct(IDBConnection $connection, IConfig $config) { |
|
| 45 | + $this->connection = $connection; |
|
| 46 | + $this->config = $config; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Returns the step's name |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - * @since 9.1.0 |
|
| 54 | - */ |
|
| 55 | - public function getName() { |
|
| 56 | - return 'Copy twofactor backup codes from legacy table'; |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * Returns the step's name |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + * @since 9.1.0 |
|
| 54 | + */ |
|
| 55 | + public function getName() { |
|
| 56 | + return 'Copy twofactor backup codes from legacy table'; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Run repair step. |
|
| 61 | - * Must throw exception on error. |
|
| 62 | - * |
|
| 63 | - * @since 9.1.0 |
|
| 64 | - * @param IOutput $output |
|
| 65 | - * @throws \Exception in case of failure |
|
| 66 | - */ |
|
| 67 | - public function run(IOutput $output) { |
|
| 68 | - $version = $this->config->getAppValue('twofactor_backupcodes', 'installed_version', '0.0.0'); |
|
| 69 | - if (version_compare($version, '1.1.1', '>=')) { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 59 | + /** |
|
| 60 | + * Run repair step. |
|
| 61 | + * Must throw exception on error. |
|
| 62 | + * |
|
| 63 | + * @since 9.1.0 |
|
| 64 | + * @param IOutput $output |
|
| 65 | + * @throws \Exception in case of failure |
|
| 66 | + */ |
|
| 67 | + public function run(IOutput $output) { |
|
| 68 | + $version = $this->config->getAppValue('twofactor_backupcodes', 'installed_version', '0.0.0'); |
|
| 69 | + if (version_compare($version, '1.1.1', '>=')) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if (!$this->connection->tableExists('twofactor_backup_codes')) { |
|
| 74 | - // Legacy table does not exist |
|
| 75 | - return; |
|
| 76 | - } |
|
| 73 | + if (!$this->connection->tableExists('twofactor_backup_codes')) { |
|
| 74 | + // Legacy table does not exist |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - $insert = $this->connection->getQueryBuilder(); |
|
| 79 | - $insert->insert('twofactor_backupcodes') |
|
| 80 | - ->values([ |
|
| 81 | - // Inserting with id might fail: 'id' => $insert->createParameter('id'), |
|
| 82 | - 'user_id' => $insert->createParameter('user_id'), |
|
| 83 | - 'code' => $insert->createParameter('code'), |
|
| 84 | - 'used' => $insert->createParameter('used'), |
|
| 85 | - ]); |
|
| 78 | + $insert = $this->connection->getQueryBuilder(); |
|
| 79 | + $insert->insert('twofactor_backupcodes') |
|
| 80 | + ->values([ |
|
| 81 | + // Inserting with id might fail: 'id' => $insert->createParameter('id'), |
|
| 82 | + 'user_id' => $insert->createParameter('user_id'), |
|
| 83 | + 'code' => $insert->createParameter('code'), |
|
| 84 | + 'used' => $insert->createParameter('used'), |
|
| 85 | + ]); |
|
| 86 | 86 | |
| 87 | - $query = $this->connection->getQueryBuilder(); |
|
| 88 | - $query->select('*') |
|
| 89 | - ->from('twofactor_backup_codes') |
|
| 90 | - ->orderBy('id', 'ASC'); |
|
| 91 | - $result = $query->execute(); |
|
| 87 | + $query = $this->connection->getQueryBuilder(); |
|
| 88 | + $query->select('*') |
|
| 89 | + ->from('twofactor_backup_codes') |
|
| 90 | + ->orderBy('id', 'ASC'); |
|
| 91 | + $result = $query->execute(); |
|
| 92 | 92 | |
| 93 | - $output->startProgress(); |
|
| 94 | - while ($row = $result->fetch()) { |
|
| 95 | - $output->advance(); |
|
| 93 | + $output->startProgress(); |
|
| 94 | + while ($row = $result->fetch()) { |
|
| 95 | + $output->advance(); |
|
| 96 | 96 | |
| 97 | - $insert |
|
| 98 | - // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT) |
|
| 99 | - ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR) |
|
| 100 | - ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR) |
|
| 101 | - ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT) |
|
| 102 | - ->execute(); |
|
| 103 | - } |
|
| 104 | - $output->finishProgress(); |
|
| 97 | + $insert |
|
| 98 | + // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT) |
|
| 99 | + ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR) |
|
| 100 | + ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR) |
|
| 101 | + ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT) |
|
| 102 | + ->execute(); |
|
| 103 | + } |
|
| 104 | + $output->finishProgress(); |
|
| 105 | 105 | |
| 106 | - $this->connection->dropTable('twofactor_backup_codes'); |
|
| 107 | - } |
|
| 106 | + $this->connection->dropTable('twofactor_backup_codes'); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -28,38 +28,38 @@ |
||
| 28 | 28 | |
| 29 | 29 | class BackupCodeMapper extends Mapper { |
| 30 | 30 | |
| 31 | - public function __construct(IDBConnection $db) { |
|
| 32 | - parent::__construct($db, 'twofactor_backupcodes'); |
|
| 33 | - } |
|
| 31 | + public function __construct(IDBConnection $db) { |
|
| 32 | + parent::__construct($db, 'twofactor_backupcodes'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param IUser $user |
|
| 37 | - * @return BackupCode[] |
|
| 38 | - */ |
|
| 39 | - public function getBackupCodes(IUser $user) { |
|
| 40 | - /* @var IQueryBuilder $qb */ |
|
| 41 | - $qb = $this->db->getQueryBuilder(); |
|
| 35 | + /** |
|
| 36 | + * @param IUser $user |
|
| 37 | + * @return BackupCode[] |
|
| 38 | + */ |
|
| 39 | + public function getBackupCodes(IUser $user) { |
|
| 40 | + /* @var IQueryBuilder $qb */ |
|
| 41 | + $qb = $this->db->getQueryBuilder(); |
|
| 42 | 42 | |
| 43 | - $qb->select('id', 'user_id', 'code', 'used') |
|
| 44 | - ->from('twofactor_backupcodes') |
|
| 45 | - ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
| 46 | - $result = $qb->execute(); |
|
| 43 | + $qb->select('id', 'user_id', 'code', 'used') |
|
| 44 | + ->from('twofactor_backupcodes') |
|
| 45 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
| 46 | + $result = $qb->execute(); |
|
| 47 | 47 | |
| 48 | - $rows = $result->fetchAll(); |
|
| 49 | - $result->closeCursor(); |
|
| 48 | + $rows = $result->fetchAll(); |
|
| 49 | + $result->closeCursor(); |
|
| 50 | 50 | |
| 51 | - return array_map(function ($row) { |
|
| 52 | - return BackupCode::fromRow($row); |
|
| 53 | - }, $rows); |
|
| 54 | - } |
|
| 51 | + return array_map(function ($row) { |
|
| 52 | + return BackupCode::fromRow($row); |
|
| 53 | + }, $rows); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function deleteCodes(IUser $user) { |
|
| 57 | - /* @var IQueryBuilder $qb */ |
|
| 58 | - $qb = $this->db->getQueryBuilder(); |
|
| 56 | + public function deleteCodes(IUser $user) { |
|
| 57 | + /* @var IQueryBuilder $qb */ |
|
| 58 | + $qb = $this->db->getQueryBuilder(); |
|
| 59 | 59 | |
| 60 | - $qb->delete('twofactor_backupcodes') |
|
| 61 | - ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
| 62 | - $qb->execute(); |
|
| 63 | - } |
|
| 60 | + $qb->delete('twofactor_backupcodes') |
|
| 61 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
| 62 | + $qb->execute(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |