Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix some errors
  • Loading branch information
asbiin committed Mar 9, 2018
commit 38c6f8a7c3b7e03a2171dbad5f7cb064645a4232
10 changes: 0 additions & 10 deletions app/Console/Commands/CalculateStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class CalculateStatistics extends Command
*/
protected $description = 'Calculate general usage statistics';

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

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/Deactivate2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ class Deactivate2FA extends Command
*/
protected $description = 'Deactivate 2FA for this user';

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

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/GetVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ class GetVersion extends Command
*/
protected $description = 'Get current version of monica';

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

/**
* Execute the console command.
*
Expand Down
152 changes: 83 additions & 69 deletions app/Console/Commands/ImportCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ class ImportCSV extends Command
*/
protected $description = 'Imports CSV in Google format to user account';

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

/**
* Execute the console command.
*
Expand Down Expand Up @@ -69,85 +59,109 @@ public function handle()
$gender->name = 'vCard';
$gender->save();

$row = 0;
$first = true;
$imported = 0;
if (($handle = fopen($file, 'r')) !== false) {
while (($data = fgetcsv($handle)) !== false) {
$row++;

// don't import the columns
if ($row == 1) {
continue;
try {
while (($data = fgetcsv($handle)) !== false) {
// don't import the columns
if ($first) {
continue;
} else {
$first = false;
}

if ($this->handleOneLine($data, $gender)) {
$imported++;
}
}
} finally {
fclose($handle);
}
}

$contact = new Contact();
$contact->account_id = $user->account_id;
$this->info("Imported {$imported} Contacts");
}

// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
continue;
}
/**
* Handle one line.
*
* @return mixed
*/
public function handleOneLine($data, $gender)
{
// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
return false;
}

if (! empty($data[1])) {
$contact->first_name = $data[1]; // Given Name
}
$contact = new Contact();
$contact->account_id = $user->account_id;
$contact->gender_id = $gender->id;

if (! empty($data[2])) {
$contact->middle_name = $data[2]; // Additional Name
}
$this->handleDatas($data, $contact);

if (! empty($data[3])) {
$contact->last_name = $data[3]; // Family Name
}
$contact->save();
$contact->setAvatarColor();

if (! empty($data[28])) {
$contact->email = $data[28]; // Email 1 Value
}
if (! empty($data[14])) {
$birthdate = new \DateTime(strtotime($data[14]));

if (! empty($data[42])) {
$contact->phone_number = $data[42]; // Phone 1 Value
}
$specialDate = $contact->setSpecialDate('birthdate', $birthdate->format('Y'), $birthdate->format('m'), $birthdate->format('d'));
$specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}

if (! empty($data[49])) {
$contact->street = $data[49]; // address 1 street
}
return true;
}

if (! empty($data[50])) {
$contact->city = $data[50]; // address 1 city
}
if (! empty($data[52])) {
$contact->province = $data[52]; // address 1 region (state)
}
/**
* Handle datas.
*
* @return mixed
*/
public function handleDatas($data, $contact)
{
if (! empty($data[1])) {
$contact->first_name = $data[1]; // Given Name
}

if (! empty($data[53])) {
$contact->postal_code = $data[53]; // address 1 postal code (zip) 53
}
if (! empty($data[66])) {
$contact->job = $data[66]; // organization 1 name 66
}
if (! empty($data[2])) {
$contact->middle_name = $data[2]; // Additional Name
}

// can't have empty email
if (empty($contact->email)) {
$contact->email = null;
}
if (! empty($data[3])) {
$contact->last_name = $data[3]; // Family Name
}

$contact->gender_id = $gender->id;
if (! empty($data[28])) {
$contact->email = $data[28]; // Email 1 Value
}

$contact->save();
$contact->setAvatarColor();
if (! empty($data[42])) {
$contact->phone_number = $data[42]; // Phone 1 Value
}

if (! empty($data[14])) {
$birthdate = new \DateTime(strtotime($data[14]));
if (! empty($data[49])) {
$contact->street = $data[49]; // address 1 street
}

$specialDate = $contact->setSpecialDate('birthdate', $birthdate->format('Y'), $birthdate->format('m'), $birthdate->format('d'));
$specialDate->setReminder('year', 1, trans('people.people_add_birthday_reminder', ['name' => $contact->first_name]));
}
if (! empty($data[50])) {
$contact->city = $data[50]; // address 1 city
}
if (! empty($data[52])) {
$contact->province = $data[52]; // address 1 region (state)
}

$imported++;
}
fclose($handle);
if (! empty($data[53])) {
$contact->postal_code = $data[53]; // address 1 postal code (zip) 53
}
if (! empty($data[66])) {
$contact->job = $data[66]; // organization 1 name 66
}

$this->info("Imported {$imported} Contacts");
// can't have empty email
if (empty($contact->email)) {
$contact->email = null;
}
}
}
10 changes: 0 additions & 10 deletions app/Console/Commands/PingVersionServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class PingVersionServer extends Command
*/
protected $description = 'Ping version.monicahq.com to know if a new version is available';

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

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/SendNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ class SendNotifications extends Command
*/
protected $description = 'Send notifications about reminders';

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

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/SendReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ class SendReminders extends Command
*/
protected $description = 'Send reminders that are scheduled for the contacts';

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

/**
* Execute the console command.
*
Expand Down
8 changes: 0 additions & 8 deletions app/Console/Commands/SetupProduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ class SetupProduction extends Command
*/
protected $description = 'Perform setup of Monica.';

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

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ class SetupTest extends Command
*/
protected $description = 'Create the test environment with optional fake data for testing purposes.';

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

/**
* Execute the console command.
*
Expand Down