Skip to content

Commit

Permalink
remove some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
scott grayson authored and scott grayson committed Jan 14, 2025
1 parent 1e664c0 commit 5e92af3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 52 deletions.
15 changes: 3 additions & 12 deletions src/Models/HubspotCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public static function updateOrCreateHubspotCompany($model)

$hubspotCompany = static::getCompanyById($model);

// TODO if no hubspot id or if id fetch failed, try searching by name

if (! $hubspotCompany) {
return static::createHubspotCompany($model);
}
Expand All @@ -89,16 +91,6 @@ public static function getCompanyById($model)
}
}

// TODO if no hubspot id or if id fetch failed, try searching by name
// try {
// $hubspotCompany = Hubspot::crm()->companies()->basicApi()->getById($model->email, null, null, null, false, 'email');

// // dont save to prevent loop from model event
// $model->hubspot_id = $hubspotCompany['id'];
// } catch (ApiException $e) {
// Log::debug('Hubspot company not found with email', ['email' => $model->email]);
// }

return $hubspotCompany;
}

Expand Down Expand Up @@ -147,8 +139,7 @@ public static function findOrCreateCompany($properties)
try {
$searchResults = Hubspot::crm()->companies()->searchApi()->doSearch($companySearch);
} catch (\Exception $e) {
// TODO debugging
dump($filter, $properties);
// dump($filter, $properties);
// dd($e);
throw ($e);
}
Expand Down
42 changes: 2 additions & 40 deletions src/Models/HubspotContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,43 +147,6 @@ public function hubspotPropertiesObject(array $map): ContactObject
return new ContactObject(['properties' => $this->hubspotProperties($map)]);
}

public static function findOrCreateCompany($properties)
{
$filter = new Filter([
'value' => $properties['name'],
'property_name' => 'name',
'operator' => 'EQ',
]);

$filterGroup = new FilterGroup([
'filters' => [$filter],
]);

$companySearch = new CompanySearch([
'filter_groups' => [$filterGroup],
]);

$searchResults = Hubspot::crm()->companies()->searchApi()->doSearch($companySearch);

$companyExists = $searchResults['total'];

if ($companyExists) {
return $searchResults['results'][0];
} else {
// TODO create company
dd('todo create company from relation');
$properties = [
'na' => $domain,
];

$companyObject = new CompanyObject([
'properties' => $properties,
]);

return Hubspot::crm()->companies()->basicApi()->create($companyObject);
}
}

public static function associateCompanyWithContact(string $companyId, string $contactId)
{
$associationSpec = new AssociationSpec([
Expand All @@ -192,12 +155,11 @@ public static function associateCompanyWithContact(string $companyId, string $co
]);

try {
$apiResponse = Hubspot::crm()->associations()->v4()->basicApi()->create('contact', $contactId, 'company', $companyId, [$associationSpec]);
return Hubspot::crm()->associations()->v4()->basicApi()->create('contact', $contactId, 'company', $companyId, [$associationSpec]);
} catch (AssociationsApiException $e) {
// dd($companyId, $contactId);
dd($e);
// dd($e);
throw ($e);
echo 'Exception when calling basic_api->create: ', $e->getMessage();
}
}
}

0 comments on commit 5e92af3

Please sign in to comment.