update livemap to use rivets.js bindings for data updates
This commit is contained in:
@@ -31,7 +31,7 @@ class DatabaseService extends Service
|
||||
*/
|
||||
protected function time(): string
|
||||
{
|
||||
return Carbon::now('UTC')->format('Y-m-d H:i:s');
|
||||
return Carbon::now('UTC'); //->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,6 @@ class DatabaseService extends Service
|
||||
public function seed_from_yaml_file($yaml_file, $ignore_errors = false): array
|
||||
{
|
||||
$yml = file_get_contents($yaml_file);
|
||||
|
||||
return $this->seed_from_yaml($yml, $ignore_errors);
|
||||
}
|
||||
|
||||
@@ -61,39 +60,56 @@ class DatabaseService extends Service
|
||||
$imported[$table] = 0;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
# see if this table uses a UUID as the PK
|
||||
# if no ID is specified
|
||||
if (in_array($table, $this->uuid_tables)) {
|
||||
if (!array_key_exists('id', $row)) {
|
||||
$row['id'] = Uuid::generate()->string;
|
||||
}
|
||||
}
|
||||
|
||||
# encrypt any password fields
|
||||
if (array_key_exists('password', $row)) {
|
||||
$row['password'] = bcrypt($row['password']);
|
||||
}
|
||||
|
||||
# if any time fields are == to "now", then insert the right time
|
||||
foreach ($this->time_fields as $tf) {
|
||||
if (array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') {
|
||||
$row[$tf] = $this->time();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table($table)->insert($row);
|
||||
++$imported[$table];
|
||||
} catch (QueryException $e) {
|
||||
$row = $this->insert_row($table, $row);
|
||||
} catch(QueryException $e) {
|
||||
if ($ignore_errors) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
++$imported[$table];
|
||||
}
|
||||
}
|
||||
|
||||
return $imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $table
|
||||
* @param $row
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function insert_row($table, $row) {
|
||||
# see if this table uses a UUID as the PK
|
||||
# if no ID is specified
|
||||
if (\in_array($table, $this->uuid_tables, true)) {
|
||||
if (!array_key_exists('id', $row)) {
|
||||
$row['id'] = Uuid::generate()->string;
|
||||
}
|
||||
}
|
||||
|
||||
# encrypt any password fields
|
||||
if (array_key_exists('password', $row)) {
|
||||
$row['password'] = bcrypt($row['password']);
|
||||
}
|
||||
|
||||
# if any time fields are == to "now", then insert the right time
|
||||
foreach($row as $column => $value) {
|
||||
if(strtolower($value) === 'now') {
|
||||
$row[$column] = $this->time();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table($table)->insert($row);
|
||||
} catch (QueryException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user