Skip to content

Commit 87c2e12

Browse files
author
Nicolas Boisvert
committed
Fixes little mistakes on writing
1 parent dc24d02 commit 87c2e12

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/Import.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ abstract class Import
7676
*/
7777
protected $showTablesCommand = 'SHOW TABLES';
7878

79+
/**
80+
* Key for default password when using reset passwords
81+
*
82+
* @var string
83+
*/
84+
protected $defaultPasswordColumn = 'password';
85+
7986
/**
8087
* Checks if provided table has specific selected columns
8188
*
@@ -161,7 +168,7 @@ public function getSourceRows($table)
161168
{
162169
return DB::connection($this->sourceConnection)
163170
->table($table)
164-
->select($this->getSelects())
171+
->select($this->getSelects($table))
165172
->get();
166173
}
167174

@@ -184,11 +191,28 @@ public function clearDestinationTable($table)
184191
*/
185192
public function insertInDestination($table, $row)
186193
{
194+
if ($this->hasPasswordResets()) {
195+
$passwords = $this->getPasswordResetValues($table);
196+
foreach ($passwords as $column => $password) {
197+
$row->{$column} = $this->hashPassword($password);
198+
}
199+
}
187200
return DB::connection($this->destinationConnection)
188201
->table($table)
189202
->insert((array) $this->executeManipulation($table, $row));
190203
}
191204

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+
192216
/**
193217
* Sort the sources tables by ordering last tables and removing the ingored
194218
*
@@ -201,7 +225,7 @@ public function getSortedSourceTables()
201225
$holds = collect([]);
202226
foreach ($tables as $table) {
203227
if ($this->hasLastTable($table)) {
204-
$hold->push($table);
228+
$holds->push($table);
205229
} elseif (!$this->hasIgnoreTable($table)) {
206230
$filteredTables->push($table);
207231
}
@@ -230,21 +254,32 @@ public function hasLastTable($table)
230254
}
231255

232256
/**
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
234268
*
235269
* @return bool
236270
*/
237-
public function hasPasswordReset($table)
271+
public function getPasswordResetValues($table)
238272
{
273+
$columns = [];
239274
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';
243278
if ($table == $tableName) {
244-
return true;
279+
$columns[$column] = $password;
245280
}
246281
}
247-
return false;
282+
return $columns;
248283
}
249284

250285
/**

0 commit comments

Comments
 (0)