Skip to content

Commit

Permalink
sync hubspot contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
scott grayson authored and scott grayson committed Dec 3, 2024
1 parent 17bd74d commit 5506d21
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/Commands/SyncHubspotContacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Tapp\LaravelHubspot\Commands;

use Illuminate\Console\Command;
use Tapp\LaravelHubspot\Models\HubspotContact;

class SyncHubspotContacts extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'hubspot:sync-contacts {model=\App\Models\User}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create missing hubspot contacts.';

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

/**
* Execute the console command.
*/
public function handle(): int
{
$contactModel = $this->argument('model');

$contacts = $contactModel::all();

foreach ($contacts as $contact) {
HubspotContact::updateOrCreateHubspotContact($contact);
}

return Command::SUCCESS;
}
}
4 changes: 3 additions & 1 deletion src/LaravelHubspotServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Psr\Http\Message\RequestInterface;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Tapp\LaravelHubspot\Commands\SyncHubspotContacts;
use Tapp\LaravelHubspot\Commands\SyncHubspotProperties;

class LaravelHubspotServiceProvider extends PackageServiceProvider
Expand All @@ -25,7 +26,8 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasViews()
->hasMigration('add_hubspot_id_to_users_table')
->hasCommand(SyncHubspotProperties::class);
->hasCommand(SyncHubspotProperties::class)
->hasCommand(SyncHubspotContacts::class);
}

public function bootingPackage()
Expand Down

0 comments on commit 5506d21

Please sign in to comment.