Skip to content

Commit d3f66ae

Browse files
committed
Merge branch 'master' into #355-2fa
# Conflicts: # app/HMS/User/ProfileManager.php # app/HMS/User/UserManager.php # app/Http/Controllers/MembershipController.php # app/Http/Kernel.php # resources/views/layouts/navbar.blade.php # routes/web.php
2 parents ccc43c3 + f7825cc commit d3f66ae

File tree

185 files changed

+5084
-1020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+5084
-1020
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ To run an artisan command on the VM, (for example if you don't have PHP installe
2626
Simply pass it the artisan command you want to run, e.g:
2727

2828
```./dev/php-artisan make:controller```
29+
30+
## Vagrant re-provisioning notes
31+
32+
When re-provisioning the box (`vagrnat up`) you must make sure that the `.env` file has `QUEUE_CONNECTION=sync` in order the to the `db:seed` to correctly populate the `mailserver` database entries.
33+
34+
If the `mailserver.mailbox` tables it empty you can do a datebase reset and reseed with `dev/reseed.sh`
35+

Vagrantfile

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
3434
config.trigger.after :up, :resume, :reload do |trigger|
3535
trigger.info = "Restaring Nginx & PHP"
3636
trigger.run_remote = {inline: "sudo systemctl restart nginx php7.2-fpm"}
37+
trigger.run_remote = {inline: "php /vagrant/artisan horizon:terminate"}
3738
end
3839

3940
end

app/Console/Commands/Database/MigrateInstrumentaionCommand.php

+187-70
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,36 @@ class MigrateInstrumentaionCommand extends Command
6161
// 'account_number' => 'account_number',
6262
// ],
6363
// ],
64-
'bells' => [
65-
'newTableName' => 'bells',
66-
'columns' => [
67-
'bell_id' => 'id',
68-
'bell_description' => 'description',
69-
'bell_topic' => 'topic',
70-
'bell_message' => 'message',
71-
'bell_enabled' => 'enabled',
72-
],
73-
],
74-
'door_bells' => [
75-
'newTableName' => 'door_bell',
76-
'columns' => [
77-
'door_id' => 'door_id',
78-
'bell_id' => 'bell_id',
79-
],
80-
],
81-
'doors' => [
82-
'newTableName' => 'doors',
83-
'columns' => [
84-
'door_id' => 'id',
85-
'door_description' => 'description',
86-
'door_short_name' => 'short_name',
87-
'door_state' => 'state',
88-
'door_state_change' => 'state_change',
89-
'permission_code' => 'permission_code',
90-
'side_a_zone_id' => 'side_a_zone_id',
91-
'side_b_zone_id' => 'side_b_zone_id',
92-
],
93-
],
64+
// 'bells' => [
65+
// 'newTableName' => 'bells',
66+
// 'columns' => [
67+
// 'bell_id' => 'id',
68+
// 'bell_description' => 'description',
69+
// 'bell_topic' => 'topic',
70+
// 'bell_message' => 'message',
71+
// 'bell_enabled' => 'enabled',
72+
// ],
73+
// ],
74+
// 'door_bells' => [
75+
// 'newTableName' => 'door_bell',
76+
// 'columns' => [
77+
// 'door_id' => 'door_id',
78+
// 'bell_id' => 'bell_id',
79+
// ],
80+
// ],
81+
// 'doors' => [
82+
// 'newTableName' => 'doors',
83+
// 'columns' => [
84+
// 'door_id' => 'id',
85+
// 'door_description' => 'description',
86+
// 'door_short_name' => 'short_name',
87+
// 'door_state' => 'state',
88+
// 'door_state_change' => 'state_change',
89+
// // 'permission_code' => 'permission_code',
90+
// 'side_a_zone_id' => 'side_a_zone_id',
91+
// 'side_b_zone_id' => 'side_b_zone_id',
92+
// ],
93+
// ],
9494
'emails' => [
9595
'newTableName' => 'snackspace_emails',
9696
'columns' => [
@@ -255,22 +255,22 @@ class MigrateInstrumentaionCommand extends Command
255255
'vmc_address' => 'address',
256256
],
257257
],
258-
'vmc_ref' => [
259-
'newTableName' => 'vending_locations',
260-
'columns' => [
261-
'vmc_ref_id' => 'id',
262-
'vmc_id' => 'vending_machine_id',
263-
'loc_encoded' => 'encoding',
264-
'loc_name' => 'name',
265-
],
266-
],
267-
'vmc_state' => [
268-
'newTableName' => 'product_vending_location',
269-
'columns' => [
270-
'vmc_ref_id' => 'vending_location_id',
271-
'product_id' => 'product_id',
272-
],
273-
],
258+
// 'vmc_ref' => [
259+
// 'newTableName' => 'vending_locations',
260+
// 'columns' => [
261+
// 'vmc_ref_id' => 'id',
262+
// 'vmc_id' => 'vending_machine_id',
263+
// 'loc_encoded' => 'encoding',
264+
// 'loc_name' => 'name',
265+
// ],
266+
// ],
267+
// 'vmc_state' => [
268+
// 'newTableName' => 'product_vending_location',
269+
// 'columns' => [
270+
// 'vmc_ref_id' => 'vending_location_id',
271+
// 'product_id' => 'product_id',
272+
// ],
273+
// ],
274274
'transactions' => [
275275
'newTableName' => 'transactions',
276276
'columns' => [
@@ -347,15 +347,15 @@ class MigrateInstrumentaionCommand extends Command
347347
'time_entered' => 'time_entered',
348348
],
349349
],
350-
'zones' => [
351-
'newTableName' => 'zones',
352-
'columns' => [
353-
'zone_id' => 'id',
354-
'zone_description' => 'description',
355-
'zone_short_name' => 'short_name',
356-
'permission_code' => 'permission_code',
357-
],
358-
],
350+
// 'zones' => [
351+
// 'newTableName' => 'zones',
352+
// 'columns' => [
353+
// 'zone_id' => 'id',
354+
// 'zone_description' => 'description',
355+
// 'zone_short_name' => 'short_name',
356+
// 'permission_code' => 'permission_code',
357+
// ],
358+
// ],
359359
];
360360

