Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Version000403Date20200231152118 | |
0.00% |
0 / 45 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
preSchemaChange | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
changeSchema | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
postSchemaChange | |
0.00% |
0 / 29 |
|
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 | |
14 | /** |
15 | * Auto-generated migration step: Please modify to your needs! |
16 | */ |
17 | class Version000403Date20200231152118 extends SimpleMigrationStep { |
18 | |
19 | /** @var IDBConnection */ |
20 | private $connection; |
21 | |
22 | /** |
23 | * @param IDBConnection $connection |
24 | */ |
25 | public function __construct(IDBConnection $connection) { |
26 | $this->connection = $connection; |
27 | } |
28 | |
29 | /** |
30 | * @param IOutput $output |
31 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
32 | * @param array $options |
33 | */ |
34 | public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
35 | } |
36 | |
37 | /** |
38 | * @param IOutput $output |
39 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
40 | * @param array $options |
41 | * @return null|ISchemaWrapper |
42 | */ |
43 | public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
44 | /** @var ISchemaWrapper $schema */ |
45 | $schema = $schemaClosure(); |
46 | $table = $schema->getTable('cospend_projects'); |
47 | $table->addColumn('guestaccesslevel', 'integer', [ |
48 | 'notnull' => true, |
49 | 'length' => 4, |
50 | 'default' => 2 |
51 | ]); |
52 | $table = $schema->getTable('cospend_shares'); |
53 | $table->addColumn('accesslevel', 'integer', [ |
54 | 'notnull' => true, |
55 | 'length' => 4, |
56 | 'default' => 2 |
57 | ]); |
58 | return $schema; |
59 | } |
60 | |
61 | /** |
62 | * @param IOutput $output |
63 | * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
64 | * @param array $options |
65 | */ |
66 | public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
67 | $qb = $this->connection->getQueryBuilder(); |
68 | |
69 | // permissions were c e d => v p m a for viewer participant maintener admin |
70 | // user share permissions |
71 | $qb->update('cospend_shares') |
72 | ->set('accesslevel', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT)) |
73 | ->where( |
74 | $qb->expr()->neq('permissions', $qb->createNamedParameter('', IQueryBuilder::PARAM_STR)) |
75 | ); |
76 | $qb->executeStatement(); |
77 | $qb = $qb->resetQueryParts(); |
78 | |
79 | $qb->update('cospend_shares') |
80 | ->set('accesslevel', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) |
81 | ->where( |
82 | $qb->expr()->eq('permissions', $qb->createNamedParameter('', IQueryBuilder::PARAM_STR)) |
83 | ); |
84 | $qb->executeStatement(); |
85 | $qb = $qb->resetQueryParts(); |
86 | |
87 | // guest permissions |
88 | $qb->update('cospend_projects') |
89 | ->set('guestaccesslevel', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT)) |
90 | ->where( |
91 | $qb->expr()->neq('guestpermissions', $qb->createNamedParameter('', IQueryBuilder::PARAM_STR)) |
92 | ); |
93 | $qb->executeStatement(); |
94 | $qb = $qb->resetQueryParts(); |
95 | |
96 | $qb->update('cospend_projects') |
97 | ->set('guestaccesslevel', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) |
98 | ->where( |
99 | $qb->expr()->eq('guestpermissions', $qb->createNamedParameter('', IQueryBuilder::PARAM_STR)) |
100 | ); |
101 | $qb->executeStatement(); |
102 | $qb = $qb->resetQueryParts(); |
103 | } |
104 | } |