1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace OCA\FaceRecognition\Migration; |
6
|
|
|
|
7
|
|
|
use OCP\DB\ISchemaWrapper; |
8
|
|
|
use OCP\IDBConnection; |
9
|
|
|
use OCP\Migration\SimpleMigrationStep; |
10
|
|
|
use OCP\Migration\IOutput; |
11
|
|
|
|
12
|
|
|
class Version000509Date20191204003814 extends SimpleMigrationStep { |
13
|
|
|
|
14
|
|
|
/** @var IDBConnection */ |
15
|
|
|
protected $connection; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param IDBConnection $connection |
19
|
|
|
*/ |
20
|
|
|
public function __construct(IDBConnection $connection) { |
21
|
|
|
$this->connection = $connection; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param IOutput $output |
26
|
|
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
27
|
|
|
* @param array $options |
28
|
|
|
*/ |
29
|
|
|
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
30
|
|
|
|
31
|
|
|
/** @var ISchemaWrapper $schema */ |
32
|
|
|
$schema = $schemaClosure(); |
33
|
|
|
|
34
|
|
|
if (!$schema->hasTable('face_recognition_persons')) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/* |
39
|
|
|
* Migrate 'face_recognition_persons' to 'facerecog_persons' |
40
|
|
|
*/ |
41
|
|
|
$query = $this->connection->getQueryBuilder(); |
42
|
|
|
$query->select('*') |
43
|
|
|
->from('face_recognition_persons'); |
44
|
|
|
|
45
|
|
|
$insert = $this->connection->getQueryBuilder(); |
46
|
|
|
$insert->insert('facerecog_persons') |
47
|
|
|
->values([ |
48
|
|
|
'id' => '?', |
49
|
|
|
'user' => '?', |
50
|
|
|
'name' => '?', |
51
|
|
|
'is_valid' => '?', |
52
|
|
|
'last_generation_time' => '?', |
53
|
|
|
'linked_user' => '?' |
54
|
|
|
]); |
55
|
|
|
|
56
|
|
|
$result = $query->execute(); |
57
|
|
|
while ($row = $result->fetch()) { |
58
|
|
|
$insert->setParameters([ |
59
|
|
|
$row['id'], |
60
|
|
|
$row['user'], |
61
|
|
|
$row['name'], |
62
|
|
|
$row['is_valid'], |
63
|
|
|
$row['last_generation_time'], |
64
|
|
|
$row['linked_user'] |
65
|
|
|
])->execute(); |
66
|
|
|
} |
67
|
|
|
$result->closeCursor(); |
68
|
|
|
|
69
|
|
|
/* |
70
|
|
|
* Migrate 'face_recognition_images' to 'facerecog_images' |
71
|
|
|
*/ |
72
|
|
|
$query = $this->connection->getQueryBuilder(); |
73
|
|
|
$query->select('*') |
74
|
|
|
->from('face_recognition_images'); |
75
|
|
|
|
76
|
|
|
$insert = $this->connection->getQueryBuilder(); |
77
|
|
|
$insert->insert('facerecog_images') |
78
|
|
|
->values([ |
79
|
|
|
'id' => '?', |
80
|
|
|
'user' => '?', |
81
|
|
|
'file' => '?', |
82
|
|
|
'model' => '?', |
83
|
|
|
'is_processed' => '?', |
84
|
|
|
'error' => '?', |
85
|
|
|
'last_processed_time' => '?', |
86
|
|
|
'processing_duration' => '?' |
87
|
|
|
]); |
88
|
|
|
|
89
|
|
|
$result = $query->execute(); |
90
|
|
|
while ($row = $result->fetch()) { |
91
|
|
|
$insert->setParameters([ |
92
|
|
|
$row['id'], |
93
|
|
|
$row['user'], |
94
|
|
|
$row['file'], |
95
|
|
|
$row['model'], |
96
|
|
|
$row['is_processed'], |
97
|
|
|
$row['error'], |
98
|
|
|
$row['last_processed_time'], |
99
|
|
|
$row['processing_duration'] |
100
|
|
|
])->execute(); |
101
|
|
|
} |
102
|
|
|
$result->closeCursor(); |
103
|
|
|
|
104
|
|
|
/* |
105
|
|
|
* Migrate 'face_recognition_faces' to 'facerecog_faces' |
106
|
|
|
*/ |
107
|
|
|
$query = $this->connection->getQueryBuilder(); |
108
|
|
|
$query->select('*') |
109
|
|
|
->from('face_recognition_faces'); |
110
|
|
|
|
111
|
|
|
$insert = $this->connection->getQueryBuilder(); |
112
|
|
|
$insert->insert('facerecog_faces') |
113
|
|
|
->values([ |
114
|
|
|
'id' => '?', |
115
|
|
|
'image' => '?', |
116
|
|
|
'person' => '?', |
117
|
|
|
'left' => '?', |
118
|
|
|
'right' => '?', |
119
|
|
|
'top' => '?', |
120
|
|
|
'bottom' => '?', |
121
|
|
|
'descriptor' => '?', |
122
|
|
|
'creation_time' => '?', |
123
|
|
|
'confidence' => '?', |
124
|
|
|
'landmarks' => '?' |
125
|
|
|
]); |
126
|
|
|
|
127
|
|
|
$result = $query->execute(); |
128
|
|
|
while ($row = $result->fetch()) { |
129
|
|
|
$insert->setParameters([ |
130
|
|
|
$row['id'], |
131
|
|
|
$row['image'], |
132
|
|
|
$row['person'], |
133
|
|
|
$row['left'], |
134
|
|
|
$row['right'], |
135
|
|
|
$row['top'], |
136
|
|
|
$row['bottom'], |
137
|
|
|
$row['descriptor'], |
138
|
|
|
$row['creation_time'], |
139
|
|
|
$row['confidence'], |
140
|
|
|
$row['landmarks'] |
141
|
|
|
])->execute(); |
142
|
|
|
} |
143
|
|
|
$result->closeCursor(); |
144
|
|
|
|
145
|
|
|
/* |
146
|
|
|
* Migrate 'face_recognition_face_models' to 'facerecog_models' |
147
|
|
|
*/ |
148
|
|
|
$query = $this->connection->getQueryBuilder(); |
149
|
|
|
$query->select('*') |
150
|
|
|
->from('face_recognition_face_models'); |
151
|
|
|
|
152
|
|
|
$insert = $this->connection->getQueryBuilder(); |
153
|
|
|
$insert->insert('facerecog_models') |
154
|
|
|
->values([ |
155
|
|
|
'id' => '?', |
156
|
|
|
'name' => '?', |
157
|
|
|
'description' => '?' |
158
|
|
|
]); |
159
|
|
|
|
160
|
|
|
$result = $query->execute(); |
161
|
|
|
while ($row = $result->fetch()) { |
162
|
|
|
$insert->setParameters([ |
163
|
|
|
$row['id'], |
164
|
|
|
$row['name'], |
165
|
|
|
$row['description'] |
166
|
|
|
])->execute(); |
167
|
|
|
} |
168
|
|
|
$result->closeCursor(); |
169
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param IOutput $output |
174
|
|
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
175
|
|
|
* @param array $options |
176
|
|
|
* @return null|ISchemaWrapper |
177
|
|
|
*/ |
178
|
|
|
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
179
|
|
|
/** @var ISchemaWrapper $schema */ |
180
|
|
|
$schema = $schemaClosure(); |
181
|
|
|
|
182
|
|
|
if ($schema->hasTable('face_recognition_persons')) { |
183
|
|
|
$schema->dropTable('face_recognition_persons'); |
184
|
|
|
} |
185
|
|
|
if ($schema->hasTable('face_recognition_images')) { |
186
|
|
|
$schema->dropTable('face_recognition_images'); |
187
|
|
|
} |
188
|
|
|
if ($schema->hasTable('face_recognition_faces')) { |
189
|
|
|
$schema->dropTable('face_recognition_faces'); |
190
|
|
|
} |
191
|
|
|
if ($schema->hasTable('face_recognition_face_models')) { |
192
|
|
|
$schema->dropTable('face_recognition_face_models'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $schema; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
} |
199
|
|
|
|