361361
/**
@@ -377,6 +377,16 @@ class MigrateInstrumentaionCommand extends Command
377377
*/
378378
protected $description = 'Migrate data form old instrumentation database';
379379

380+
/**
381+
* @var null|\DateTimeZone
382+
*/
383+
private static $utc = null;
384+
385+
/**
386+
* @var null|\DateTimeZone
387+
*/
388+
private static $gmt = null;
389+
380390
/**
381391
* Create a new command instance.
382392
*
@@ -397,11 +407,18 @@ public function __construct(ToolManager $toolManager)
397407
*/
398408
public function handle()
399409
{
400-
// TODO get from user
401-
$instrumentationHost = '127.0.0.1';
402-
$instrumentationDatabase = 'instrumentation';
403-
$instrumentationUser = 'hms';
404-
$instrumentationPassword = 'secret';
410+
if (is_null(self::$utc)) {
411+
self::$utc = new \DateTimeZone('UTC');
412+
}
413+
if (is_null(self::$gmt)) {
414+
self::$gmt = new \DateTimeZone('Europe/London');
415+
}
416+
417+
$this->info('Please provide details for connecting to the instrumentation database.');
418+
$instrumentationHost = $this->anticipate('Host? [127.0.0.1]', ['127.0.0.1']) ?: '127.0.0.1';
419+
$instrumentationDatabase = $this->anticipate('Database name? [instrumentation]', ['instrumentation']) ?: 'instrumentation';
420+
$instrumentationUser = $this->anticipate('User? [hms]', ['hms']) ?: 'hms';
421+
$instrumentationPassword = $this->secret('Password? [secret]') ?: 'secret';
405422

406423
$start = Carbon::now();
407424
config(['database.connections.instrumentation' => [
@@ -432,6 +449,7 @@ public function handle()
432449
$this->migrateTools();
433450
$this->migrateMemberTools();
434451
$this->migrateHmsEmails();
452+
$this->migrateVeningLocations();
435453

436454
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
437455
$this->info('Total run took ' . $start->diff(Carbon::now())->format('%H:%i:%s'));
@@ -474,6 +492,16 @@ protected function migrateStatusUpdates()
474492
$roleUpdates = [];
475493

476494
foreach ($oldData as $row) {
495+
// convert timestamp column from Europe/London to UTC
496+
$converted = Carbon::createFromFormat(
497+
'Y-m-d H:i:s',
498+
$row->timestamp,
499+
self::$gmt
500+
);
501+
502+
$converted->setTimezone(self::$utc);
503+
$row->timestamp = $converted->toDateTimeString();
504+
477505
// deal with old status first
478506
if ($row->old_status > 2) {
479507
$roleUpdates[] = [
@@ -559,9 +587,10 @@ protected function migrateMembers()
559587
'lastname' => $row->surname,
560588
'username' => $row->username,
561589
'email' => $row->email,
562-
'created_at' => $row->join_date != '0000-00-00' ? $row->join_date : Carbon::now(),
563-
'updated_at' => Carbon::now(),
590+
'created_at' => $row->join_date != '0000-00-00' ? $row->join_date : Carbon::now(self::$utc),
591+
'updated_at' => Carbon::now(self::$utc),
564592
'account_id' => $row->account_id,
593+
'email_verified_at' => Carbon::now(self::$utc),
565594
];
566595
$profile = [
567596
'user_id' => $row->member_id,
@@ -573,8 +602,8 @@ protected function migrateMembers()
573602
'address_city' => $row->address_city,
574603
'address_postcode' => $row->address_postcode,
575604
'contact_number' => $row->contact_number,
576-
'created_at' => $row->join_date != '0000-00-00' ? $row->join_date : Carbon::now(),
577-
'updated_at' => Carbon::now(),
605+
'created_at' => $row->join_date != '0000-00-00' ? $row->join_date : Carbon::now(self::$utc),
606+
'updated_at' => Carbon::now(self::$utc),
578607
'balance' => $row->balance,
579608
];
580609

@@ -736,6 +765,16 @@ protected function migrateMemberTools()
736765
$roleUsers = [];
737766
$roleUpdates = [];
738767
foreach ($oldData as $row) {
768+
// convert mt_date_inducted column from Europe/London to UTC
769+
$converted = Carbon::createFromFormat(
770+
'Y-m-d H:i:s',
771+
$row->mt_date_inducted,
772+
self::$gmt
773+
);
774+
775+
$converted->setTimezone(self::$utc);
776+
$row->mt_date_inducted = $converted->toDateTimeString();
777+
739778
switch ($row->mt_access_level) {
740779
case 'MAINTAINER':
741780
$roleUsers[] = [
@@ -816,6 +855,16 @@ protected function migrateHmsEmails()
816855
});
817856

818857
$newData = $filteredData->map(function ($row, $key) use ($columns, $newTableName, &$emailUser) {
858+
// convert timestamp column from Europe/London to UTC
859+
$converted = Carbon::createFromFormat(
860+
'Y-m-d H:i:s',
861+
$row->timestamp,
862+
self::$gmt
863+
);
864+
865+
$converted->setTimezone(self::$utc);
866+
$row->timestamp = $converted->toDateTimeString();
867+
819868
$newRow = [];
820869
foreach ($columns as $oldName => $newName) {
821870
$newRow[$newName] = $row->$oldName;
@@ -855,6 +904,45 @@ protected function migrateHmsEmails()
855904
$this->info($startTime->diff(Carbon::now())->format('took: %H:%i:%s'));
856905
}
857906

907+
protected function migrateVeningLocations()
908+
{
909+
$oldTableName = 'vmc_ref';
910+
$newTableName = 'vending_locations';
911+
$columns = [
912+
'vmc_ref_id' => 'id',
913+
'vmc_id' => 'vending_machine_id',
914+
'loc_encoded' => 'encoding',
915+
'loc_name' => 'name',
916+
];
917+
918+
$this->info('Migrating ' . $oldTableName);
919+
$startTime = Carbon::now();
920+
$oldData = DB::connection('instrumentation')->table($oldTableName)->get();
921+
922+
$newData = $oldData->map(function ($row, $key) use ($columns, $newTableName) {
923+
$newRow = [];
924+
foreach ($columns as $oldName => $newName) {
925+
$newRow[$newName] = $row->$oldName;
926+
}
927+
928+
// From old state for find product_id for $newRow['id']
929+
$state = DB::connection('instrumentation')->table('vmc_state')->where('vmc_ref_id', $row->vmc_ref_id)->first();
930+
931+
$newRow['product_id'] = $state->product_id;
932+
933+
return $newRow;
934+
});
935+
936+
DB::statement("TRUNCATE TABLE $newTableName;");
937+
938+
$dataChunks = array_chunk($newData->toArray(), 1000, true);
939+
foreach ($dataChunks as $dataChunk) {
940+
DB::table($newTableName)->insert($dataChunk);
941+
}
942+
943+
$this->info($startTime->diff(Carbon::now())->format('took: %H:%i:%s'));
944+
}
945+
858946
protected function migrateSimpleMappings()
859947
{
860948
$simpleStart = Carbon::now();
@@ -872,7 +960,12 @@ protected function simpleMigration($oldTableName, $mapping)
872960
$startTime = Carbon::now();
873961
$oldData = DB::connection('instrumentation')->table($oldTableName)->get();
874962

875-
$newData = $oldData->map(function ($row, $key) use ($mapping, $newTableName) {
963+
$column_types = [];
964+
foreach ($mapping['columns'] as $oldName => $newName) {
965+
$column_types[$oldName] = DB::connection('instrumentation')->getSchemaBuilder()->getColumnType($oldTableName, $oldName);
966+
}
967+
968+
$newData = $oldData->map(function ($row, $key) use ($mapping, $newTableName, $column_types) {
876969
$newRow = [];
877970
foreach ($mapping['columns'] as $oldName => $newName) {
878971
if (array_key_exists($oldName, $row)) {
@@ -883,11 +976,25 @@ protected function simpleMigration($oldTableName, $mapping)
883976
$newRow[$newName] *= 100;
884977
}
885978

886-
// zone id's need to be increase by one
887-
if (strpos($newName, 'zone_id') !== false) {
888-
$newRow[$newName] += 1;
889-
} elseif ($newTableName == 'zones' && $newName == 'id') {
890-
$newRow[$newName] += 1;
979+
if ($column_types[$oldName] == 'datetime') {
980+
// convert datatime columns from Europe/London to UTC
981+
if (is_null($newRow[$newName])) {
982+
// skipp null
983+
} elseif (strlen($newRow[$newName]) == 10) {
984+
// skip date only fields
985+
} elseif (strlen($newRow[$newName]) == 19) {
986+
// ah date and time
987+
$converted = Carbon::createFromFormat(
988+
'Y-m-d H:i:s',
989+
$newRow[$newName],
990+
self::$gmt
991+
);
992+
$converted->setTimezone(self::$utc);
993+
$newRow[$newName] = $converted->toDateTimeString();
994+
} else {
995+
// hmm time only field?
996+
dd($newRow[$newName]);
997+
}
891998
}
892999
}
8931000
}
@@ -897,10 +1004,20 @@ protected function simpleMigration($oldTableName, $mapping)
8971004

8981005
DB::statement("TRUNCATE TABLE $newTableName;");
8991006

1007+
if ($newTableName == 'zones') {
1008+
$mode = DB::select('select @@sql_mode as sql_mode')[0];
1009+
DB::statement("SET sql_mode='$mode->sql_mode,NO_AUTO_VALUE_ON_ZERO'");
1010+
}
1011+
9001012
$dataChunks = array_chunk($newData->toArray(), 1000, true);
9011013
foreach ($dataChunks as $dataChunk) {
9021014
DB::table($newTableName)->insert($dataChunk);
9031015
}
1016+
1017+
if ($newTableName == 'zones') {
1018+
DB::statement("SET sql_mode='$mode->sql_mode'");
1019+
}
1020+
9041021
$this->info($startTime->diff(Carbon::now())->format('took: %H:%i:%s'));
9051022
}
9061023
}

0 commit comments

Comments
 (0)