|
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
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
32
|
|
|
|
|
33
|
|
|
/** @var ISchemaWrapper $schema */ |
|
34
|
|
|
$schema = $schemaClosure(); |
|
35
|
|
|
|
|
36
|
|
|
if (!$schema->hasTable('face_recognition_persons')) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/* |
|
41
|
|
|
* Migrate 'face_recognition_persons' to 'facerecog_persons' |
|
42
|
|
|
*/ |
|
43
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
44
|
|
|
$query->select('*') |
|
45
|
|
|
->from('face_recognition_persons'); |
|
46
|
|
|
|
|
47
|
|
|
$insert = $this->connection->getQueryBuilder(); |
|
48
|
|
|
$insert->insert('facerecog_persons') |
|
49
|
|
|
->values([ |
|
50
|
|
|
'id' => '?', |
|
51
|
|
|
'user' => '?', |
|
52
|
|
|
'name' => '?', |
|
53
|
|
|
'is_valid' => '?', |
|
54
|
|
|
'last_generation_time' => '?', |
|
55
|
|
|
'linked_user' => '?' |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
$result = $query->execute(); |
|
|
|
|
|
|
59
|
|
|
while ($row = $result->fetch()) { |
|
60
|
|
|
$insert->setParameters([ |
|
|
|
|
|
|
61
|
|
|
$row['id'], |
|
62
|
|
|
$row['user'], |
|
63
|
|
|
$row['name'], |
|
64
|
|
|
$row['is_valid'], |
|
65
|
|
|
$row['last_generation_time'], |
|
66
|
|
|
$row['linked_user'] |
|
67
|
|
|
])->execute(); |
|
68
|
|
|
} |
|
69
|
|
|
$result->closeCursor(); |
|
70
|
|
|
|
|
71
|
|
|
/* |
|
72
|
|
|
* Migrate 'face_recognition_images' to 'facerecog_images' |
|
73
|
|
|
*/ |
|
74
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
75
|
|
|
$query->select('*') |
|
76
|
|
|
->from('face_recognition_images'); |
|
77
|
|
|
|
|
78
|
|
|
$insert = $this->connection->getQueryBuilder(); |
|
79
|
|
|
$insert->insert('facerecog_images') |
|
80
|
|
|
->values([ |
|
81
|
|
|
'id' => '?', |
|
82
|
|
|
'user' => '?', |
|
83
|
|
|
'file' => '?', |
|
84
|
|
|
'model' => '?', |
|
85
|
|
|
'is_processed' => '?', |
|
86
|
|
|
'error' => '?', |
|
87
|
|
|
'last_processed_time' => '?', |
|
88
|
|
|
'processing_duration' => '?' |
|
89
|
|
|
]); |
|
90
|
|
|
|
|
91
|
|
|
$result = $query->execute(); |
|
|
|
|
|
|
92
|
|
|
while ($row = $result->fetch()) { |
|
93
|
|
|
$insert->setParameters([ |
|
|
|
|
|
|
94
|
|
|
$row['id'], |
|
95
|
|
|
$row['user'], |
|
96
|
|
|
$row['file'], |
|
97
|
|
|
$row['model'], |
|
98
|
|
|
$row['is_processed'], |
|
99
|
|
|
$row['error'], |
|
100
|
|
|
$row['last_processed_time'], |
|
101
|
|
|
$row['processing_duration'] |
|
102
|
|
|
])->execute(); |
|
103
|
|
|
} |
|
104
|
|
|
$result->closeCursor(); |
|
105
|
|
|
|
|
106
|
|
|
/* |
|
107
|
|
|
* Migrate 'face_recognition_faces' to 'facerecog_faces' |
|
108
|
|
|
*/ |
|
109
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
110
|
|
|
$query->select('*') |
|
111
|
|
|
->from('face_recognition_faces'); |
|
112
|
|
|
|
|
113
|
|
|
$insert = $this->connection->getQueryBuilder(); |
|
114
|
|
|
$insert->insert('facerecog_faces') |
|
115
|
|
|
->values([ |
|
116
|
|
|
'id' => '?', |
|
117
|
|
|
'image' => '?', |
|
118
|
|
|
'person' => '?', |
|
119
|
|
|
'left' => '?', |
|
120
|
|
|
'right' => '?', |
|
121
|
|
|
'top' => '?', |
|
122
|
|
|
'bottom' => '?', |
|
123
|
|
|
'descriptor' => '?', |
|
124
|
|
|
'creation_time' => '?', |
|
125
|
|
|
'confidence' => '?', |
|
126
|
|
|
'landmarks' => '?' |
|
127
|
|
|
]); |
|
128
|
|
|
|
|
129
|
|
|
$result = $query->execute(); |
|
|
|
|
|
|
130
|
|
|
while ($row = $result->fetch()) { |
|
131
|
|
|
$insert->setParameters([ |
|
|
|
|
|
|
132
|
|
|
$row['id'], |
|
133
|
|
|
$row['image'], |
|
134
|
|
|
$row['person'], |
|
135
|
|
|
$row['left'], |
|
136
|
|
|
$row['right'], |
|
137
|
|
|
$row['top'], |
|
138
|
|
|
$row['bottom'], |
|
139
|
|
|
$row['descriptor'], |
|
140
|
|
|
$row['creation_time'], |
|
141
|
|
|
$row['confidence'], |
|
142
|
|
|
$row['landmarks'] |
|
143
|
|
|
])->execute(); |
|
144
|
|
|
} |
|
145
|
|
|
$result->closeCursor(); |
|
146
|
|
|
|
|
147
|
|
|
/* |
|
148
|
|
|
* Migrate 'face_recognition_face_models' to 'facerecog_models' |
|
149
|
|
|
*/ |
|
150
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
151
|
|
|
$query->select('*') |
|
152
|
|
|
->from('face_recognition_face_models'); |
|
153
|
|
|
|
|
154
|
|
|
$insert = $this->connection->getQueryBuilder(); |
|
155
|
|
|
$insert->insert('facerecog_models') |
|
156
|
|
|
->values([ |
|
157
|
|
|
'id' => '?', |
|
158
|
|
|
'name' => '?', |
|
159
|
|
|
'description' => '?' |
|
160
|
|
|
]); |
|
161
|
|
|
|
|
162
|
|
|
$result = $query->execute(); |
|
|
|
|
|
|
163
|
|
|
while ($row = $result->fetch()) { |
|
164
|
|
|
$insert->setParameters([ |
|
|
|
|
|
|
165
|
|
|
$row['id'], |
|
166
|
|
|
$row['name'], |
|
167
|
|
|
$row['description'] |
|
168
|
|
|
])->execute(); |
|
169
|
|
|
} |
|
170
|
|
|
$result->closeCursor(); |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @param IOutput $output |
|
176
|
|
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
177
|
|
|
* @param array $options |
|
178
|
|
|
* @return null|ISchemaWrapper |
|
179
|
|
|
*/ |
|
180
|
|
|
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
181
|
|
|
/** @var ISchemaWrapper $schema */ |
|
182
|
|
|
$schema = $schemaClosure(); |
|
183
|
|
|
|
|
184
|
|
|
if ($schema->hasTable('face_recognition_persons')) { |
|
185
|
|
|
$schema->dropTable('face_recognition_persons'); |
|
186
|
|
|
} |
|
187
|
|
|
if ($schema->hasTable('face_recognition_images')) { |
|
188
|
|
|
$schema->dropTable('face_recognition_images'); |
|
189
|
|
|
} |
|
190
|
|
|
if ($schema->hasTable('face_recognition_faces')) { |
|
191
|
|
|
$schema->dropTable('face_recognition_faces'); |
|
192
|
|
|
} |
|
193
|
|
|
if ($schema->hasTable('face_recognition_face_models')) { |
|
194
|
|
|
$schema->dropTable('face_recognition_face_models'); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
return $schema; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.