Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Version010309Date20210628143307 | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| preSchemaChange | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| changeSchema | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| postSchemaChange | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace OCA\Cospend\Migration; |
| 6 | |
| 7 | use Closure; |
| 8 | use OCP\DB\ISchemaWrapper; |
| 9 | use OCP\Migration\SimpleMigrationStep; |
| 10 | use OCP\Migration\IOutput; |
| 11 | use OCP\DB\QueryBuilder\IQueryBuilder; |
| 12 | use OCP\IDBConnection; |
| 13 | use OCP\IL10N; |
| 14 | |
| 15 | /** |
| 16 | * Auto-generated migration step: Please modify to your needs! |
| 17 | */ |
| 18 | class Version010309Date20210628143307 extends SimpleMigrationStep { |
| 19 | |
| 20 | /** @var IDBConnection */ |
| 21 | private $connection; |
| 22 | private $trans; |
| 23 | |
| 24 | /** |
| 25 | * @param IDBConnection $connection |
| 26 | */ |
| 27 | public function __construct(IDBConnection $connection, IL10N $l10n) { |
| 28 | $this->connection = $connection; |
| 29 | $this->trans = $l10n; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @param IOutput $output |
| 34 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 35 | * @param array $options |
| 36 | */ |
| 37 | public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param IOutput $output |
| 42 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 43 | * @param array $options |
| 44 | * @return null|ISchemaWrapper |
| 45 | */ |
| 46 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
| 47 | /** @var ISchemaWrapper $schema */ |
| 48 | $schema = $schemaClosure(); |
| 49 | return $schema; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param IOutput $output |
| 54 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 55 | * @param array $options |
| 56 | */ |
| 57 | public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
| 58 | $qb = $this->connection->getQueryBuilder(); |
| 59 | |
| 60 | // fix potentially incorrect category ids < 0 and != -11 |
| 61 | // => set them to -11 (reimbursement) |
| 62 | $qb->update('cospend_bills'); |
| 63 | $qb->set('categoryid', $qb->createNamedParameter(-11, IQueryBuilder::PARAM_INT)); |
| 64 | $qb->where( |
| 65 | $qb->expr()->lt('categoryid', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) |
| 66 | ); |
| 67 | $qb->andWhere( |
| 68 | $qb->expr()->neq('categoryid', $qb->createNamedParameter(-11, IQueryBuilder::PARAM_INT)) |
| 69 | ); |
| 70 | $qb->executeStatement(); |
| 71 | $qb->resetQueryParts(); |
| 72 | } |
| 73 | } |