Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
156 changes: 81 additions & 75 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 @@ -64,90 +54,106 @@ public function handle()
// create special gender for this import
// we don't know which gender all the contacts are, so we need to create a special status for them, as we
// can't guess whether they are men, women or else.
$gender = new Gender;
$gender->account_id = $user->account_id;
$gender->name = 'vCard';
$gender->save();
$gender = Gender::where('name', 'vCard')->first();
if (! $gender) {
$gender = new Gender;
$gender->account_id = $user->account_id;
$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;
}

$contact = new Contact();
$contact->account_id = $user->account_id;

// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
continue;
try {
while (($data = fgetcsv($handle)) !== false) {
// don't import the columns
if ($first) {
$first = false;
continue;
}

// if first & last name do not exist skip row
if (empty($data[1]) && empty($data[3])) {
continue;
}

$this->csvToContact($data, $user->account_id, $gender->id);

$imported++;
}
} finally {
fclose($handle);
}
}

if (! empty($data[1])) {
$contact->first_name = $data[1]; // Given Name
}
$this->info("Imported {$imported} Contacts");
}

if (! empty($data[2])) {
$contact->middle_name = $data[2]; // Additional Name
}
/**
* Create contact.
*/
private function csvToContact($data, $account_id, $gender_id)
{
$contact = new Contact();
$contact->account_id = $account_id;
$contact->gender_id = $gender_id;

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

if (! empty($data[28])) {
$contact->email = $data[28]; // Email 1 Value
}
if (! empty($data[2])) {
$contact->middle_name = $data[2]; // Additional Name
}

if (! empty($data[42])) {
$contact->phone_number = $data[42]; // Phone 1 Value
}
if (! empty($data[3])) {
$contact->last_name = $data[3]; // Family Name
}

if (! empty($data[49])) {
$contact->street = $data[49]; // address 1 street
}
if (! empty($data[28])) {
$contact->email = $data[28]; // Email 1 Value
}

if (! empty($data[50])) {
$contact->city = $data[50]; // address 1 city
}
if (! empty($data[52])) {
$contact->province = $data[52]; // address 1 region (state)
}
if (! empty($data[42])) {
$contact->phone_number = $data[42]; // Phone 1 Value
}

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[49])) {
$contact->street = $data[49]; // address 1 street
}

// can't have empty email
if (empty($contact->email)) {
$contact->email = null;
}
if (! empty($data[50])) {
$contact->city = $data[50]; // address 1 city
}
if (! empty($data[52])) {
$contact->province = $data[52]; // address 1 region (state)
}

$contact->gender_id = $gender->id;
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
}

$contact->save();
$contact->setAvatarColor();
// can't have empty email
if (empty($contact->email)) {
$contact->email = null;
}

if (! empty($data[14])) {
$birthdate = new \DateTime(strtotime($data[14]));
$contact->save();
$contact->setAvatarColor();

$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[14])) {
$birthdate = new \DateTime(strtotime($data[14]));

$imported++;
}
fclose($handle);
$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]));
}

$this->info("Imported {$imported} Contacts");
$contact->updateGravatar();

$contact->logEvent('contact', $contact->id, 'create');
}
}
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
16 changes: 0 additions & 16 deletions app/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,4 @@ public function scopeForObject(Builder $query, Model $object, string $key = null
return $query->where('object_type', $key)
->where('object_id', $object->id);
}

public function getDescription()
{
if ($this->nature_of_operation == 'create') {
$description = 'You added ';
}

if ($this->nature_of_operation == 'update') {
$description = 'You updated ';
}

// You added a reminder about John Doe
if ($this->object_type == 'reminder') {
$reminder = Reminder::findOrFail($this->object_id);
}
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/ApiGiftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function store(Request $request)

if (! is_null($request->input('is_for'))) {
try {
$contact = Contact::where('account_id', auth()->user()->account_id)
Contact::where('account_id', auth()->user()->account_id)
->where('id', $request->input('is_for'))
->firstOrFail();
} catch (ModelNotFoundException $e) {
Expand Down Expand Up @@ -142,7 +142,7 @@ public function update(Request $request, $giftId)

if (! is_null($request->input('is_for'))) {
try {
$contact = Contact::where('account_id', auth()->user()->account_id)
Contact::where('account_id', auth()->user()->account_id)
->where('id', $request->input('is_for'))
->firstOrFail();
} catch (ModelNotFoundException $e) {
Expand Down