|
89217
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
rapstomViewCoocWindowFV faVsco.|s ~#12121 on JY-20963-fx-lProinet vCSamviceTestonDeleteObjectsTrait.phgcomposer.isonMmacuryochyict.on© RecordSelector.phg© Activity.prpC) Team.phdcomposer lockdependency-checker.sondew.isorCiosooweaistocesseimce.onImportBatch.lobTrait.ohdE ids.txinieraison distctosbsnoasxnMNnERNAuwErhoesatema201125 Kouantrait OpportunitySyncTraitliminny storaadMalicancac.m240226 Koval* Boaran arraucstring> Scralds HubSpot deal CRM IDSMMakere7402.26 Kovalt© package-lock.json=phpstan.neon.distF phpstan-baseline.neo.<>phpunit.xmltraw_sqLquery.saMAPEAOMS ma7602.26 Kovalt23.02.26 Kovall* acetucn arrayisuccess: array, fazted_ids: array, errors?: array<string, string>,SAIE KONAT188 Cnuaidieunctton noor toorunvearchiuidslarray SermidsearcarMae77a KONAlT198aeltsThisosrea 5edcseruscooroerstedssarcon.aunarsonisrhiso%conro0 sonar-proiect propertiesEtest.pv23.02.26 KovalSUn tieo Dnciom.xmi23.02.26 Kovalkisvetur.confia.i23.02.26 KovalikM:.WEBHOOK_FILTERING_IMPLEMENTAT22.02 26. Kovar> 1h Extemnal Libraries23.02.26 Kovalkv #Scratches and Consoles22.02 28 KouaR.v @ Database Consoles23.02.26 KovalkV AEU22.02 2R Kouanconsole lEuLSULLO KOVA4 DEAL RISKS (EU)22.02 28 Kouan193Salldeals = UJ:Eoreach arcay chunkSernids.length: self::BATCH_SIZE) as Schunk) 4Sdeals = Sthis->client-›get0pportunitiesByIds(Schunk, Sfields):foreach (Sdeals as Sdeal) 1SallDeals[) = Sdeal;DNTEUAEL(EInIDs not returned by HubSpot are Likely deleted on inaccessible dealsaeseae nor.SX HONcYRla 5 Pgáng th°a Pask →SfetchedIds = arraya sp ecamusce"strval' array column(SallDealscolumn.key. "id')):Servicas7) Outputiiiliminny.opportunitiesiid fiminny stage1id Result 34iid liminny.stages 2 Xv Moatabasd10 гowswAn id Min crm provider id Mi probability yAm type yi2 con conficuration_id yconcalo 1eon maCil users 1 s 548 msv#liminny@localhostAHS Jocal14267 closedwon100.00 opportunity14268 closedlost8n88 opportunttyWNO DRRURRAAanl ail onnontun14297 219944019100.00 opportunityVHODan14284 2198649170.00 opportunity# consolaV ASTAGING# ConcalaO, naavor14298 1773033788.80 opportunity14292 1773033888.88 oppontunity14293 177303379ebred oppontunty1holMtnenAkoe100.00 opportunity14204492119749100.00 opportunitye MursreSMCAS,WNotANDeonwedanisniuilcomolatar.h.minutas.aooServiceTestTO0У L7Inu co moy kuiogis+0.=custom.log=laravellogA SF jminny@localhostHSJocal (jiminny(@localhost)e console (PROD)A console (EU) X18001801180218031 HHM111.80418051.[PHONE]9=18101811=18121813E1824E18151816=1818iid users (EU"A console [STAGINGTEANCoMMeceCOUNT(*) as totalFROM opportunities oJOIN stages s1.n<->1: ON s.id = o.stage_1gJOIN crm_configurations cc 1.n<->1: ON cc.id = s.crn_configuration_icWHERE cc.provider = "hubspot"AND S.probability = 106AMn oris monAl031 A9 A31 Y3 Y113 AAND o.deleted at IS NULLAND s.deleted at IS NULL:SELECT o.id, o.is-won, o.probability as opp probabilityS.probabzlzcy as scage orobs.cre provzder 1oo.created_atFROM oppontunities oJUIN Scages S1.n<->1: ON s.id = o.stage1dWHERE o.tean_id = 416 AND o.created at > '2826-85-28' AND s.probability = 100ORDER BY o.created_at DESC LIMIT 10SELECT s.id. s.crn_provider id. s.probabflity. s.type. s.crn_confiquration&FROM stagessmhete sheon contouritoon.ioeyAle stunes"opporunyAND s-probability IN (0, 100)AND s.deleted at IS NULL:eworehsermiehalsorce oelcdonkttonenarravioronerctesloescraocrSeloseostacestwonis tecemine something other than "208499441» in Sorooertes"deniotage")Check what HubSpot actually returns for des lstage on these dealsound i Look at process AoiResults line 390"oroperttes" @ Sobiectoone.Prooerttesor.egetProperties() on the HubSpot SDK returns an associative array where values are the raw property values. For dealstas0) OpportunitySyncTrait.php:192-199seiehsecencoe0ooorunesoyoscnunkeoscallhenletle cooloetdoportunttesByide returns an array keved ow CRM 1D Ine 388: SresnltelSobiectoooetdolehal thenAccept allAck aouthno (2oL+ • code)3Adaptive• OASVwI Wodeur Thams 180-80 UTE-R AlA enano...
|
PhpStorm
|
faVsco.js – OpportunitySyncTrait.php
|
NULL
|
89217
|
|
89216
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:59:32®8 10Untitled +...
|
PhpStorm
|
faVsco.js – OpportunitySyncTrait.php
|
NULL
|
89216
|
|
89215
|
PhpStormProinet vViewCoocFV faVsco.|s ~#12121 on J PhpStormProinet vViewCoocFV faVsco.|s ~#12121 on JY-20963-fx-imWindowCSamcetesconDeleteObjectsTrait.phgcomposer.isonMmacuryochyict.on© RecordSelector.phg© Activity.prpC) Team.phdcomposer lockdependency-checker.sondew.isorE ids.txinieraison distHoooswo.noocxea.cokicontoenisyiostoreoCoseowaisto.osseiwice.onImportBatch.lobTrait.ohdx52/6MNIERNALWE.HO0Satema201125 Kouantaast NonontunstySunetoastliminny storaadsets containing company CRM IDs collected from webhook eventsMalicancac.m12.03.26 Kovalk* and dispatches ImportüpportunityBatch jobs for batch processingMMakere17.03.26 Koval© package-lock.json12.03.26 Kovalik* Bcetucn int Number of opportunity I0s dispatched to jobs=phpstan.neon.dist17.03.26 KovalF phpstan-baseline.neo.To usdrdu<>phpunit.xml17.03.26 Kovalpublic function batchSyncOpportunities@: int..traw_sqLquery.sa12.03.26 KovalikMAPEAOMS ma72.02 28 KAupt180 Б0 sonar-proiect propertiesLU.ULILO NOYOEtest.pvwon tieo Ornolom.xml23.02.20 KOValisvetur.confia.iM:.WEBHOOK_FILTERING_IMPLEMENTAT23.02.20 KOVal> 1h Extemal Librariesv #Scratches and Consoles23.02.20 KOVSv @ Database ConsolesV AEU23.02.26 KovalRconsole lEu23.02.26 KOValA DEAL RISKS (EU)DNTEU26.02.26 KoVal23.02.26 KovalRAEL(EIn* Import a batch of opportunities by their CRM IDs.* Fetches opportunity data fron HubSpot API and delegates to importOpportunityBatcho.183184* Soanan arrau<string> Scrnids HubSpot deal CRM IDs* @retuen array(success: array, failed_ids: array, errors?: array<string, string>)188 Cpublic function importOpportunityBatchByIds(array ScrnIds): array$f49682od 5thgs-XR3@9FF4eldsForConFtguration(Sthis-2config);Servicas7) Outputiiiliminny.opportunitiesiii fiminny stages1id Result 34iid liminny.stages 2 Xv Moatabasd10 гowswAn id Min crm provider id Mim probability Mconcalo 1eon maCil users 1 s 548 msv#liminny@localhostAHS Jocal14267 closedwonAm typey100.00 opportunityi2 con conficuration_id y14268 closedlost8n88 opportunttyWNO DRRARRAAIanl ail onnontun14297 219944019100.00 opportunityv Honan# consolaV ASTAGING# ConcalaO, naavor14284 2198649178.00 opportunity14298 1773033788.80 opportunity14292 1773033888.88 oppontunity14293 177303379ebred oppontunty1holMtnenAkoe100.00 opportunity14204492119749100.00 opportunityServiceTestTO0У L7inu co moy kuiosis+0.=custom.log=laravellogA SF (jiminny@localhostHS_Jocal (jiminny(@localhost)e console (PROD)A console (EU) X180E180118021803TіВА-Н1.804180718081809=18101811=18121813E1814E18151814=1818iid users (EU"A console [STAGINGeoreesermieeMlsorce DalehionkTEANCoMMeceCOUNT(*) as totalFROM opportunities oJOIN stages s1.n<->1: ON s.id = o.stage_1gJOIN crm_configurations cc 1.n<-›1: ON cc.id = s.crn_configuration_idWHERE cc.provider = "hubspot"AND S.probability = 106AMn oris monAl031 A9 A31 Y3 Y113 AAND o.deleted at IS NULLAND s.deleted at IS NULL:SELECT o.id, o.is-won, o.probability as opp probabilitys.probability as stage probs.cre provzder 1oo.created_atFROM oppontunities oJOIN stages s1.n<->1: ON s.id = o.stage1.WHERE o.tean_id = 416 AND o.created at > '2826-85-28' AND s.probability = 100ORDER BY o.created_at DESC LIMIT 10SELECT s.id. s.crn_provider id. s.probabflity. s.type. s.crn_confiquration&FROM stagessmhete sheon contouritoon.ioeyAle stunes"opporunyAND s-probability IN (0, 100)AND s.deleted at IS NULL:wsnarravisoronerctesldenktaoc.rseloscostacestois receiving something other than "208488441" in Sproperties ("dealstage")Check what HubSpot actually returns for des latage on these dealsound i Look at processAo iResults lina 390"oroperttes" m sobiectosaetProoertsicco?.hugetProperties() on the HubSpot SDK returns an associative array where values are the raw property values. For dealstaseths would teturn "288489441" That soems tinewoooruniwwme.tatnohonyoetehooeuten csoe doporundes.woschunkeostoneschSdeslsas SdestgetOpportunitiesByIds returns an array keyed by CRM ID (line 388: sresults [Sobject->getId()] = [..• )). Then itAccept allИI 101 Н-0Ax ahyuintltoL• <› CodelAdwotrwe• 0ASVw1 Windeurt Taams 190.5 (1674 chars. 40 fne breskel UTE-R Ai/A enand...
|
PhpStorm
|
faVsco.js – OpportunitySyncTrait.php
|
NULL
|
89215
|
|
89214
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:59:30®8 10Untitled +...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89214
|
|
89213
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89213
|
|
89212
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89212
|
|
89211
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89211
|
|
89210
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89210
|
|
89209
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89209
|
|
89208
|
Undo
Redo
Cut
HomeDMsActivityFilesLater..•More+Sla Undo
Redo
Cut
HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:43®8 10Untitled +...
|
PhpStorm
|
|
NULL
|
89208
|
|
89207
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89207
|
|
89206
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89206
|
|
89205
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89205
|
|
89204
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
PhpStormViewNeweNNCCodeKelucioWindowPVovsco.s#12121 on JY-20963-folProinet vttwwtrweonttollae.oh© Service Test.phppeleteooiccistrai.pngcomposer.isonMmacuryochyict.onyuschedcmmschkeoecordkor.on.uorcoaiuocrd.pntw pmcordselector.on:composer lockdependency-checker.sondew.isorE ids.txinieraison distwwwo.noocea.cokicontoeusyixstoloe.m© PayloadBulider.ohCoseowaisto.osseiwice.on© CrmEntityRepository.phprart noortbarch.obtrayprorected tuncizon processinoor darchlMNnERNAuwErhoesatemaliminny storaadSernSeruicesinstanceor HubsnotintertnceMalicancac.mLog::error( message: Sthis->getLogPrefixO' CRM service is not HubSpot', lMMakere'conConfiguration.d' => Sthis->craConfigurationid,© package-lock.json'serviceClass' => ScrnService::class,=phpstan.neon.distF phpstan-baseline.neo.<>phpunit.xmlTecorntraw_sqLquery.saMAPEAOMS maSourca,fiminny.stageseywttactor0 sonar-proiect propertiesEtest.pvLog::info message: Sthis->getLoqPrefix. * Processing batch','crnConfigurationid' a> Sthis->crnConfiqurationid."batchSize' => count(Sthis->crnids),JSONSUn tieo Dnciom.xmiisvetur.confia.iM:.WEBHOOK_FILTERING_IMPLEMENTAT112113>1h Extemnal Librariesv #Scratches and Consolesv @ Database ConsolesV AEUconsole lEu4 DEAL RISKS (EU)DNIEUAFUIFINLiiranendsOutput file:/Users/lukas/Documentsfiminny_staocs. 2.isoSfilteredIds = Sthis->filterExisting0brects(ScrnConfig, ScrnEntityRepository):if (enpty(SfilteredIds)) 4Log::info( message: Sthis->getlogPrefix(. • No existing obfects found in a'craConfigurationId' = Sthis->craConfigurationIdlreouescedcoun = countschts-scralosService:+.O,Cta outoutul liminnv coportunities1h fiminny staces18 Recult 34ill fiminn staces 2 x Tx.yMbatahaed8 W 10 rows v6G 4TrelenV AEUconsolesumeGii users 1 s 548 msvA liminny@localhostAHSJlocalIm con provider sd MTarobabiitity"I tyoe M14y alosednon.ebred opportunty14268 closedlost0.00 opportunity14269 208488441100.00 opportunity14283 219864918100.00 opportunityAPROD#consoleV ASTAGING14284 2198649178.00 opportunity14290 177303378A.80 onpontunity14292 127583388ArAd onnortuntyconsoleDocker14203 177303379108.00 opportunityMMO7 499010709100.00 opportunity47004 400110740100.00 opportunitycustomuosaravetosA SF (jiminny@localhost)HS_Jocal (jiminny(@localhost)e console (PROD)C) Team.phdA console (EU) Xiid users (EU"A console [STAGINGTeAncdyMeceImportBatch.lcbTrait.pho x812 ×17 ^ V 1804JOIN stages s 1.n<->1: ON s.id = o.stage_idJOIN con_configurations cc 1.n<->1: ON cc.id = s.crn_configuration_icWHERE cc.provider = 'hubspot"AND S-probability = 106031 A9 A31 УЗ У113 A VANU ORAON - OAND o.deleted.at IS NULLAND s.deleted.at IS NULLEynoroatexport previeworobabiuity =188confouraton."orobabTity": 188.88"id". 14768"crn_provider_id": "Closed.ost""arobabry". 8.ee)"type": "opportunity"."eon contsqurattionid".#А". кO"crm provider 1d*: *288488441""probability": 100.00"type": "opportunity"Cancelcooy to e obosro331331331TO0У L7Inu co moy k0ioo.se+0.alsorce oelcdonktooeooonunimAsked 1 questionRun the queno Run this Sol to check what actopportunityclosedstages actuslly returns tor team 416 s contioO so.SELECT s.1d, s.cm provider id, s.probability, s.type, s.cmm configuration 10NERE C.em cooffourattion 1d = 331AND s-probability IN (0, 100)mo s.oeleteolat as wulL:Run that and share the results. If stage 14269 (cra_provider_id = 20843944)*)) appears in the results, then getclosedbealStages () correctly includes it in won [] - and the bug must be in how sproperties ["dealstage") compares against it."adoesn't appear, then somethina is oreventina it.trom being in the query results desote arobabsility a 109 in the 08 2which would mean the crn configuration id on the stage doesn't match contig 331, or deleted at is set, or type isWrondOal -Accept allAxahuineltoL• <> CodelAdhotrweCSVvLITS-9T...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89204
|
|
89203
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89203
|
|
89202
|
Export preview:
[
{
"id": 14267,
Export preview:
[
{
"id": 14267,
"crm_provider_id": "closedwon",
"probability": 100.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14268,
"crm_provider_id": "closedlost",
"probability": 0.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14269,
"crm_provider_id": "208480441",
"probability": 100.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14283,
"crm_provider_id": "219864918",
"probability": 100.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14284,
"crm_provider_id": "219864917",
"probability": 0.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14290,
"crm_provider_id": "177303378",
"probability": 0.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14292,
"crm_provider_id": "177303380",
"probability": 0.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14293,
"crm_provider_id": "177303379",
"probability": 100.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14294,
"crm_provider_id": "177210398",
"probability": 100.00,
"type": "opportunity",
"crm_configuration_id": 331
},
{
"id": 14296,
"crm_provider_id": "182118318",
"probability": 100.00,
"type": "opportunity",
"crm_configuration_id": 331
}
]
Computed
Add columns:
Generated...
|
PhpStorm
|
Export Data
|
NULL
|
89202
|
|
89201
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
PhpStormViewNeweNNCCoocKelucioWindowFV faVsco.|s ~#12121 on JY-20963-fx-lproinet"© Service Test.phpDeleteObjectsTrait.phg=custom.log=laravellogA SF (jiminny@localhostHS_Jocal (jiminny(@localhost)e console (PROD)composer.isonCmkcurayocryict.onaecndemwwDecorouor.ouorcoaiuocrd.pnt© RecordSelector.phg© Activity.phoC) Team.phdA console (EU) X ii users (EU"A console [STAGINGcomposer lockT AnCo yMecedependency-checker.sondew.isor=ldshtyinieraison distwwwo.oocea.cokicontnoensyixstoloc.m© PayloadBulider.ohCoseweaisto.esseiwice.on(0ImportBatch.lcbTrait.pho x© CrmEntityRepository.phprart noortbarch.obtrart1802€ | 412 ½17 A ~ 1804prorected tuncizon processinoor darchlMNnERNAuwErhoesatemaliminny storaad1884JOIN stages s1.n<->1: ON s.id = o.stage_1cJOIN crm_configurations cc 1.nc->1: ON cc.id = s.crn_configuration_icWHERE cc.provider = 'hubspot"AND S-probability = 106AND o.is-won = eAND o.deleted.at IS NULLAND s.deleted.at IS NULL031 A9 A31 УЗ У113 A VMalicancac.mMMakere© package-lock.json=phpstan.neon.distF phpstan-baseline.neo.< phpunit.xmltraw_sqLquery.saMAPEAOMS ma0 sonar-proiect propertiesEtest.pv<> Untitied Diagram.xmlisvetur.confia.iM:.WEBHOOK_FILTERING_IMPLEMENTAT112113>1h Extemnal Librariesv #Scratches and Consolesv @ Database ConsolesV AEUconsole lEu4 DEAL RISKS (EU)DNTEUAFUIFINSernSeruicesinstanceor HubsnotintertnceLog::error( message: Sthis->getLogPrefixO' CRM service is not HubSpot', l'conConfiguration.d' => Sthis->craConfigurationid,'serviceClass' => ScrnService::class,TecornLog::info message: Sthis->getLoqPrefix. * Processing batch','crnConfigurationid' a> Sthis->crnConfiqurationid."batchSize' => count(Sthis->crnids),SfilteredIds = Sthis->filterExisting0brects(ScrnConfig, ScrnEntityRepository)if (enpty(SfilteredIds)) 4Log::info( message: Sthis->getlogPrefix. • No existing obfects found in Jininny, skipping batch'. ['craConfigurationId' = Sthis->craConfigurationIdlreouescedcoun = countschts-scralosService:+.O,CyMbatahaedV AEUconsolesumeGii users 1 s 548 msvA liminny@localhostAHSJlocalta outoutul liminnv coportunities1h fiminny staces18 Recult 34ill fiminn staces 2 x Tx.8 W 10 rows v6G 4TrelenIm con provider sd MTarobabiitity"I tyoe Ti con confiicuratzionsidy14y alosednon.ebred opportunty14268 closedlost0.00 opportunityAPROD#consoleV ASTAGINGconsoleDocker .00 opportunity100.00 opportunity8.00 opportunityA.80 onpontunity14292 127583388ArAd onnortunty14203 177303379MAR.AR onnontun tySELECT o.id, o.is-won, o,probability as opp-probabilityFRon opportunttesJOIN stages s 1.n<->1: ON s.id = o.stage_idHERE O tean d = G6 AND o creared at > 7826-85-78 AND s.orobabioty =188ORDER BY o.created at DESC LTMIT 18:SELECT s.id, s.crn_provider_id, s.probability, s.type, s.crm_configuration_1Fcor stages smheke swcon confqurationd=35alAND Stype=opporcunttyAND S.probability IN (8, 188)AND s.deleted_at IS NULLSIMMO7 499010709100.00 opportunity33147004 400110740100.00 opportunity4MIIIIEynart all data ta hio d MinhaanhTO0У L7Inu co moy k0ioo.seServiceTestalsorce oelcdonkttoooeoooguni+0.Asked 1 questionRun the queno Run this Sol to check what actopportunityclosedstages actuslly returns tor team 416 s contioO so.SELECT s.1d, s.cm provider id, s.probability, s.type, s.cmm configuration 10NERE C.em coofdourattion $a = 33%AND s-probability IN (0, 100)mo s.oeleteolat as wulL:Run that and share the results. If stage 14269 (cra_provider_id = 20843944)*)) appears in the results, then getclosedbealStages () correctly includes it in won [] - and the bug must be in how sproperties ["dealstage") compares against it."adoesn't appear, then somethina is oreventina it.trom being in the query results desote arobabsility a 109 in the 08 2which would mean the crn configuration id on the stage doesn't match contig 331, or deleted at is set, or type isWrondOal -Accept allAxahuineltoL• <> CodelAdhotrwe60%-CSVv1852me lTee hensy...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89201
|
|
89200
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:36®8 10Untitled +...
|
PhpStorm
|
Export Data
|
NULL
|
89200
|
|
89199
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
PhpStormFV faVsco.|s ~Projectvcomposer.isoncomposer lockdependency-checker.sondew.isorE ids.txtinieraison distViewNeweNNC#12121 on JY-20963-fix-inCoocKelucioWindow© ServiceTest.phpMmacuryochyict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpuorcoaiuocrd.pntRecordSelector.phpE custom.logE Iaravellog4 SF [iminny@localhost)A HS.Jocal (jiminny@ocalhost)A console (PROD]© Activity.php© Team,phpA console (EU] * ( users (EU]A console [STAGING)Tx: Auto68jminey ~Huosooswo.noocea.cokicontoeuisyiostoco.© ImportBatchJcbTrait.phpx1802JOIN stages s1.n<->1: ON s.id = o.stage_id031 A9 A31 X3 X113 A© CrmEntityRepository.php1803JOIN crm_configurations cc 1.n<-›1: ON cc.id = s.crn_configuration_idWHERE cc-provider = 'hubspes'rart noor barch.obtray€ | 412 217 A ~ 1804_1805AND S-probability = 100prorected tuncizon processinoor darchlMNnERNAuwErhoesatemajiminny_storage1806AND o.is_won = eAND o.deleted_at IS NULLif (1 ScraService instanceof HubspotInterface) {Malicancac.mLog::error(message: Sthis->getLogPrefixO)AND s.deleted_at IS NULL;• CRM service is not HubSpot', [M Makefile"scaConfigucationld' = Sthis->craConfigurationid,0 package-lockjsonSELECT o.id, o.is_won, O.probability as opp_probability,phpstan.neon.dist1):'serviceClass' => ScrnService::class,F phpstan-baseline.neon< phpunit.xmlTecorntraw_sqLquery.saMAPEAOMS ma0 sonar-proiect propertieso.created_atFRon opportunttesJOIN stages s 1.n<->1: ON s.id = o.stage_idHERE O tean d = G6 AND o creared at > 7826-85-78 AND s.orobabioty =188ORDER BY o.created_at DESC LIMIT 10;Etest.pvwon tieo Oaotom.xmlLog: : info( message: Sthis->getLogPrefix() . ' Processing batch', ["crnConfigurationid' => Sthis->crnConfigurationid,"batchSize' => count(Sthis-›crnids),SELECT s.1d, s.crn_provider_id, s.probability, s.type, s.crn_configuration_id# vetur.config.is112M:WEBHOOK_FILTERING_JMPLEMENTAT1131):> tlh External LibrariesSfilteredIds = $this->filterExisting0bjects(ScrnConfig, ScrnEntityRepository);v E® Scratches and Consoles115~ E Database ConsolesV AEUconsole lEuA DEAL RISKS (EU)if Cenpty(SfilteredIds)) {Log:: info( message: Sthis->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch'. t'graConfigurationid' = Sthis->craConfigurationid,reouescedcoun = countschts-scralos1822Fcor stages sWHERE s.crn_configuration_id = 331AND s.type=opportuntyAND s-probability IN (B, 108)AND s.deleted_at IS NULL:lDNIEUAEUTFINServices+,o, c*v M DatabaseV AEUA console 2 s 845 msti users 1 s 548 msvA liminny@localhost4 HSJJocalV A PROD#consoleV A STAGINGconsole& Dockerta outout8 W 10 rows vJid y %798988879898877989886ul liminnv coportunitiesisstiminny stade500M3s won TResult 34IID opp_probability Y11l Result 47 x Tx.[0)CAA+I stage_prob V18:1001001001001001AR188188@ crn_provider_1d Y188.88 788488447188.88. 288488447100.00 208480441100.00 208480441100.00 208488441100.00 208480441198.88 298489441AA.AA 2AR/RRGK188.80 288488441400 00 209/90/1mcneated at M2826-85-28 17:48412026-05-28 17:48:162026-05-28 17:43:272026-05-28 17:23:172026-05-28 16:49:092026-05-28 16:49:092026-05-28 16:49:082026-05-28 16:384342826-85-28 16:38:312826-85-28 16:33:24TO0У L7Inu co moy kuiooisServiceTestalsorce oelcdonkttoooeoooguni+0.Asked 1 question -Run the queryo Run this Sol to check what actopportunityclosedstages actuslly returns tor team 416 s contioD solSELECT s.id, s.cr_provider_id, s-probability, s.type, s.crn_configuration_idNHERE Chem coofkouration $a =33%AND S-probability IN (8, 100)mo s.oeleteolat as wulL:Run that and share the results. If stage 14269 (crn_previder_1d = "208498441*) appears in the results, then getClosedDealStages () correctly includes it in wont] - and the bug must be in how Sproperties ('dealstage*) compares against it."adoesn't appear, then somethina is oreventina it.trom being in the query results desote arobabsility a 109 in the D8 2which would mean the cre_configuration_id on the stage doesn't match config 331, or deleted_at is set, or type iswrong.0 al -Accept allAx ahyuinelnot• <> CodelAdhotrwecsv ~console (EUJ: SELECT SUM(CASE WHEN o.up...ULL AND s.deleted_.at IS NULL... // completed. (5 minutes ago)18220e litee ensd...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89199
|
|
89198
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:308 10Untitled +...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89198
|
|
89197
|
Search
SELECT s.id, s.crm_provider_id, s.probabili Search
SELECT s.id, s.crm_provider_id, s.probability, s.t...
SELECT * FROM team_features where team_id = 1; SEL...
Customize
Statements...
|
PhpStorm
|
|
NULL
|
89197
|
|
89196
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
PhpStormFV faVsco.|s ~Projectvcomposer.isoncomposer lockdependency-checker.sondew.isorE ids.txtinieraison distViewNeweNNCCoocKelucioWindow#12121 on JY-20963-fix-in© ServiceTest.phpMmacuryochyict.on© CachedCrmServiceDecorator.phpuorcoaiuocrd.pnt© DeleteObjects Trait.phpRecordSelector.php© Activity.php© Team,phpHuosooswo.noocea.cokicontoeuisyiostoco.© ImportBatchJcbTrait.phpx© CrmEntityRepository.phprart noor barch.obtrayprorected tuncizon processinoor darchlMNnERNAuwErhoesatemajiminny_storageMalicancac.mM Makefile0 package-lockjsonphpstan.neon.distF phpstan-baseline.neon< phpunit.xmltraw_sqLquery.saMAPEAOMS ma0 sonar-proiect propertiesEtest.pvSUn tieo Dnciom.xmi# vetur.config.is112M:WEBHOOK_FILTERING_JMPLEMENTAT113> tlh External Librariesv E® Scratches and Consoles115~ E Database ConsolesV AEUconsole lEuA DEAL RISKS (EU)DNIEUAEUTFINif (1 ScraService instanceof HubspotInterface) {Log::error(message: Sthis->getLogPrefixO)• CRM service is not HubSpot', ["scaConfigucationld' = Sthis->craConfigurationid,'serviceClass' = ScrnService::class,1):1802€ | 412 ½17 A ~ 180318041805180618071808DoyV1810E custom.logE IaravellogA console (EUJ XE users (EU)4 SF [iminny@localhost)A console (STAGING)A HS.Jocal (jiminny@localhost)A console (PROD]T AnCo yFROM opportunities o68 jminey~032 49 431 23 213 A VJOIN stages s 1.n<->1: ON s.id = o.stage_idJOIN crn_configurations cc 1.n<-›1: ON cc.id = s.crm_configuration_idWHERE CC-provider = 'hubspet"AND S-probability = 100ANU ORAON- OAND o.deleted_at IS NULLAND s.deleted_at IS NULL;TecornLog: : info( message: Sthis->getLogPrefix() .' Processing batch', l"crnConfigurationId' => Sthis->crnConfigurationid,"batchSize' => count(Sthis-›crnids),1):SfilteredIds = $this->filterExisting0bjects(ScrnConfig, ScrnEntityRepository);if Cenpty(SfilteredIds)) {Log:: info( message: Sthis->getLogPrefix() . • No existing objects found in Jiminny, skipping batch', ['graConfigurationid' = Sthis->craConfigurationid,reouescedcoun = countschts-scralosServices+,o, c*v M DatabaseV AEUA console 2 s 845 msti users 1 s 548 msvA liminny@localhost4 HSJJocalta outoutul liminnv coportunitiesisstiminny stade500M3s won TResult 34V A PROD#consoleV A STAGINGconsole& Docker8 W 10 rows vJid y %798988879898877989886IID opp_probability Yil Result 47 x Tx,CAA+I stage_prob V@ crn_provider_1d Y188.88 78848844718:100100100100100100188188188.88. 288488447100.00 208480441100.00 208480441100.00 208488441100.00 208480441198.88 298489441AA.AA 2AR/RRGK188.80 288488441188.80 288488441console (EUJ: SELECT SUM(CASE WHEN o.up...ULL AND s.deleted_.at IS NULL... // completed. (5 minutes ago)1812Shorooaporyas saceeseoeoo.created.atFROM opportunities oJoin stages s 1..nc-21: ON sd e orstage1dWHERE o.tean_id = 416 AND o.created_at > '2826-05-28' AND s.probability = 100OROE? BY o created.at DESt Biiataerpeoh stagessWHERE s.crn_configuration_id = 331AND Stwpe=opporcunttyAND s.probabil{ty IN (0, 100)ine denletederslIcreated at M2826-85-28 17:48112026-05-28 17:48:162026-05-28 17:43:272026-05-28 17:23:172026-05-28 16:49:092026-05-28 16:49:092026-05-28 16:49:082026-05-28 16:384342026-05-28 16:38:312826-85-28 16:33:24TO0У L7Inu co moy kuiooidServiceTestalsorce oelcdonktooeooonunim+0.Asked 1 questionRun the queryo Run this Sol to check what actopportunityclosedstages actuslly returns tor team 416 s contioD solSELECT s.id, s.crm_provider_id, s-probability, s.type, s.crn_configuration_idNERE C.em cooffourattion 1d = 331AND S-probability IN (8, 100)mo s.oeleteolat as wulL:Run that and share the results. If stage 14269 (crn_previder_1d = "208498441*) appears in the results, then getClosedDealStages () correctly includes it in wont] - and the bug must be in how Sproperties ('dealstage*) compares against it."adoesn't appear, then somethina is oreventina it.trom being in the query results desote arobabsility a 109 in the 08 2which would mean the cre_configuration_id on the stage doesn't match config 331, or deleted_at is set, or type iswrong.0 al -Accept allfask anything (XOL)• <> CodelAdhotrwecsv~d.4o0NMmaid Tosma 1918%2 lITS-9/ens/...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89196
|
|
89195
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:268 10Untitled +...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89195
|
|
89194
|
Project: faVsco.js, menu
HomeDMsActivityFilesLater Project: faVsco.js, menu
HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:218 10Untitled +...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89194
|
|
89193
|
Project: faVsco.js, menu
PhpStormFV faVsco.|s ~Pro Project: faVsco.js, menu
PhpStormFV faVsco.|s ~Projectvcomposer.isoncomposer lockdependency-checker.sondew.isorE ids.txtinieraison distViewNeweNNC#12121 on JY-20963-fix-inCoocKelucioWindow© ServiceTest.phpMmacuryochyict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpuorcoaiuocrd.pntRecordSelector.php© Activity.php© Team,phpE custom.logE IaravellogA console (EU] x] ( users (EU)4 SF [iminny@locahost]A console (STAGING)A HS.Jocal (jiminny@localhost)A console (PROD]HwMo..noocea.cokicontoensytosdoroo.© CrmEntityRepository.phprart noortbarch.obtrayprorected tuncizon processinoor darchl© ImportBatchJcbTrait.phpx68 jminey~Ö32 A9 A31 X3 X113€ | 412 X17 A ~ 17841785MNnERNAuwErhoesatemajiminny_storageMalicancacmaM Makefile0 package-lockjsonphpstan.neon.distF phpstan-baseline.neon< phpunit.xmltraw_sqLquery.saMAPEAOMS ma0 sonar-proiect propertiesEtest.pvwon tieo Oaotom.xml# vetur.config.is112M:WEBHOOK_FILTERING_JMPLEMENTAT113› tlh External Librariesv E® Scratches and Consoles115~ E Database ConsolesV AEUconsole lEuA DEAL RISKS (EU)DNIEUAEUTFINif (1 ScraService instanceof HubspotInterface) {Log::error(message: Sthis->getLogPrefixO)* CRM service is not HubSpot', ("scaConfigucationld' = Sthis->craConfigurationid,'serviceClass' = ScrnService::class,1):TecornLog: : info( message: Sthis->getLogPrefix() .' Processing batch', l"crnConfigurationid' => Sthis->crnConfigurationid,"batchSize' => count(Sthis-›crnids),1):SfilteredIds = $this->filterExisting0bjects(ScrnConfig, ScrnEntityRepository);if Cenpty(SfiLteredIds)) {Log:: info( message: Sthis->getLogPrefix() . • No existing objects found in Jiminny, skipping batch', ['graConfigurationid' = Sthis->craConfigurationid,reouescedcoun = countsthts-scraldsServices+,o, c*v M DatabaseV AEUA console 2 s 845 msti users 1 s 548 msvA liminny@localhost4 HSJJocalV A PROD#consoleV A STAGINGconsole& Dockerta outout8 W 10 rows vJid y %798988879898877989886ul liminnv coportunitiesisstiminny stade500M3s won TResult 34IID opp_probability Yil Result 47 xTx,BA4dI stage_prob V18:100100100100100100188188@ crn_provider_1d Y100.00 208488441108.00 208480441100.00 208480441100.00 208480441100.00 208488441100.00 208480441198.88 298489441AA.AA 2AR/RRGK100 n0 209/90/1400 00 209/90/1console (EUJ: SELECT SUM(CASE WHEN o.up...ULL AND s.deleted_.at IS NULL... // completed. (5 minutes ago)17871788178917911792aelaen molunineFROM opportunities oNonN stadesneos:OM sunide orsthadidJOIN crn_configurations cc 1.n<->1: ON cc.id = s.crn_configuration_idWHERE cc-provider = 'hubspet"AND S-probability = 100AND o.is_won = eAND o.deleted_at IS NULLAND s.deleted_at IS NULLAND o.created at > '2025-10-13*:17941795179618B8-18011802=38)=1807SELECTSUM(CASE WHEN o.updated_at < *2825-10-13' THEN 1 ELSE 0 END) as before_fix,SUM(CASE WHEN O.updated_at >*2025-10-13' THEN 1 ELSE 0 END) as after_fix,COUNT(*) as totalFROM opportunities oJOIN stages s[1.n<->1: ON s.id = o.stage_idJOIN crn_configurations cc 1.n<->1: ON cc.id = s.crn_configuration_idWHERE cc-provider = 'hubspot"AND S-probability = 180AND o.is_won = 0AND o.deleted_at IS NULLAND s.deleted_at IS NULL;Icreated_at V2026-05-28 17:48:162826-85-28 17:48:162026-05-28 17:43:272026-05-28 17:23:172026-05-28 16:49:092026-05-28 16:49:092026-05-28 16:49:082826-05-28 16:38:320054 06. 00 [CREDIT_CARD] 14,2212TO0У L7Inu co moy kurooieServiceTestCascadealsorce oelcdonktooeooonunim+0.Asked 1 question ~o Run this Sol to check what actopportunityclosedstages actuslly returns tor team 416 s contioRun the queryO so.SELECT s.id, s.crm_provider_id, s-probability, s-type, s.crm_configuration_id331AD S.oeleteo.at is NULLRun that and share the results. If stage 14269 (crn_previder_1d = "208498441*) appears in the results, then getClosedDealStages () correctly includes it in wont] - and the bug must be in how Sproperties ['dealstage") compares against it."adoesn't appear, then somethina is oreventina it.trom being in the query results desote arobabsility a 109 in the D8 2which would mean the cre_configuration_id on the stage doesn't match config 331, or deleted_at is set, or type iswrong.0 al -Accept allAsk anything (XOL)• <> CodelAdhotrwecsv ~d.4o0MMaid Tosma 1918%2 lITE9 ensd....
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89193
|
|
89192
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
32
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89192
|
|
89191
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
32
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89191
|
|
89190
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
HomeDMsActivityFilesLater..•More+Slack(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesP Channel Overview7 RefinementsQ Files* PinsBookmarksP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:158 10Untitled +...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89190
|
|
89189
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89189
|
|
89188
|
PhpStormEV faVsco,ls ~ProjectvViewNeweNNCCooc#1212 PhpStormEV faVsco,ls ~ProjectvViewNeweNNCCooc#12121 on JY-20963-fix-InWindow© ServiceTest.php© HubspotAppUninstalLJob.fimportaccountostonto© ImportBatchJobTrait.phpemoorcontcororon©ImportOpportunityBatch.pUmacurayochict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpRecordSelector.php© Team,phpHuosooswosnoocxeacokecontnoensytscorooe© ImportBatchJcbTrait.phpx© ProcessinternalWethookEcrmantityRepos.tory.phprart noor barch.obtrayprorected tuncizon process noor sarchewaeweaweocsE SalesforceC Autolon Delavedtocrm oho© CheckAndRetryRemoteMatchCreateFollowuoachmiy ohdC) ereateNotes onoC MatchActvitiestoNeweooor©MatchActivityCrmData.phpE [EMAIL]© SaveTranscription.php© SetupLayout.php©SyncActivity.php© SyncFieidMetadata.php© SyncHubspotObjects.php© SyncLeads.php© SyncObjects.php© SyncOpportunities.Job.php© SyncOpportunity.php© SyncProfileMetadata.php@ SvncTeamFieldsJob.ohoif (1 ScrnService instanceof HubspotInterface) (Log::error(message: Sthis->getLogPrefixO)* CRM service is not HubSpot', ("scaConfigucationld' = Sthis->craConfigurationid,'serviceClass' => ScrnService::class,1):Tecorn1081098 aLog: : info( message: Sthis->getLogPrefix() .' Processing batch', l"crnConfigurationid' => Sthis->crnConfigurationid,"batchSize' => count(Sthis-›crnids),1):SfilteredIds = $this->filterExisting0bjects(ScrnConfig, ScrnEntityRepository);if Cenpty(SfiLteredIds)) {Log:: info( message: Sthis->getLogPrefix(). ' No existing objects found in Jininny, skipping batch', l'graConfigurationid' = Sthis->craConfigurationid,reouescedcoun = countsthts-scraosServices+,o, c*v M DatabaseV AEUA console 2 s 845 msti users 1 s 548 msAliminny@localhost4 HSJJocal4 SFV A PROD#consoleV A STAGINGconsole& Dockerta outout8 W 10 rows vJid y %798988879898877989886il liminny coportunitiesisstiminny stadeResult 34M3s won TIID opp_probability Yil Result 47 x Tx,BA4dI stage_prob V@ crn_provider_1d Y100.00 208488441108.00 20848044118:1001001001001001AR188188188.80 288488441100.00 208488441100.00 208480441100.00 2084804411AA.AA 2AR/RRGK100 n0 209/90/1400 00 209/90/1CANEAlO ISTN: CSISAT GHMICAGE WHEM AIEATET ANG CANGINISRIG NIIITICAMNIStANT mimitos saayE custom.logE Iaravellog4 console (EU] x] ( users (EU)A console (STAGING)D6000 0Tee AncoytE cc.provider = "hubspot"ID s-probability = 100ID o.is_won = 0ID o.deleted_at IS NULLlu s.delered ar as nuLuluo.crcared ar >2825-18-13A HS.Jocal (jiminny@localhost)A console (PROD]68 Jiminny~031 A9 A31 X3 X13 AECTSUMCCASE WHEN O.updated_at < ^2825-16-13' THEN 1 ELSE 0 END) as before_fix,SUMCCASE WHEN O.updated_at >= *2025-18-13* THEN 1 ELSE 0 END) as after_fix,COUNT(*) as total1.n<->1: ON s.id = o.stage_idcrm_configurations cc .nc->l: ON cc.1d = s.crm_configuration_1dIE cc.provider = 'hubspot"sunnohabtiuty taal1D o.is_won = 0ID o.deleted_at IS NULLID s.deleted_at IS NULL;18161812=1814ECT o.1d, o.is_won, O.probability as opp_probability,s.probability as stage_prob, s.crn_provider_id,o.created_attopportunities o1 stages s 1.n<-›1: ON s.id = o.stage_idtE o.tean,id = 416 AND o.created_at > 2026-85-28' AND S.probability = 100ER BY O.created_at DESC LIMIT 10:|TO0У L7inu co moy kuioo.ServiceTestCascadeworeewerweeiealsorce oelcdonktooeooonunim+0.Roteetaoed se uallm tetuen ar mintime,Asked 1 question -Run the queryo kun this sol to check wnat getoppor unityclosedstages actually returns vor team 410'$ coniigO soSELECT s.id, s.crm_provider_id, s-probability, S-type, s.crn_configuration_idRid s.oelerco ar as nuLLRun that and share the results. If stage 14269 (cra_provider_1d - "28843241*) appears in the results, then getClosedDealStages () correctly includes it in won() - and the bug must be in how Sproperties ('dealstage') compares against it.tit doesn't appear, then something is preventing it from being in the query results despite probabi1ity = 109 in the DB -which would mean the crn._configuration_id on the stage doesn't match config 331, or deleted_at is set, or type is6 al -Accept allAsk anything (atoL)• • code)3Adaptivecsv ~Icreated_at V2026-05-28 17:48:162826-85-28 17:48:16Dank.ACrDe47:/2022826-85-28 17:23:172826-85-28 16:49:892026-05-28 16:49:092026-05-28 16:49:082926-05-28 16:79•340054 06. 00 [CREDIT_CARD] 14,2212W Windsurf Teams1916.27 lTe e ensd,...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89188
|
|
89187
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:58:118 10Untitled +...
|
PhpStorm
|
faVsco.js – console [EU]
|
NULL
|
89187
|
|
89186
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89186
|
|
89185
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89185
|
|
89184
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89184
|
|
89183
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89183
|
|
89182
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89182
|
|
89181
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89181
|
|
89180
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
PhpStormEV faVsco,ls ~ProjectvViewCooc#12121 on JY-20963-fix-InWindow© ServiceTest.php© HubspotAppUninstalLJob.fimportaccountostonto© ImportBatchJobTrait.phpemoorcontconcron©ImportOpportunityBatch.pUmacurayochict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpRecordSelector.php© Team,phphuosooswo..noocxea.cokecontrooenisynostorec.Coseowaisto.osseiwice.onImportBatchJcbTrait.phpx© ProcessinternalWethookEcrmantityRepos.tory.phprart noortbarch.obtrayprorected tuncizon process noor sarchewaeweaweocsE SalesforceC Autolon Delavedtocrm oho© CheckAndRetryRemoteMatchCcreatefollowuoactmiy oho(C)ereateNotes ohoC MatchActvitiestoNeweooor©MatchActivityCrmData.phpE Notee biectono© SaveActivity.php© SaveTranscription.php© SetupLayout.php©SyncActivity.php© SyncFieidMetadata.php© SyncHubspotObjects.php© SyncLeads.php© SyncObjects.php© SyncOpportunities.Job.php© SyncOpportunity.php© SyncProfileMetadata.phpe GunaTosmSiahe lah nhoif (1 ScrnService instanceof HubspotInterface) (Log::error(message: Sthis->getLogPrefixO)* CRM service is not HubSpot', ["scaConfigucationld' = Sthis->craConfigurationid,'serviceClass' = ScrnService::class,1):TecornLog: : info( message: Sthis->getLogPrefix() .' Processing batch', l"crnConfigurationid' => Sthis->crnConfigurationid,"batchSize' => count(Sthis-›crnids),E BE E1):SfilteredIds = $this->filterExisting0bjects(ScrnConfig, ScrnEntityRepository);if Cenpty(SfilteredIds)) {Log:: info( message: Sthis->getLogPrefix(). ' No existing objects found in Jininny, skipping batch', l'graConfigurationid' = Sthis->craConfigurationid,reouescedcoun = countsthts-scraos120Services+,ocv Moatabasd@ Outpurt10 rowsDidy799900419988851jiminny.opportunitiesiid fiminny stageE Result: 34Resule 47 x Txgis_won Yopp_probability YI stage_prob V4 console 2 s 845 msell users 1 s 548 ms#liminny@localhostAHS JocalA SFV A PRODA consoleV A STAGING& consoleDockersaalac "TH:[CREDIT_CARD] crn_provider_id P100.00 208480441100.00 208480441108.00 208480441100100.00 208488441100.00 288488441100.00 208488441108.00 208480441Maguaa nagkeollole MursreSMWASSWNoTANDeonwesanswilcomolatar.lkminutas.oE custom.logE Iaravellogconsole (EU]xE users (EU)4 SF [iminny@locahost]A console (STAGING)D6000 0TE Alco ytE cc.provider = "hubspot"ID s.probability = 100ID o.is_won = 0ID o.deleted_at IS NULLID s.deleted_at IS NULL1D o.created_at > '2025-10-13*:A HS.Jocal (jiminny@localhost)A console (PROD]68 jminey~031 49 A31 23 213 A VECTSUMCCASE WHEN O.updated_at < ^2825-18-13' THEN 1 ELSE 0 END) as before_fix,SUMCCASE WHEN O.updated_at >= *2025-10-13* THEN 1 ELSE 0 END) as after_fix,COUNT(*) as total1 stages s 1.n<->1: ON s.id = o.stage_idcon conSiqurations ce1.nc-s1: OM cc.idins.oon consiauratsiion jaIE cc.provider = 'hubspot"sunnohabtiuty taal1D o.is_won = 0ID o.deleted_at IS NULLID s.deleted_at IS NULL;[CREDIT_CARD]=1814ECT o.1d, o.is_won, O.probability as opp_probability,s.probability as stage_prob, s.crn_provider_id,o.created_attopportunities o1 stages s 1.n<-›1: ON s.id = o.stage_idE o.tean_id = 416 AND o.created_at > '2026-85-28' AND S-probability = 100ER BY O.created_at DESC LIMIT 10;created_at Y2826-05-28 17:48:162026-05-28 17:48:162826-05-28 17:43:272024-95.28 17:27:172004-A6-20 14:40-902926-05-28 16:49:692826-05-28 16:49:082026-05-28 16:38:322826-85-28 16:38:31DankrACDe 1X2.2Thu 28 May 20:57:12U ServiceTest ~Salesforce Service Telory cre provider ealsorce oelcdonkoturooeooonurcoortStaoes sets cre cont louration id on stages. But look at the ucnteon reate n coort Stages - the search keviSstage = Sthis->config-»stages()-swithTrashed()-›update0rCreateliwssloromoatyeeeSthis-›config-»stages() scopes to cre_configuration_1d = 331, so the upsert correctly finds/creates within that config.Thattetndo grep =2 *5-n "crm_configuration_id™ /Users/lukas/jiminny/app/database/nigrations/ -r | grep -1 "stage"RuntalskioAccept allAck nauth no lNAtCode# AdaptiveASVw11$00WW Wndsurf Teamns 113:1 UTF-8 P 4 spaco-...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89180
|
|
89179
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:57:128 10Untitled +...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89179
|
|
89178
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:56:53®8 10Untitled +...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89178
|
|
89177
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89177
|
|
89176
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89176
|
|
89175
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89175
|
|
89174
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:56:508 10Untitled +...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89174
|
|
89173
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:56:498 10Untitled +...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89173
|
|
89172
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
12
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Jobs\Crm\Hubspot;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Support\Facades\Log;
use Jiminny\Contracts\Services\Crm\Provider\HubspotInterface;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Repositories\Crm\CrmConfigurationRepository;
use Jiminny\Repositories\Crm\CrmEntityRepository;
use Jiminny\Services\Crm\Hubspot\BatchSyncRedisService;
use Jiminny\Services\ResolveTeamCrmConnection;
/**
* Shared logic for HubSpot batch import jobs.
*
* Provides common functionality for importing batches of HubSpot objects (deals, contacts, companies)
* with consistent error handling, logging, and failure recovery mechanisms.
*
* Failure Handling Strategy:
*
* 1. SYSTEM-LEVEL FAILURES (HubSpot API down, DB connection lost, timeout):
* - Exception propagates out of handle()
* - Laravel retries the job up to $tries times with $backoff delays
* - If all retries exhausted, failed() requeues ALL IDs back to Redis
* - Next SyncObjects cycle will pick them up and retry
*
* 2. DATA-LEVEL FAILURES (per-object exceptions during import):
* - Caught inside the per-object loop in import*BatchByIds() methods
* - Indicate permanent issues: DB constraints, corrupt data, unmappable values
* - Retrying won't fix them - logged with specific error per ID
* - NOT requeued to avoid infinite retry loops
* - Require manual investigation and data correction
*
* Note: Objects intentionally skipped (missing dependencies like account, unknown pipeline/stage)
* return null and are not considered failures - they simply cannot be imported until dependencies exist.
*/
trait ImportBatchJobTrait
{
private const string OBJECT_TYPE_CONTACT = 'contact';
private const string OBJECT_TYPE_COMPANY = 'company';
private const string OBJECT_TYPE_DEAL = 'deal';
private const int LOCK_EXPIRES_AFTER_SECONDS = 360;
private const string [ENV_SECRET];
private int $crmConfigurationId;
private array $crmIds;
abstract protected function getObjectType(): string;
abstract protected function getLogPrefix(): string;
abstract protected function importBatch(HubspotInterface $crmService, array $crmIds): array;
/**
* Serialize HubSpot import batches per CRM configuration across all object types.
*
* `shared()` makes the lock key omit the job class, so ImportOpportunityBatch,
* ImportContactBatch and ImportAccountBatch for the same crm_configuration_id
* contend on a single lock. This prevents concurrent imports from causing
* gap-lock contention on the `accounts` and `contacts` unique indexes.
*
* Duplicates are dropped (not released back to the queue). On SQS, each release
* increments the message's ApproximateReceiveCount, which Laravel reads as
* $job->attempts(). With $tries = 3 and lock-holders that can run for >45s,
* releasing duplicates causes them to exhaust their attempt budget while waiting
* and trip MaxAttemptsExceededException without ever running. Dropping is safe
* here because SyncObjects rediscovers IDs on every cycle, so any IDs carried
* by a dropped duplicate will be re-batched on the next sync.
*/
public function middleware(): array
{
return [
new WithoutOverlapping(self::LOCK_KEY_PREFIX . $this->crmConfigurationId)
->shared()
->expireAfter(self::LOCK_EXPIRES_AFTER_SECONDS)
->dontRelease(),
];
}
protected function processImportBatch(
ResolveTeamCrmConnection $resolveTeamCrmConnection,
CrmConfigurationRepository $crmConfigurationRepository,
CrmEntityRepository $crmEntityRepository
): void {
$crmConfig = $crmConfigurationRepository->findById($this->crmConfigurationId);
if ($crmConfig === null) {
Log::error($this->getLogPrefix() . ' CRM configuration not found', [
'crmConfigurationId' => $this->crmConfigurationId,
]);
return;
}
$crmService = $resolveTeamCrmConnection->resolveForTeam($crmConfig->getTeam());
if (! $crmService instanceof HubspotInterface) {
Log::error($this->getLogPrefix() . ' CRM service is not HubSpot', [
'crmConfigurationId' => $this->crmConfigurationId,
'serviceClass' => $crmService::class,
]);
return;
}
Log::info($this->getLogPrefix() . ' Processing batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'batchSize' => count($this->crmIds),
]);
$filteredIds = $this->filterExistingObjects($crmConfig, $crmEntityRepository);
if (empty($filteredIds)) {
Log::info($this->getLogPrefix() . ' No existing objects found in Jiminny, skipping batch', [
'crmConfigurationId' => $this->crmConfigurationId,
'requestedCount' => count($this->crmIds),
]);
return;
}
$startTime = microtime(true);
$result = $this->importBatch($crmService, $filteredIds);
$durationMs = round((microtime(true) - $startTime) * 1000, 2);
$successCount = $result['success_count'] ?? \count($result['success'] ?? []);
$failedIds = $result['failed_ids'] ?? [];
$skippedCount = count($this->crmIds) - count($filteredIds);
Log::info($this->getLogPrefix() . ' Batch completed', [
'crmConfigurationId' => $this->crmConfigurationId,
'success' => $successCount,
'failed' => count($failedIds),
'skipped' => $skippedCount,
'requested' => count($this->crmIds),
'processed' => count($filteredIds),
'duration_ms' => $durationMs,
]);
if (! empty($failedIds)) {
Log::error($this->getLogPrefix() . ' Data-level failures require investigation', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedCount' => \count($failedIds),
'failedIds' => $failedIds,
'errors' => $result['errors'] ?? [],
]);
}
}
/**
* Called by Laravel after all $tries are exhausted.
*
* System-level failure (HubSpot API down, timeout, OOM) - the entire handle() threw
* an unhandled exception on every attempt. Requeue ALL IDs back to Redis so the next
* SyncObjects cycle picks them up.
*
* This does NOT fire for data-level failures (those are caught in the per-object loop
* and logged without retrying).
*
* Requeue Strategy:
* - Each ID is individually requeued to Redis using SADD (automatic deduplication)
* - If requeue fails for specific IDs, they are logged as permanently lost
* - Redis requeue failures are rare (Redis connection issues) but critical
*/
protected function requeueFailedBatch(\Throwable $exception): void
{
$redisService = app(BatchSyncRedisService::class);
Log::error($this->getLogPrefix() . ' Job failed after all retries, requeuing IDs', [
'crmConfigurationId' => $this->crmConfigurationId,
'idCount' => \count($this->crmIds),
'error' => $exception->getMessage(),
]);
$requeued = 0;
$failedToRequeue = [];
foreach ($this->crmIds as $crmId) {
try {
$redisService->collectObjectIdToBatch(
$this->getObjectType(),
(string) $crmId,
$this->crmConfigurationId,
'all'
);
$requeued++;
} catch (\Throwable $e) {
$failedToRequeue[] = $crmId;
Log::warning($this->getLogPrefix() . ' Failed to requeue ID', [
'crmConfigurationId' => $this->crmConfigurationId,
'crmId' => $crmId,
'error' => $e->getMessage(),
]);
}
}
Log::info($this->getLogPrefix() . ' Requeue completed after job failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'requeued' => $requeued,
'failedToRequeue' => \count($failedToRequeue),
'total' => \count($this->crmIds),
]);
if (! empty($failedToRequeue)) {
Log::critical($this->getLogPrefix() . ' Permanently lost IDs after requeue failure', [
'crmConfigurationId' => $this->crmConfigurationId,
'failedIds' => $failedToRequeue,
]);
}
}
private function filterExistingObjects(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$objectType = $this->getObjectType();
if ($objectType === self::OBJECT_TYPE_CONTACT) {
return $this->filterExistingContacts($crmConfig, $crmEntityRepository);
}
if ($objectType === self::OBJECT_TYPE_COMPANY) {
return $this->filterExistingAccounts($crmConfig, $crmEntityRepository);
}
return $this->crmIds;
}
private function filterExistingContacts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingContacts = $crmEntityRepository->getExistingContactCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingContacts);
return array_values($existingIds);
}
private function filterExistingAccounts(Configuration $crmConfig, CrmEntityRepository $crmEntityRepository): array
{
$existingAccounts = $crmEntityRepository->getExistingAccountCrmIds($crmConfig, $this->crmIds);
$existingIds = array_intersect($this->crmIds, $existingAccounts);
return array_values($existingIds);
}
}
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Code changed:
Hide
Sync Changes
Hide This Notification
31
9
31
3
113
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM team_features where team_id = 1;
SELECT * FROM teams WHERE name LIKE '%Vixio%'; # 340,270,11922
SELECT * FROM users WHERE team_id = 340; # 12015
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 340
and sa.provider = 'salesforce';
# and sa.provider = 'salesloft';
select * from crm_fields where crm_configuration_id = 270 and object_type = 'event';
# 125558 - Event Type - Event_Type__c
# 125552 - Event Status - Event_Status__c
SELECT * FROM sidekick_settings WHERE team_id = 340;
SELECT * FROM crm_field_values WHERE crm_field_id in (125552);
select * from activities where crm_configuration_id = 270
and type = 'conference' and crm_provider_id IS NOT NULL
and actual_start_time > '2024-09-16 09:00:00' order by scheduled_start_time;
SELECT * FROM activities WHERE id = 20871677;
SELECT * FROM crm_field_data WHERE activity_id = 20871677;
select * from crm_layouts where crm_configuration_id = 270;
select * from crm_layout_entities where crm_layout_id in (886,887);
SELECT * FROM crm_configurations WHERE id = 270;
select * from playbooks where team_id = 340; # 1514
select * from groups where team_id = 340;
SELECT * FROM crm_fields WHERE id IN (125393, 125401);
select g.name as 'team name', p.name as 'playbook name', f.label as 'activity type field' from groups g
join playbooks p on g.playbook_id = p.id
join crm_fields f on p.activity_field_id = f.id
where g.team_id = 340;
SELECT * FROM activities WHERE uuid_to_bin('0c180357-67d2-419e-a8c3-b832a3490770') = uuid; # 20448716
select * from crm_field_data where object_id = 20448716;
select * from activities where crm_configuration_id = 270 and provider = 'salesloft' order by id desc;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%CybSafe%'; # 343,273,12008
select * from opportunities where team_id = 343;
select * from opportunities where team_id = 343 and crm_provider_id = '18099102526';
select * from opportunities where team_id = 343 and account_id = 945217482;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
select * from accounts where team_id = 343 order by name asc;
select * from stages where crm_configuration_id = 273 and type = 'opportunity';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Voyado%'; # 353,283,12143
SELECT * FROM activities WHERE crm_configuration_id = 283 and account_id = 3777844 order by id desc;
SELECT * FROM accounts WHERE team_id = 353 AND name LIKE '%Salesloft%';
SELECT * FROM activities WHERE id = 20717903;
select * from participants where activity_id IN (20929172,20928605,20928468,20926272,20926271,20926270,20926269,20916499,20916454,20916436,20916435,20900015,20900014,20900013,20897312,20897243,20897241,20897237,20897232,20897229,20893648,20893231,20893230,20893229,20893228,20889784,20885039,20885038,20885037,20885036,20885035,20882728,20882708,20882703,20882702,20869828,20869811,20869806,20869801,20869799,20869798,20869796,20869795,20869794,20869761,20869760,20869759,20868688,20868687,20850340,20847195,20841710,20833967,20827021,20825307,20825305,20825297,20824615,20824400,20823927,20821760,20795588,20794233,20794057,20793710,20785811,20781789,20781394,20781307,20762651,20758453,20758282,20757323,20756643,20756636,20756629,20756627,20756606,20756605,20756604,20756603,20756602,20756600,20756599,20756598,20756595,20756594,20756589,20756587,20756577,20756573,20748918,20748386,20748385,20748384,20748383,20748382,20748381,20748380,20748379,20748377,20748375,20748373,20743301,20717905,20717904,20717903,20717901,20717899);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 353
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%modern world business solutions%'; # 345,275,12016, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('3921d399-3fef-4609-a291-b0097a166d43') = uuid;
# id: 20940638, user: 12022, contact: 5305871
SELECT * FROM activity_summary_logs WHERE activity_id = 20940638;
select * from contacts where team_id = 345 and crm_provider_id = '30891432415' order by name asc; # 5305871
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 345
and sa.provider = 'hubspot';
select * from users where team_id = 345 and id = 12022;
SELECT * FROM crm_profiles WHERE user_id = 12022;
SELECT * FROM participants WHERE activity_id = 20940638;
SELECT * FROM users u
JOIN crm_profiles cp ON u.id = cp.user_id
WHERE u.team_id = 345;
select * from contacts where team_id = 345 and crm_provider_id = '30880813535' order by name desc; # 5305871
select * from team_features where team_id = 345;
SELECT * FROM activities WHERE uuid_to_bin('11701e2d-2f82-4dab-a616-1db4fad238df') = uuid; # 21115197
SELECT * FROM participants WHERE activity_id = 20897406;
SELECT * FROM activities WHERE uuid_to_bin('63ba55cd-1abc-447d-83da-0137000005b7') = uuid; # 20953912
SELECT * FROM activities WHERE crm_configuration_id = 275 and provider = 'ringcentral' and title like '%1252629100%';
SELECT * FROM activities WHERE id = 20946641;
SELECT * FROM crm_profiles WHERE user_id = 10211;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120,97,10984, [EMAIL]
SELECT * FROM opportunities WHERE crm_configuration_id = 97 and crm_provider_id = '006N1000006c5PpIAI';
select * from stages where crm_configuration_id = 97 and type = 'opportunity';
select * from opportunities where team_id = 120;
select * from crm_configurations crm join teams t on crm.id = t.crm_id
where 1=1
AND t.current_billing_plan IS NOT NULL
AND crm.auto_sync_activity = 0
and crm.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Exclaimer%'; # 270,205,10053,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 270
and sa.provider = 'salesforce';
SELECT * FROM activities WHERE uuid_to_bin('b54df794-2a9a-4957-8d80-09a600ead5f8') = uuid; # 21637956
SELECT * FROM crm_profiles WHERE user_id = 11446;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cygnetise%'; # 372,300,12554, [EMAIL]
select * from playbooks where team_id = 372;
select * from crm_fields where crm_configuration_id = 300 and object_type = 'event'; # 141340
SELECT * FROM crm_field_values WHERE crm_field_id = 141340;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 372
and sa.provider = 'salesforce';
select * from crm_profiles where crm_configuration_id = 300;
SELECT * FROM crm_configurations WHERE team_id = 372;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Planday%'; # 291,242,11501,[EMAIL]
SELECT * FROM opportunities WHERE team_id = 291 and crm_provider_id = '006bG000005DO86QAG'; # 3207756
select * from crm_field_data where object_id = 3207756;
SELECT * FROM crm_fields WHERE id = 111834;
select f.id, f.crm_provider_id AS field_name, f.label, fd.object_id AS dealId, fd.value
FROM crm_fields f
JOIN crm_field_data fd ON f.id = fd.crm_field_id
WHERE f.crm_configuration_id = 242
AND f.object_type = 'opportunity'
AND fd.object_id IN (3207756)
ORDER BY fd.object_id, fd.updated_at;
SELECT * FROM crm_configurations WHERE auto_connect = 1;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150,[EMAIL]
select * from group_deal_risk_types drgt join groups g on drgt.group_id = g.id
where g.team_id = 187;
select * from `groups` where team_id = 187;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 187
and sa.provider = 'salesforce';
# Destination - 98870 - Destination__c
# Stage - 79014 - StageName
# Land Arrangement - 98856 - Land_Arrangement__c
# Flight - 98848 - Flight__c
# Last activity date - 98812 - LastActivityDate
# Last modified date - 98809 - LastModifiedDate
# Last inbound mail timestamp - 99151 - Last_Inbound_Mail_Timestamp__c
# next call - 98864 - Next_Call__c
select * from crm_fields where crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
select * from opportunities where team_id = 187 and name LIKE'%Muriel Sal%';
select * from opportunities where team_id = 187 and user_id = 9951 and is_closed = 0;
select * from activities where opportunity_id = 3538248;
SELECT * FROM crm_profiles WHERE user_id = 8150;
select * from deal_risks where opportunity_id = 3538248;
select * from teams where crm_id IS NULL;
SELECT opp.id AS opportunity_id,
u.group_id AS group_id,
MAX(
CASE
WHEN a.type IN ("sms-inbound", "sms-outbound") THEN a.created_at
ELSE a.actual_end_time
END) as last_date
FROM opportunities opp
left join activities a on a.opportunity_id = opp.id
inner join users u on opp.user_id = u.id
where opp.user_id IN (9951)
AND opp.is_closed = 0
and a.status IN ('completed', 'received', 'delivered') OR a.status IS NULL
group by opp.id;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Cybsafe%'; # 343,301,12008,[EMAIL]
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_profiles WHERE crm_configuration_id = 301;
SELECT * FROM contacts WHERE id = 6612363;
SELECT * FROM accounts WHERE id = 4235676;
SELECT * FROM opportunities WHERE crm_configuration_id = 301 and crm_provider_id = 32983784868;
select * from opportunity_stages where opportunity_id = 4503759;
# SELECT * FROM opportunities WHERE id = 4569937;
select * from activities where crm_configuration_id = 301;
SELECT * FROM activities WHERE uuid_to_bin('d3b2b28b-c3d0-4c2d-8ed0-eef42855278a') = uuid; # 26330370
SELECT * FROM participants WHERE activity_id = 26330370;
SELECT * FROM teams WHERE id = 375;
select * from playbooks where team_id = 375;
select * from stages where crm_configuration_id = 301 and type = 'opportunity';
select * from teams;
select * from contact_roles;
SELECT * FROM opportunities WHERE team_id = 343 and user_id = 12871 and close_date >= '2024-11-01';
select * from users u join crm_profiles cp on cp.user_id = u.id where u.team_id = 343;
SELECT * FROM crm_field_data WHERE object_id = 3771706;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 343
and sa.provider = 'hubspot';
SELECT * FROM crm_fields WHERE crm_configuration_id = 301 and object_type = 'opportunity'
and crm_provider_id LIKE "%traffic_light%";
SELECT * FROM crm_field_values WHERE crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531);
SELECT fd.* FROM opportunities o
JOIN crm_field_data fd ON o.id = fd.object_id
WHERE o.team_id = 343
# and o.user_id IS NOT NULL
and fd.crm_field_id IN (144020,144048,144111,144113,144126,144481,144508,144531)
and fd.value != ''
order by value desc
# group by o.id
;
SELECT * FROM opportunities WHERE id = 3769843;
SELECT * FROM teams WHERE name LIKE '%Tour%'; # 187,209,8150, [EMAIL]
SELECT * FROM crm_layouts WHERE crm_configuration_id = 209;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 682;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding Circle%'; # 220,177,8603,[EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('7a40e99b-3b37-4bb1-b983-325b81801c01') = uuid; # 23139839
SELECT * FROM opportunities WHERE id = 3855992;
SELECT * FROM users WHERE name LIKE '%Angus Pollard%'; # 8988
SELECT * FROM teams WHERE name LIKE '%Story Terrace%'; # 379, 307, 12894
SELECT * FROM crm_fields WHERE crm_configuration_id = 307 and object_type != 'opportunity';
select * from contacts where team_id = 379 and name like '%bebro%'; # 5874411, crm: 77229348507
SELECT * FROM crm_field_data WHERE object_id = 5874411;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 379
and sa.provider = 'hubspot';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%mentio%'; # 117, 94, 6371, [EMAIL]
SELECT * FROM activities WHERE uuid_to_bin('82939311-1af0-4506-8546-21e8d1fdf2c1') = uuid;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Tourlane%'; # 187, 209, 8150, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 187 and crm_provider_id = '006Se000008xfvNIAQ'; # 3537793
select * from generic_ai_prompts where subject_id = 3537793;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lunio%'; # 120, 97, 10984, [EMAIL]
SELECT * FROM crm_configurations WHERE id = 97;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 97;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 355;
SELECT * FROM crm_fields WHERE id = 32682;
select cfd.value, o.* from opportunities o
join crm_field_data cfd on o.id = cfd.object_id and cfd.crm_field_id = 32682
where team_id = 120
and cfd.value != ''
;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 120
and sa.provider = 'salesforce';
select * from opportunities where team_id = 120 and crm_provider_id = '006N1000007X8MAIA0';
SELECT * FROM crm_field_data WHERE object_id = 2313439;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 410;
SELECT * FROM teams WHERE name LIKE '%Local Business Oxford%';
select * from scorecards where team_id = 410;
select * from scorecard_rules;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Funding%'; # 220, 177, 8603, [EMAIL]
select * from activities a
join opportunities o on a.opportunity_id = o.id
join users u on o.user_id = u.id
where a.crm_configuration_id = 177 and a.type LIKE '%email-out%'
# and a.actual_end_time > '2024-12-16 00:00:00'
# and o.remotely_created_at > '2024-12-01 00:00:00'
# and u.group_id = 1014
and u.id = 9021
order by a.id desc;
SELECT * FROM opportunities WHERE id in (3981384,4017346);
SELECT * FROM users WHERE team_id = 220 and id IN (8775, 11435);
select * from users where id = 9021;
select * from inboxes where user_id = 9021;
select * from inbox_emails where inbox_id = 1349 and email_date > '2024-12-18 00:00:00';
select * from email_messages where team_id = 220
and orig_date > '2024-12-16 00:00:00' and orig_date < '2024-12-19 00:00:00'
and subject LIKE '%Personal%'
# and 'from' = '[EMAIL]'
;
select * from activities a
join opportunities o on a.opportunity_id = o.id
where a.user_id = 9021 and a.type LIKE '%email-out%'
and a.actual_end_time > '2024-12-18 00:00:00'
and o.user_id IS NOT NULL
and o.remotely_created_at > '2024-12-01 00:00:00'
order by a.id desc;
SELECT * FROM opportunities WHERE team_id = 220 and name LIKE '%Right Car move Limited%' and id = 3966852;
select * from activities where crm_configuration_id = 177 and type LIKE '%email%' and opportunity_id = 3966852 order by id desc;
select * from team_settings where name IN ('useCloseDate');
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Hurree%'; # 104, 81, 6175, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 104 and name = 'PropOp';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 104
and sa.provider = 'hubspot';
select * from crm_configurations where last_synced_at > '2025-01-19 01:00:00'
select * from teams where crm_id IS NULL;
select t.name as 'team', u.name as 'owner', u.email, u.phone
from teams t
join activity_providers ap on t.id = ap.team_id
join users u on t.owner_id = u.id
where 1=1
and t.status = 'active'
and ap.is_enabled = 1
# and u.status = 1
and ap.provider = 'ms-teams';
select * from crm_configurations where provider = 'bullhorn'; # 344
SELECT * FROM teams WHERE id = 442; # 14293
select * from users where team_id = 442;
select * from social_accounts sa where sa.sociable_id = 14293;
select * from invitations where team_id = 442;
# [PASSWORD_DOTS]
SELECT * FROM users WHERE email LIKE '%[EMAIL]%'; # 14022
SELECT * FROM teams WHERE id = 429;
select * from opportunities where team_id = 429 and crm_provider_id IN (16157415775, 22246219645);
select * from activities where opportunity_id in (4340436,4353519);
select * from transcription where activity_id IN (25630961,25381771);
select * from generic_ai_prompts where subject_id IN (4353519);
SELECT
a.id as activity_id,
a.opportunity_id,
a.type as activity_type,
a.language,
CONCAT(a.title, a.description) AS mail_content,
e.from AS mail_from,
e.to AS mail_to,
e.subject AS mail_subject,
e.body AS mail_body,
p.type as prompt_type,
p.status as prompt_status,
p.content AS prompt_content,
a.actual_start_time as created_at
FROM activities a
LEFT JOIN ai_prompts p ON a.transcription_id = p.transcription_id AND p.deleted_at IS NULL
LEFT JOIN email_messages e ON a.id = e.activity_id
WHERE a.actual_start_time > '2024-01-01 00:00:00'
AND a.opportunity_id IN (4353519)
AND a.status IN ('completed', 'received', 'delivered')
AND a.deleted_at IS NULL
AND a.type NOT IN ('sms-inbound', 'sms-outbound')
ORDER BY a.opportunity_id ASC, a.id ASC;
SELECT * FROM users WHERE name LIKE '%George Fierstone%'; # 14293
SELECT * FROM teams WHERE id = 442;
SELECT * FROM crm_configurations WHERE id = 344;
select * from team_features where team_id = 442;
select * from groups where team_id = 442;
select * from playbooks where team_id = 442;
select * from playbook_categories where playbook_id = 1729;
select * from crm_fields where crm_configuration_id = 344 and id = 172024;
SELECT * FROM crm_field_values WHERE crm_field_id = 172024;
select * from crm_layouts where crm_configuration_id = 344;
select * from playbook_layouts where playbook_id = 1729;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Learning%'; # 260, 221, 9444
select s.*
# , s.sent_at, u.name, a.*
from activity_summary_logs s
inner join activities a on a.id = s.activity_id
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 356
and s.sent_at > date_sub(now(), interval 60 day)
order by a.actual_end_time desc;
select * from activities a
# inner join activity_summary_logs s on s.activity_id = a.id
where a.crm_configuration_id = 356 and a.actual_end_time > date_sub(now(), interval 60 day)
# and a.crm_provider_id is not null
# and provider <> 'ringcentral'
and status = 'completed'
order by a.actual_end_time desc;
select * from teams order by id desc; # 17328, 32, 17830, [EMAIL]
SELECT * FROM users;
SELECT * FROM users where team_id = 260 and status = 1; # 201 - 150 active
SELECT * FROM teams WHERE id = 260;
select * from team_settings where team_id = 260;
select * from crm_configurations where team_id = 260;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 356;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 1184;
select * from accounts where crm_configuration_id = 221 order by id desc; # 7000
select * from leads where crm_configuration_id = 221 order by id desc; # 0
select * from contacts where crm_configuration_id = 221 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 221 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 221 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 221;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 221 order by id desc;
select * from stages where crm_configuration_id = 221 order by id desc;
select * from accounts where crm_configuration_id = 356 order by id desc; # 7000
select * from leads where crm_configuration_id = 356 order by id desc; # 0
select * from contacts where crm_configuration_id = 356 order by id desc; # 200 000
select * from opportunities where crm_configuration_id = 356 order by id desc; # 0
select * from crm_profiles where crm_configuration_id = 356 order by id desc; # 23
select * from crm_fields where crm_configuration_id = 356;
select * from crm_field_values where crm_field_id = 5302 order by id desc;
select * from crm_layouts where crm_configuration_id = 356 order by id desc;
select * from stages where crm_configuration_id = 356 order by id desc;
select * from playbooks where team_id = 260 order by id desc; # 4 (2 deleted)
select * from groups where team_id = 260 order by id desc; # 27 groups, (2 deleted)
select * from playbook_layouts where playbook_id IN (1410,1409,1276,1254); # 4
select ce.* from calendars c
join users u on c.user_id = u.id
join calendar_events ce on c.id = ce.calendar_id
where u.team_id = 260
and (ce.start_time > '2025-02-21 00:00:00')
;
# calendar events 1207
#
select * from opportunities where team_id = 260;
SELECT * FROM crm_field_data WHERE object_id = 4696496;
select * from activities where crm_configuration_id = 356 and crm_provider_id IS NOT NULL;
select * from activities where crm_configuration_id IN (221) and provider NOT IN ('ms-teams', 'uploader', 'zoom-bot')
# and type = 'conference' and status = 'scheduled' and activities.is_internal = 0
and created_at > '2024-03-01 00:00:00'
order by id desc; # 880 000, ringcentral, avaya
SELECT * FROM participants WHERE activity_id = 26371744;
# all activities 942 000 +
# conference 7385 - scheduled 984 - external 343
select * from activities where id = 26321812;
select * from participants where activity_id = 26321812;
select * from participants where activity_id in (26414510,26414514,26414516,26414604,26414653,26414655);
select * from leads where id in (720428,689175,731546,645866,621037);
select * from users where id = 13841;
select * from opportunities where user_id = 9541;
select * from stages where id = 15900;
select * from accounts where
# id IN (4160055,5053725,4965303,4896434)
id in (4584518,3249934,3218025,3891133,3399450,4172999,4485161,3101785,4587203,3070816,2870343,2870341,3563940,4550846,3424464,3249963,2870342)
;
select * from activities where id = 26654935;
SELECT * FROM opportunities WHERE id = 4803458;
SELECT * FROM opportunities where team_id = 260 and user_id = 13841 AND stage_id = 15900;
SELECT id, uuid, provider, type, lead_id, account_id, contact_id, opportunity_id, stage_id, status, recording_state, title, actual_start_time, actual_end_time
FROM activities WHERE user_id = 13841 AND opportunity_id IN (4729783, 4731717, 4731726, 4732064, 4732849, 4803458, 4813213);
SELECT DISTINCT
o.id, o.stage_id, s.name, a.title,
a.*
FROM activities a
# INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
INNER JOIN groups g ON u.group_id = g.id
INNER JOIN opportunities o ON a.opportunity_id = o.id
INNER JOIN stages s ON o.stage_id = s.id
WHERE
a.crm_configuration_id = 356
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 13841
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
AND team.uuid = uuid_to_bin('a607fba7-452e-4683-b2af-00d6cb52c93c')
AND g.uuid = uuid_to_bin('b5d69e40-24a0-4c16-810b-5fa462299f94')
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-13 00:00:00' AND '2025-03-18 07:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND u.uuid = uuid_to_bin('6f40e4b8-c340-4059-b4ac-1728e87ea99e')
)
)
AND (
# s.id = 15900
s.uuid = uuid_to_bin('04ca1c26-c666-4268-a129-419c0acffd73')
OR s.uuid IS NULL -- Include records without opportunity stage
)
ORDER BY a.actual_end_time DESC;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Lead Forensics%'; # 190, 162, 8474, [EMAIL]
SELECT * FROM users WHERE team_id = 190;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 190
and sa.provider = 'hubspot';
select * from role_user where user_id = 8474;
select * from crm_configurations where provider = 'bullhorn';
SELECT * FROM opportunities WHERE uuid_to_bin('94578249-65ec-4205-90f2-7d1a7d5ab64a') = uuid;
SELECT * FROM users WHERE uuid_to_bin('26dbadeb-926f-4150-b11b-771b9d4c2f9a') = uuid;
SELECT * FROM opportunities WHERE id = 4732493;
select * from activities where opportunity_id = 4732493;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE id = 443; # 358, 14315, [EMAIL]
SELECT * FROM opportunities WHERE team_id = 443;
SELECT a.id, a.type, a.user_id, a.status, a.deleted_at, u.name, u.email, u.team_id as activity_team_id, u.status, u.deleted_at, t.name, t.status, s.team_id as stage_team_id
FROM activities AS a
JOIN stages AS s ON a.stage_id = s.id
JOIN users AS u ON u.id = a.user_id
JOIN teams AS t ON t.id = s.team_id
WHERE u.team_id <> s.team_id and t.id > 135;
SELECT
crm_configuration_id,
crm_provider_id,
COUNT(*) as duplicate_count,
GROUP_CONCAT(id) as stage_ids,
GROUP_CONCAT(name) as stage_names
FROM stages
GROUP BY crm_configuration_id, crm_provider_id
HAVING COUNT(*) > 1
ORDER BY duplicate_count DESC;
select * from stages where id IN (14898,14907);
select * from business_processes;
SELECT *
FROM crm_configurations
WHERE team_id IN (
SELECT team_id
FROM crm_configurations
GROUP BY team_id
HAVING COUNT(*) > 1
)
ORDER BY team_id;
SELECT *
FROM teams
WHERE crm_id IN (
SELECT crm_id
FROM teams
GROUP BY crm_id
HAVING COUNT(*) > 1
)
ORDER BY crm_id;
# [PASSWORD_DOTS]
select * from crm_configurations where provider = 'integration-app';
SELECT * FROM teams WHERE id = 443; # Correre Naturale 358 14315 [EMAIL]
select * from activities where crm_configuration_id = 358 order by actual_end_time desc;
select id, uuid, actual_end_time, crm_provider_id, is_internal, playbook_category_id, type, user_id, lead_id, contact_id, account_id, opportunity_id, status, title from activities where crm_configuration_id = 358 order by actual_end_time desc;
select * from team_features where team_id = 358;
select * from activity_summary_logs;
select * from teams where id = 406;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Sportfive%'; # 267, 202, 14637, [EMAIL]
select * from activities where crm_configuration_id = 202 order by actual_end_time desc;
SELECT * FROM users where id = 14637;
SELECT * FROM teams where id = 267;
SELECT * FROM groups where id = 1118;
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM activities
WHERE crm_configuration_id = 202
AND status IN ('completed', 'failed')
AND recording_state != 'stopped'
AND type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
AND (is_private = 0 OR user_id = 14637)
AND (
(
actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
) OR (
actual_start_time IS NULL
AND type IN ('sms-outbound', 'sms-inbound')
AND created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND NOT EXISTS (
SELECT 1
FROM tracks
WHERE
tracks.activity_id = activities.id
AND tracks.type IN ('audio', 'video')
)
ORDER BY actual_end_time DESC;
SELECT DISTINCT
a.*
FROM activities a
INNER JOIN tracks t ON a.id = t.activity_id
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams team ON u.team_id = team.id
WHERE
a.crm_configuration_id = 202
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
# and a.user_id = 14637
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND t.type IN ('audio', 'video')
AND (
(a.actual_start_time BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59')
OR
(
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-12 12:00:00' AND '2025-03-24 11:59:59'
)
)
AND (
a.is_private = 0
OR (
a.is_private = 1
AND a.user_id = 14637
)
)
ORDER BY a.actual_end_time DESC
;
SELECT DISTINCT a.*
FROM activities a
INNER JOIN users u ON a.user_id = u.id
INNER JOIN teams t ON u.team_id = t.id
# INNER JOIN tracks tr ON a.id = tr.activity_id
# INNER JOIN groups g ON u.group_id = g.id
WHERE 1=1
AND t.id = 267
# AND t.uuid = uuid_to_bin('aed4927b-f1ea-499e-94c3-83762fd233e8')
AND a.status IN ('completed', 'failed')
AND a.recording_state != 'stopped'
AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
# AND tr.type NOT IN ('audio', 'video')
AND (
a.is_private = 0
OR a.user_id = 14637
)
AND (
(a.actual_start_time BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59')
OR (
a.actual_start_time IS NULL
AND a.type IN ('sms-outbound', 'sms-inbound')
AND a.created_at BETWEEN '2025-03-19 00:00:00' AND '2025-03-21 23:59:59'
)
)
# and NOT EXISTS (
# SELECT 1
# FROM tracks t
# WHERE t.activity_id = a.id
# AND t.type IN ('audio', 'video')
# )
ORDER BY a.actual_end_time DESC;
SELECT * FROM tracks WHERE activity_id = 26485995;
select a.is_private, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
where a.crm_configuration_id = 202
# and a.is_internal = 0
and (a.actual_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type IN ("softphone","softphone-inbound","conference","sms-inbound")
and a.status IN ('completed', 'failed')
# and a.external_id is not null
order by a.actual_end_time desc;
select * from activities a where a.crm_configuration_id = 202
and a.actual_start_time between '2025-03-20 00:00:00' and '2025-03-21 00:00:00'
# AND a.type IN ('softphone', 'softphone-inbound', 'conference', 'sms-inbound', 'sms-outbound')
select g.name, a.title, uuid_from_bin(a.uuid), a.external_id, a.status, a.recording_state, a.recording_reason_code, a.scheduled_start_time, a.scheduled_end_time, a.actual_start_time, a.actual_end_time from activities a
inner join users u on u.id = a.user_id
inner join groups g on g.id = u.group_id
where a.crm_configuration_id = 202
and a.is_internal = 0
and (a.scheduled_start_time between '2025-03-19 00:00:00' and '2025-03-21 00:00:00')
and a.type = 'conference'
and a.status != 'completed'
and a.external_id is not null
order by a.scheduled_start_time desc;
SELECT * FROM teams WHERE name LIKE '%Tourlane%';
SELECT * FROM crm_fields WHERE crm_configuration_id = 209 and object_type = 'opportunity';
SELECT * FROM crm_field_data WHERE crm_field_id = 98809;
select * from users where status = 1 AND timezone = 'MDT';
select * from opportunities where id = 3769814;
select * from deal_risks where opportunity_id = 3769814;
select cp.* from crm_profiles cp
join users u on cp.user_id = u.id
join crm_configurations crm on cp.crm_configuration_id = crm.id
where crm.provider = 'hubspot' AND u.status = 1 AND log_notes != 'none';
select * from crm_fields where id = 154575;
select * from team_features where feature = 'SUPPORTS_SYNC_MISSING_CALL_DISPOSITIONS';
SELECT * FROM teams WHERE id = 176; # crm 148
select * from activities where crm_configuration_id = 148 and provider = 'hubspot' order by id desc;
select * from activity_providers where provider = 'amazon-connect';
select * from crm_fields cf
join crm_configurations crm on crm.id = cf.crm_configuration_id
where crm.provider = 'hubspot' and cf.object_type IN ('account', 'contact');
# [PASSWORD_DOTS]
SELECT * FROM users WHERE id IN (15415, 15418);
SELECT * FROM groups WHERE id IN (1805,1806);
SELECT * FROM playbooks WHERE id = 1860;
SELECT * FROM playbook_categories WHERE id = 38634;
SELECT * FROM crm_fields WHERE id = 189962;
SELECT * FROM teams WHERE name = 'Pulsar Group'; # 472, 380, 15138 [EMAIL]
SELECT * FROM crm_profiles WHERE user_id = 15415;
SELECT * FROM social_accounts WHERE sociable_id = 15415 and provider = 'salesforce';
select * from sidekick_settings where team_id = 472;
SELECT * FROM activities WHERE uuid_to_bin('452c58c7-b87c-4fdd-953e-d7af185e9588') = uuid; # 28617536, user: 15418
SELECT * FROM activities WHERE uuid_to_bin('399114ee-d3a8-458c-bff5-5f654658db0a') = uuid; # 28344407, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('f0aa567f-0ab1-4bbb-96aa-37dcf184676b') = uuid; # 28580288, user: 15415
SELECT * FROM activities WHERE uuid_to_bin('50c086b1-2770-4bca-b5ae-6bac22ec426b') = uuid; # 28566069, user: 15415
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%TeamTailor%'; # 109, 218, 13969, [EMAIL]
select * from crm_configurations where id = 218;
SELECT * FROM activities WHERE uuid_to_bin('e39b5857-7fdb-4f5a-951a-8d3ca69bb1b0') = uuid; # 28338765
SELECT * FROM users WHERE id IN (13232, 13230);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
0057R00000EPL5HQAX Inez Ekblad
1091cb81-5ea1-4951-a0ed-f00b568f0140 Triman Kaur
SELECT * FROM crm_profiles WHERE user_id IN (13232, 13230);
############################################################################################
SELECT * FROM activities WHERE uuid_to_bin('675eeaeb-5681-42db-90bc-54c07a604408') = uuid; # 28655939 00UVg00000FLvnSMAT
SELECT * FROM crm_field_data WHERE activity_id = 28655939;
SELECT * FROM crm_fields WHERE id IN (94491,94493,94498);
SELECT * FROM users WHERE id = 13658;
SELECT * FROM teams WHERE id = 109;
SELECT * FROM crm_configurations WHERE id = 218;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 109
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Strengthscope%'; # 481, 390, 15420, [EMAIL]
SELECT * FROM stages WHERE crm_configuration_id = 390;
select * from business_processes where team_id = 481 and crm_configuration_id = 390;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 481
and sa.provider = 'salesforce';
SELECT * FROM users WHERE id = 15780; # team 462
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 462
and sa.provider = 'hubspot';
select * from teams where id = 495;
SELECT * FROM users WHERE id = 15794;
select * from social_accounts where sociable_id = 15794;
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Flight%'; # 427, 333, 13752
SELECT * FROM accounts WHERE team_id = 427 and crm_provider_id = '668731000183444517';
# [PASSWORD_DOTS]
SELECT * FROM teams WHERE name LIKE '%Group GTI%'; # 495, 407, 15794
SELECT * FROM activities WHERE crm_configuration_id = 407
and status = 'completed' and type = 'conference'
order by id desc;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from permission_role;
select * from activities where crm_configuration_id = 407 and status = 'completed' order by id desc;
SELECT * FROM activities WHERE id = 29512773;
SELECT * FROM activities WHERE id IN (29042721,28991325,29002874);
SELECT al.* from activity_summary_logs al join activities a on a.id = al.activity_id
where a.crm_configuration_id = 407
# and a.id IN (29042721,28991325,29002874);
SELECT * FROM users WHERE id = 15794;
SELECT * FROM users WHERE team_id = 495;
SELECT * FROM social_accounts WHERE sociable_id = 15794;
SELECT * FROM opportunities WHERE team_id = 495 and name like '%OC:%';
SELECT * FROM contacts WHERE team_id = 495;
SELECT * FROM leads WHERE team_id = 495;
SELECT * FROM accounts WHERE team_id = 495;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 407;
SELECT * FROM crm_fields WHERE crm_configuration_id = 407;
SELECT * FROM crm_configurations WHERE id = 407;
SELECT * FROM opportunities WHERE team_id = ...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89172
|
|
89171
|
PhpStormEV faVsco,ls ~ProjectvViewNeweNNCCooc#1212 PhpStormEV faVsco,ls ~ProjectvViewNeweNNCCooc#12121 on JY-20963-fx-ImKetucioWindow© ServiceTest.php© HubspotAppUninstalLJob.fimportaccountostonto© ImportBatchJobTrait.phpemoorcontcororon©ImportOpportunityBatch.pMmacuryochyict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpuorcoaiuocrd.pntRecordSelector.phphuososwo.noocea.cokecontoensynstooo.m© PayloadBulider.phpImportBatchJcbTrait.php© ProcessinternalWethookEcrmantityRepos.tory.phprart noortbarch.obtrayprotected functzon processimportsatchtE SalesforceC Autolon Delavedtocrm oho© CheckAndRetryRemoteMatchCereateFollowuosctmty oho(C)ereateNotes onoCMatchactvitiesToNewdooor 114© MatchActivityCrmData.phpE Noteeoiectono© SaveActivity.php116117© SaveTranscription.php© SetupLayout.php©SyncActivity.php© SyncFieidMetadata.php© SyncHubspotObjects.phpE B© SyncLeads.php© SyncObjects.php122124© SyncOpportunities.Job.php© SyncOpportunity.php126© SyncProfileMetadata.phpe GunaTosmSiahe lah nhoLog: : info( message: Sthis->getLogPrefix() . ' Processing batch', ["scnConfigurationid' => Sthis->crnConfigurationid,"batchSize' => count(Sthis->crnids),1):SfilteredIds = $this->filterExisting0bjects(ScraConfig, $crnEntityRepository);if Cenpty(SfilteredIds)) €Log:: info( message: Sthis->getLogPrefix() . * No existing objects found in Liniony, skipping batch',"scaCenfigucationld' = Sthis-scraConfigurationId,eeuosoeroun s coontottncosD):SstartTine = microtime(as.float true):Sresult = sthis-smoor.BarchlScrnSeryicer stterediids)"Services+, o,cv Moatabasd@ Outpurt10 rowsDidy799900419988851jiminny.opportunitiesiid fiminny stageE Result: 34Result 47xgis_won Yopp_probability Ystage_prob Y4 console 2 s 845 msell users 1 s 548 ms#liminny@localhostAHS JocalA SOV A PRODA consoleV A STAGING& consoleDocker "TH:100100180100100crn_provider_1d Y168.60 29848944100.00 208480441108.00 208480441188.80.298488641100100.00 208488441108.00 208480441108.00 208488441e MrsreSMCASSWNoTANDeoAw.edanswiulcomolatar.l.minutas.aooE customlogE Iaravellog4 SF [iminny@localhost)4 console (EU) xE users (EU)A console (STAGING)ihee AncdytE cc.provider = "hubspot"ID s-probability = 1001D 0.is_won = 0iu o.delered ac as nuLulu s.delered ar as nuLuID o.created_at > *2025-10-13' :A HS.Jocal (jiminny@localhost)A console (PROD]68 Jiminny~031 49 A31 X3 X113 AECTSUMCCASE WHEN O.updated_at < *2825-18-13 THEN 1 ELSE 0 END) as before_fix,SUMCCASE WHEN O.updated_at >= *2825-10-13* THEN 1 ELSE 0 END) as after_fix,COUNT(*) as totalonnartunttes1 stages s 1.n<->1: ON s.id = o.stage_idcrm_configurations cc .nc->l: ON cc.1d = s.crm_configuration_1dIE cc.provider = "hubspot"sunnohabtiuty taal1D o.is_won = 0Unondeleted at is MullID s.deleted_at IS NULL;ECT o.1d, o.is_won, O.probability as opp_probability,1812o.created_attopportunities o1 stages s 1.n<-›1: ON s.id = o.stage_idtE o.tean,id = 416 AND o.created_at > *2026-85-28' AND S.probability = 100ER BY O.created_at DESC LIMIT 10;created_at Y2826-05-28 17:48:162826-05-28 17:48:162826-05-28 17:43:272826-05-28 17:23:172004-A6-20 14-10-002926-05-28 16:49:692026-05-28 16:38:322826-85-28 16:38:31DankrACDe 1X2.2TO0У L7Inu co moy k0ioo.eU ServiceTest ~CascadeeworehsermiehTlasorce DaleionkOtwooeoo0ntur+0.The only remaining explanation: getClosedDealStages () is not returning *21843841* in wonfl . Let me check getOpportumwcloscos ooes aoin- soeciowhetnerneresa cocontourrmmmSberein('probability', (0.0e, 108.001) - stage has probability • 188 (integer). This should match 108.00 . But wait -probability column is cast as integer in the Stage model. Let me check wnat MysoL actually stores and whether there's afloat precision issue... no, 180 == 100.00 in MySQL regardless.The real question is: does Sthis->config-»stages() for team 416's config (id=331) actually return stage 14269?Siote 1ezo3 nos cre contguration zd m 35% v. oux contiguracion os cenesi) ls bas anylsceneiiclass, 'cre conttouratM") Sonqueres WHERE em. contfouration1d u 331, Stace 14269 has that Should workUnless - Sthis->config in the service instance is NOT configuration 331. Let me check how the service is instantiated forthe batch job:Now I see something critical on line 114-123:ImportbatchJobtrait.php:114-12Stalteredlos = Sthis-iilterexistingobiects Scracontza, ScrecntzcyRepositony=1f (empty(sfilteredids)) €Loa:: intosthis-soetiooPrerxo No existing cbfects toundsinoinny, skiooina batchieroatdaurar.onidtCthiceser.contacuratool1 fle +2 >Ask anything (atoL)Accept all• • code)# Adaptive• OCSV~WW Windsurf Teams 114.1 (390 chars, 9 line breaks) UTF-8 A 4 spaco-...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89171
|
|
89170
|
HomeDMsActivityFilesLater..•More+Slack> 0(ah]Fi HomeDMsActivityFilesLater..•More+Slack> 0(ah]FileEditViewGoHistoryJiminny ...* Starredplatform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday& infosec_internal_all# infra-changes# infrastructure_dev# jbu-team-info# jiminny-bg# platform-team# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of_jimi...WindowHelpSearch: in:#platform-inner-teamX*à platform-inner-teamMessagesBookmarks0 Channel Overview7 RefinementsO Files< PinsP Retro Action ItemsChanges:Monday, May 4th ~• Do not requeue duplicatesjiminny/app May 4th Added by GitHubNikolay Ivanov 1:48 PMhttps://github.com/jiminny/app/pull/12041, фикс за импорта на стейджове (само при hubspot се оказа )но има още една грешка за тях, слагаме стейджове от една организация на другаи не мога да намеря никьде в кода защона еи има две организации които не могат да се изтрият заради товаVasil Vasilev 2:07 PMимаше проблем със мачването на стейджове от една организация на другазаради кеширане на pipelineldпреди горе долу 10тина дена го гледахмеNikolay Ivanov 2:07 PMтой още го иматози пьт при stageвиж ми PRVasil Vasilev 2:08 PMpipelineld бeшe default за едно 5-6 организации, и там се омазваше кешапонеже няма нито crm coniguration id, нито team id включено в кеша дето заминава в РЕДИСа, да, това е сьщотодобре де, аз защо си мисля, че фикс за тоя проблем вече замина на продNikolay Ivanov 2:10 PMMessage & platform-inner-team+100% <78 • Thu 28 May 20:56:45®8 10Untitled +...
|
PhpStorm
|
faVsco.js – ImportBatchJobTrait.php
|
NULL
|
89170
|
|
89169
|
rapstomCoocPVovsco.s#12121 on JY-20963-fox-h€ Serv rapstomCoocPVovsco.s#12121 on JY-20963-fox-h€ ServiceTest.php© HubspotAppUninstalLJob.fimportaccountooterlor© ImportBatchJobTrait.phpemoorcontconcron©ImportOpportunityBatch.pMmacurayochyict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpRecordSelector.phphuososwo.noocea.cokecontoensynstooo.m© ProcessinternalWethookEcachedClosedDealStaces x 5Cc w.*6/6Tл Y:trait OpportunitySyncTraitprivate function resolveStage(BusinessPrOCeSS $businessProcess, Pstring Sstageld): ?StegeewaeweaweoSalesforceC Autolon Delavedtocrm ohoCcheckandRetrvpemotewateCereateFollowuosctmty oho(C)ereateNotes onoC MatchActvitiestoNeweooorC Matchactvitvermoate onoE Notee biectono© SaveActivity.php© SaveTranscription.php© SetupLayout.php©SyncActivity.php© SyncFieldMetadata.php© SyncHubspotObjects.php© SyncLeads.php© SyncObjects.php© SyncOpportunities.Job.php© SyncOpportunity.php© SyncProfileMetadata.php@ SvncTeamFieldsJob.oho18.11.25ISUEIZO NOYoIk13.02.26 Kovalik18.11.25 Kovallk18.11.25 Kovalik18.11.25 Kovallk18.11.25 Kovalik18.11.25 Kovallk18.11.25 Kovalik18.11.25 Kovalik18.11.25 Kovalik18.11.25 Kovalik18.11.25 Kovaik4A4011171118111911201121Sstage = Sthis->crmEntityRepository->getPipelineStageByConditions(SbusinessProcess,*crn_provider_id' = Sstageld,"type' => Stage::TYPE_OPPORTUNITY,1f (Sstage aa= null) (Sthis->inportStages(null, Sstageid);Schas-xcaoealscages = nullh18.11.25 Kovalik18.11.25 Kovaik18.11.25 Kovaik18.T1.2S KOVS18.11.25 Kovalk18.11.25 KoVal13.02.26 Kovallk11291130113111321f (Sstage === nulL) (Sthis->logger->info(*[HubSpot) Stage does not exist => • . SstageId):Sthis->cachecstaoesscachekey = Sscaoc:Services+,o, c*v M DatabaseV AEU4 console 2 $ 845 msti users 1 s 548 msv 4/jiminny@localhost4 HSJJocal4 SFV A PROD#consoleV A STAGINGconsole& Dockerta outoutil liminny coportunitiesI W 10 rows v500Jid yM3s won T %798988879898877989886D fiminny stages18 Recult 34TXc AutOIID opp_probability Y@D Result 47 x TxCAA+I stage_prob V@ crn_provider_1d Y100.00 208480441100.00 20848844118:100100100100100100188188100.00 208488441100.00 208480441100.00 208480441100.00 208480441100 n0 209/90/1400 00 209/90/1E custom.logE Iaravellog4 console (EU) xE users (EU)A console (STAGING)D800@ 0| TEANOV(E cc.provider = 'hubspot"1790ID s-probability = 100ID o.is_won = 01792ID o.deleted_at IS NULLlu s.delered ar as nuLuID o.created_at > *2025-10-13':A HS.Jocal (jiminny@localhost)A console (PROD]68 Jiminny~031 49 A31 X3 X113 A18011802=1803E1804180518061807E180818101811= 1813181318141815ECTSUMCCASE WHEN O.updated_at < ^2025-18-13' THEN 1 ELSE ® END) as before_fix,SUMCCASE WHEN O.updated_at >= *2025-18-13* THEN 1 ELSE 0 END) as after_fix,COUNT(*) as totalonnartunttes1 stages s 1.n<->1: ON s.id = o.stage_id1 crm_configurations cc (1.n<->1: ON ce.id = s.crm_configuration_idIE cc.provider = "hubspot"ID s.probability = 1001D o.is_won = 0ID o.deleted_at IS NULLID s.deleted_at IS NULL;ECT o.id, O.is_won, O.probability as opp_probability,s.probability as stage_prob, s.crn_provider_id,o.created_at1 opportunities o1 stages s 1.n<->1: ON s.id = o.stage_idtE o.tean,id = 416 AND o.created_at > *2026-85-28' AND S.probability = 100ER BY O.created_at DESC LIMIT 10;Icreated_at V2026-05-28 17:48:162826-05-28 17:48:162026-05-28 17:43:272026-05-28 17:23:172026-05-28 16:49:092026-05-28 16:49:092026-05-28 16:49:082826-05-28 16:38:320054 06. 00 [CREDIT_CARD] 14,2212Inu Lo moy k0ioo.alCascadeeworehsermiehalsorce oelcdonkoturooeooonur+0.The only remaining explanation: getClosedDealStages () is not returning "21848841* in vonf] . Let me check getOpportumwcloscos ooes aoin — Soecie Whe ner nerersa cocontcurereemimoSberein('probability', (0.ee, 108.001) - stage has probability = 100 (integer). This should match 100.00 . But wait -probability column is cast as integer in the Stage model. Let me check wnat MysoL actually stores and whether there's afloat precision issue... no, 180 == 100.00 in MySQL regardless.The real question is: does Sthis-sconfig-»stages() for team 416's config (id=331) actually return stage 142697Stage 14269 has cra_configuration_1d - 331 V. But Configuration-sstages() is haskany(Stase::class, 'cre_configuratsM") SotQueres WHERE em. contfouration 1d u 331, Stace 14269 has that Should workUnless - Sthis->config in the service instance is NOT configuration 331. Let me check how the service is instantiated forthe batch job:Now I see something critical on line 114-123:ImportbatchJobtrait.php:114-12Sfilteredids = Sthis→>filterExisting0bjects(ScrnConfig, ScreEntityRepository):1f (empty(sfilteredids)) €Loa:: intosthis-soetiooPrerxo No existing cbfects toundsinoinny, skiooina batchieroatdaurar.onidtCthiceser.contacuratool1fle +2 >Ask anything (XOL)+Code$ AdaptiveAccopt all• 0csv~d.4o0181106 UTG.8...
|
PhpStorm
|
|
NULL
|
89169
|
|
89168
|
PhpStormPwovscorsViewCooc#12121 on JY-20963-fox-Wi PhpStormPwovscorsViewCooc#12121 on JY-20963-fox-Window© ActivityController.php€ ServiceTest.php# composer.isoncomposer.lockdependency-checker.isondewisonE ids.txtinkectononoisdMSINSTALL.mdM.lNiEhNALw2.00a1?mejiminny_storageMallicinsoe.moMakerosckaar.lock.sonE phpstan.neon.dist#phpstan-baseline.neom<phpunit.xml1raw_sqLquery.sgM.README.meQ sonar-project.propertiesE test.py<> Untitled Diagram.xml20.11.25 Kovalk18.11.25 Kovalik13.02.26 Kovalik18.11.25 Kovalik18.11.25 Kovalik18.11.25 Kovalik18.11.25 Kovallk18.11.25 Kovalik18.11.25 Kovallk18.11.25 Kovalik18.11.25 Kovaik18.11.25 Kovalik18.11.25 Kovalik# vetur.config.isM:WEBHOOK_FILTERING._IMPLEMENTAT18.11.25 Kovalk› Ilb External Librarles18.11.25 Kovalkw Scratches and consoles18.11.25 Kovalk~ EO Database Consoles18.11.25 KovalkV AEU18.11.25 KovallkA console (EUT18.11.25 KovallkA DEAL RISKS (EU)30726 KovalikdDIEU13.02.26 Kovallkngultsun8.WS KovalUmacurayscrict.on© CachedCrmServiceDecorator.php© DeleteObjects Trait.phpu morconiuscid.pnioRecordSelector.phpHwwo.noocea.cokicontoensytsdorooe© PayloadBulider.php© CiosedDealStagesService.phpcachedelosedbealstaaesx5 Cc wtrait OpportunitySyncTrait1106private function resolveStage(BusinessProcess $businessProcess, Pstring Sstageld): ?Stage111611171118Sstage = Sthis->crnEntityRepository->getPipelineStaqeByConditions(112011211122crn_provider_id' => Sstageid,"type' => Stage::TYPE_OPPORTUNITY,11241f (Sstage === null) (sihisoconoreces nultn oscoterosthis-xcacdClosedDealStages = null;if (Sstage R== nulV) (Sthis->logger->info(*[HubSpot) Stage does not exist => •SstageId);5050113SSthis-scachedStaces Scachekey = Sstage:return Sstace.Services+, o,ctv Moatabase@ Outpurt10 rowsDidy799900419988851jiminny.opportunitiesiii fiminny stages1id Result 34gis_won Yopp_probability Ystage_prob Y4 console 2 s 845 msell users 1 s 548 msv#liminny@localhostAHS JocalS:V APROD# consoleV A STAGING& consoleDockerN o uAa "TH:[CREDIT_CARD] crn_provider id y168.60 29848944100.00 208480441108.00 208480441100.00 208488441188.80.298488641100100.00 208488441108.00 208480441108.00 208488441E custom.logE IaravellogA console (EUJ XE users (EU]A console (STAGING)iThe AncoytE cc.provider = "nubspot"1790ID s-probability = 100ID o.is_won = 8ID o.deleted_at IS NULL1u s.dereredar ys NULLluo.crcarcdar>2825-18-15A HS.Jocal (jiminny@localhost)A console (PROD]68 Jiminny~031 49 A31 23 213 A V-1795=1795180€=18021803E18051806- 180%1808ECTSUMCCASE WHEN O.updated_at < ^2025-18-13' THEN 1 ELSE ® END) as before_fix,SUMCCASE WHEN o.updated_at >= '2825-10-13*THEN 1 ELSE 0 END) as after_fix,COUNT(*) as totalonnartuns ttes o1 stages s 1.n<->1: ON s.id = o.stage_id1 crm_configurations ce (1.n<->1: ON ce.id = s.crm_configuration_idtE cc.provider = "hubspot"tsunranabiutyahl1D o.is_won = 0inondeleted.at is MullID s.deleted_at IS NULL;1810181218131814o.created_attopportunities o1 stages s 1..n<-›1: ON s.id = o.stage_idE o.tean_id = 416 AND o.created_at > *2026-85-28' AND S.probability = 100ER BY O.created_at DESC LIMIT 10;created_at Y2826-05-28 17:48:162826-05-28 17:48:162826-05-28 17:43:272026-05-28 17:23:172004-A6-20 14-10-002926-05-28 16:49:692026-05-28 16:38:322826-85-28 16:38:312826-05-28 16:33:24ind co mey curooisCascadeeworehsermiehTlasorce DaleionkOtwooeoo0ntur+0.The only remaining explanation: getClosedDealStages () is not returning "21848841* in vonfl . Let me check getOpportunityClosedStages again - specifically whether there's a cm_configuration_id mismatchSberein('probability', (0.ee, 108.001) - stage has probability = 100 (integer). This should match 100.00 . But wait -probability column is cast as integer in the Stage model. Let me check wnat MysoL actually stores and whether there's afloat precision issue... no, 180 == 100.00 in MySQL regardless.The real question is: does Sthis-sconfig-»stages() for team 416's config (id=331) actually return stage 142697Stage 14269 has cra_configuration_1d - 331 V. But Configuration-sstages() is haskany(Stase::class, 'cre_configuratsM") SotQueres WHERE em. contfouration 1d u 331, Stace 14269 has that Should workUnless - Sthis->config in the service instance is NOT configuration 331. Let me check how the service is instantiated forthe batch job:Now I see something critical on line 114-123:ImportbatchJobtrait.pho:114-12Sfilteredids = Sthis→>filterExisting0bjects(ScrnConfig, ScreEntityRepository):1f (empty(sfilteredids)) €Loa:: intosthis-soetiooPrerxo No existing cbfects toundsinoinny, skiooina batchieroatdaurar.onidtCthiceser.contacuratool1 fle +2 >Ask anything (atoL)"Code# AdaptiveAccept all• OCSV~11$00WW Windsurf Teams 1811.15 UTF-8 P 4 spac...
|
PhpStorm
|
|
NULL
|
89168
|