@@ -76,6 +76,13 @@ abstract class Import
76
76
*/
77
77
protected $ showTablesCommand = 'SHOW TABLES ' ;
78
78
79
+ /**
80
+ * Key for default password when using reset passwords
81
+ *
82
+ * @var string
83
+ */
84
+ protected $ defaultPasswordColumn = 'password ' ;
85
+
79
86
/**
80
87
* Checks if provided table has specific selected columns
81
88
*
@@ -161,7 +168,7 @@ public function getSourceRows($table)
161
168
{
162
169
return DB ::connection ($ this ->sourceConnection )
163
170
->table ($ table )
164
- ->select ($ this ->getSelects ())
171
+ ->select ($ this ->getSelects ($ table ))
165
172
->get ();
166
173
}
167
174
@@ -184,11 +191,28 @@ public function clearDestinationTable($table)
184
191
*/
185
192
public function insertInDestination ($ table , $ row )
186
193
{
194
+ if ($ this ->hasPasswordResets ()) {
195
+ $ passwords = $ this ->getPasswordResetValues ($ table );
196
+ foreach ($ passwords as $ column => $ password ) {
197
+ $ row ->{$ column } = $ this ->hashPassword ($ password );
198
+ }
199
+ }
187
200
return DB ::connection ($ this ->destinationConnection )
188
201
->table ($ table )
189
202
->insert ((array ) $ this ->executeManipulation ($ table , $ row ));
190
203
}
191
204
205
+ /**
206
+ * Method that hashes password
207
+ *
208
+ * @param string $password
209
+ * @return string
210
+ */
211
+ public function hashPassword ($ password )
212
+ {
213
+ return bcrypt ($ password );
214
+ }
215
+
192
216
/**
193
217
* Sort the sources tables by ordering last tables and removing the ingored
194
218
*
@@ -201,7 +225,7 @@ public function getSortedSourceTables()
201
225
$ holds = collect ([]);
202
226
foreach ($ tables as $ table ) {
203
227
if ($ this ->hasLastTable ($ table )) {
204
- $ hold ->push ($ table );
228
+ $ holds ->push ($ table );
205
229
} elseif (!$ this ->hasIgnoreTable ($ table )) {
206
230
$ filteredTables ->push ($ table );
207
231
}
@@ -230,21 +254,32 @@ public function hasLastTable($table)
230
254
}
231
255
232
256
/**
233
- * Check if there is a password reset for specified table
257
+ * Check if it has password resets registered
258
+ *
259
+ * @return boolean [description]
260
+ */
261
+ public function hasPasswordResets ()
262
+ {
263
+ return count ($ this ->resetPassword ) > 0 ;
264
+ }
265
+
266
+ /**
267
+ * Get password reset values
234
268
*
235
269
* @return bool
236
270
*/
237
- public function hasPasswordReset ($ table )
271
+ public function getPasswordResetValues ($ table )
238
272
{
273
+ $ columns = [];
239
274
foreach ($ this ->resetPassword as $ key => $ password ) {
240
- $ tableName = $ key ;
241
- $ pos = strpos ( $ tableName , ' : ' ) ;
242
- $ tableName = ($ pos !== false ) ? substr ($ table , 0 , $ pos) : $ tableName ;
275
+ $ pos = strpos ( $ key, ' : ' ) ;
276
+ $ tableName = ( $ pos !== false ) ? substr ( $ key , 0 , $ pos ) : $ key ;
277
+ $ column = ($ pos !== false ) ? substr ($ key , ( $ pos + 1 )) : ' password ' ;
243
278
if ($ table == $ tableName ) {
244
- return true ;
279
+ $ columns [ $ column ] = $ password ;
245
280
}
246
281
}
247
- return false ;
282
+ return $ columns ;
248
283
}
249
284
250
285
/**
0 commit comments