Skip to content

Commit

Permalink
Add script to import MRES emails.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwh committed Aug 14, 2023
1 parent fd0d9d1 commit 3e6bd1d
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions app/Console/Commands/ImportMRES.php
@@ -0,0 +1,78 @@
<?php

namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

use function Symfony\Component\VarDumper\Dumper\esc;

class ImportMRES extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:mres {input}';


/**
* The console command description.
*
* @var string
*/
protected $description = 'Assign email addresses to MRES groups.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$input = $this->argument('input');

$inputFile = fopen($input, 'r');

// First three lines are headers.
fgetcsv($inputFile);
fgetcsv($inputFile);
fgetcsv($inputFile);

while (!feof($inputFile))
{
$fields = fgetcsv($inputFile);

if ($fields) {
$fields = array_map("utf8_encode", $fields);
$groupname = trim($fields[0]);
$email = trim($fields[1]);

if ($email) {
// Find group with name
$group = \App\Group::where('name', 'like', $groupname)->first();

if ($group) {
$this->info("Set email for $groupname to $email");
$group->email = $email;
$group->save();
} else {
$this->error("No group found for $groupname");
}
}
}
}
}
}

0 comments on commit 3e6bd1d

Please sign in to comment.